mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
652fa1b8d4
Summary:
## Purpose
We must modify the `getTurboModuleWithJsInvoker:` method of all our NativeModules to also accept a `id<RCTTurboModulePerformanceLogger>` object. This performance logger object should then be forwarded to the `Native*SpecJSI` constructor.
## Script
Run the following script via Node:
```
var withSpaces = (...args) => args.join('\s*')
var regexString = withSpaces(
'-',
'\(',
'std::shared_ptr',
'<',
'(?<turboModuleClass>(facebook::react::|react::|::|)TurboModule)',
'>',
'\)',
'getTurboModuleWithJsInvoker',
':',
'\(',
'std::shared_ptr',
'<',
'(?<callInvokerClass>(facebook::react::|react::|::|)CallInvoker)',
'>',
'\)',
'jsInvoker',
'{',
'return',
'std::make_shared',
'<',
'(?<specName>(facebook::react::|react::|::|)Native[A-Za-z0-9]+SpecJSI)',
'>',
'\(',
'(?<arg1>[A-Za-z0-9]+)',
',',
'(?<arg2>[A-Za-z0-9]+)',
'\)',
';',
'}',
)
var replaceString = `- (std::shared_ptr<$<turboModuleClass>>)
getTurboModuleWithJsInvoker:(std::shared_ptr<$<callInvokerClass>>)jsInvoker
perfLogger:(id<RCTTurboModulePerformanceLogger>)perfLogger
{
return std::make_shared<$<specName>>($<arg1>, $<arg2>, perfLogger);
}`
const exec = (cmd) => require('child_process').execSync(cmd, { encoding: 'utf8' });
const abspath = (filename) => `${process.env.HOME}/${filename}`;
const relpath = (filename) => filename.replace(process.env.HOME + '/', '');
const readFile = (filename) => require('fs').readFileSync(filename, 'utf8');
const writeFile = (filename, content) => require('fs').writeFileSync(filename, content);
function main() {
const tmFiles = exec('cd ~/fbsource && xbgs -n 10000 -l getTurboModuleWithJsInvoker:').split('\n').filter(Boolean);
tmFiles
.filter((filename) => !filename.includes('microsoft-fork-of-react-native'))
.map(abspath)
.forEach((filename) => {
const source = readFile(filename);
const newSource = source.replace(new RegExp(regexString, 'g'), replaceString);
if (source == newSource) {
console.log(relpath(filename));
}
writeFile(filename, newSource);
});
}
if (!module.parent) {
main();
}
```
Also, run: `pushd ~/fbsource && js1 build oss-native-modules-specs -p ios && js1 build oss-native-modules-specs -p android && popd;`
Changelog: [Internal]
Reviewed By: fkgozali
Differential Revision: D20478718
fbshipit-source-id: 89ee27ed8a0338a66a9b2dbb716168a4c4582c44
91 lines
2.5 KiB
Plaintext
91 lines
2.5 KiB
Plaintext
/*
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*/
|
|
|
|
#import "RCTPlatform.h"
|
|
|
|
#import <UIKit/UIKit.h>
|
|
|
|
#import <FBReactNativeSpec/FBReactNativeSpec.h>
|
|
#import <React/RCTUtils.h>
|
|
#import <React/RCTVersion.h>
|
|
|
|
#import "CoreModulesPlugins.h"
|
|
|
|
using namespace facebook::react;
|
|
|
|
static NSString *interfaceIdiom(UIUserInterfaceIdiom idiom)
|
|
{
|
|
switch (idiom) {
|
|
case UIUserInterfaceIdiomPhone:
|
|
return @"phone";
|
|
case UIUserInterfaceIdiomPad:
|
|
return @"pad";
|
|
case UIUserInterfaceIdiomTV:
|
|
return @"tv";
|
|
case UIUserInterfaceIdiomCarPlay:
|
|
return @"carplay";
|
|
default:
|
|
return @"unknown";
|
|
}
|
|
}
|
|
|
|
@interface RCTPlatform () <NativePlatformConstantsIOSSpec>
|
|
@end
|
|
|
|
@implementation RCTPlatform
|
|
|
|
RCT_EXPORT_MODULE(PlatformConstants)
|
|
|
|
+ (BOOL)requiresMainQueueSetup
|
|
{
|
|
return YES;
|
|
}
|
|
|
|
- (dispatch_queue_t)methodQueue
|
|
{
|
|
return dispatch_get_main_queue();
|
|
}
|
|
|
|
// TODO: Use the generated struct return type.
|
|
- (ModuleConstants<JS::NativePlatformConstantsIOS::Constants>)constantsToExport
|
|
{
|
|
return (ModuleConstants<JS::NativePlatformConstantsIOS::Constants>)[self getConstants];
|
|
}
|
|
|
|
- (ModuleConstants<JS::NativePlatformConstantsIOS::Constants>)getConstants
|
|
{
|
|
UIDevice *device = [UIDevice currentDevice];
|
|
auto versions = RCTGetReactNativeVersion();
|
|
return typedConstants<JS::NativePlatformConstantsIOS::Constants>({
|
|
.forceTouchAvailable = RCTForceTouchAvailable() ? true : false,
|
|
.osVersion = [device systemVersion],
|
|
.systemName = [device systemName],
|
|
.interfaceIdiom = interfaceIdiom([device userInterfaceIdiom]),
|
|
.isTesting = RCTRunningInTestEnvironment() ? true : false,
|
|
.reactNativeVersion = JS::NativePlatformConstantsIOS::ConstantsReactNativeVersion::Builder(
|
|
{.minor = [versions[@"minor"] doubleValue],
|
|
.major = [versions[@"major"] doubleValue],
|
|
.patch = [versions[@"patch"] doubleValue],
|
|
.prerelease = [versions[@"prerelease"] isKindOfClass:[NSNull class]]
|
|
? folly::Optional<double>{}
|
|
: [versions[@"prerelease"] doubleValue]}),
|
|
});
|
|
}
|
|
|
|
- (std::shared_ptr<TurboModule>)getTurboModuleWithJsInvoker:(std::shared_ptr<CallInvoker>)jsInvoker
|
|
perfLogger:(id<RCTTurboModulePerformanceLogger>)perfLogger
|
|
{
|
|
return std::make_shared<NativePlatformConstantsIOSSpecJSI>(self, jsInvoker, perfLogger);
|
|
}
|
|
|
|
@end
|
|
|
|
Class RCTPlatformCls(void)
|
|
{
|
|
return RCTPlatform.class;
|
|
}
|