react-native-macos/React/Base/RCTPlatform.m

58 строки
1.2 KiB
Mathematica
Исходник Обычный вид История

/**
* 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 "RCTUtils.h"
#import "RCTVersion.h"
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";
}
}
@implementation RCTPlatform
RCT_EXPORT_MODULE(PlatformConstants)
+ (BOOL)requiresMainQueueSetup
{
return YES;
}
- (NSDictionary<NSString *, id> *)constantsToExport
Start using getConstants Summary: TurboModules depend on a getConstants method. Existing ObjectiveC modules do not have this method. Therefore, I moved the contents of `constantsToExport` to `getConstants` and then had `constantsToExports` call `getConstants`. facebook Since all NativeModules will eventually need to be migrated to the TurboModule system, I didn't restrict this to just the NativeModules in Marketplace. ``` const fs = require('fs'); if (process.argv.length < 3) { throw new Error('Expected a file containing a list of native modules as the third param'); } function read(filename) { return fs.readFileSync(filename, 'utf8'); } const nativeModuleFilenames = read(process.argv[2]).split('\n').filter(Boolean); nativeModuleFilenames.forEach((fileName) => { if (fileName.endsWith('.h')) { return; } const absPath = `${process.env.HOME}/${fileName}`; const fileSource = read(absPath); if (/(\n|^)-\s*\((.+)\)getConstants/.test(fileSource)) { return; } const constantsToExportRegex = /(\n|^)-\s*\((.+)\)constantsToExport/; const result = constantsToExportRegex.exec(fileSource); if (result == null) { throw new Error(`Didn't find a constantsToExport function inside NativeModule ${fileName}`); } const returnType = result[2]; const newFileSource = fileSource.replace( constantsToExportRegex, '$1- ($2)constantsToExport\n' + '{\n' + ` return ${returnType.includes('ModuleConstants') ? '($2)' : ''}[self getConstants];\n` + '}\n' + '\n' + '- ($2)getConstants' ); fs.writeFileSync(absPath, newFileSource); }); ``` ``` > xbgs -l ')constantsToExport' ``` Reviewed By: fkgozali Differential Revision: D13951197 fbshipit-source-id: 394a319d42aff466c56a3d748e17c335307a8f47
2019-02-05 04:41:36 +03:00
{
return [self getConstants];
}
- (NSDictionary<NSString *, id> *)getConstants
{
UIDevice *device = [UIDevice currentDevice];
return @{
@"forceTouchAvailable": @(RCTForceTouchAvailable()),
@"osVersion": [device systemVersion],
@"systemName": [device systemName],
@"interfaceIdiom": interfaceIdiom([device userInterfaceIdiom]),
@"isTesting": @(RCTRunningInTestEnvironment()),
Expose React Native version as a symbol rather than macro Summary: Add RCTGetReactNativeVersion() to expose version in native code. Right now, version is exposed internally to RN using a MACRO constant. This exposes a symbol (function) that can be called to retrieve the React Native version in iOS. Also exposed RCTVersion.h as a public header in the React project so it is available to developers. The motivation behind this is for https://github.com/wix/detox —we need to know what RN version the user has, if any, so we can properly handle support and abstract differences. Ran bump-oss-version.js to ensure the template is applied properly. Also compiled the project to make sure nothing is broken. [IOS] [ENHANCEMENT] [RCTVersion.h] - Expose version as a compile-time symbol for native queries <!-- Help reviewers and the release process by writing your own release notes **INTERNAL and MINOR tagged notes will not be included in the next version's final release notes.** CATEGORY [----------] TYPE [ CLI ] [-------------] LOCATION [ DOCS ] [ BREAKING ] [-------------] [ GENERAL ] [ BUGFIX ] [-{Component}-] [ INTERNAL ] [ ENHANCEMENT ] [ {File} ] [ IOS ] [ FEATURE ] [ {Directory} ] |-----------| [ ANDROID ] [ MINOR ] [ {Framework} ] - | {Message} | [----------] [-------------] [-------------] |-----------| [CATEGORY] [TYPE] [LOCATION] - MESSAGE EXAMPLES: [IOS] [BREAKING] [FlatList] - Change a thing that breaks other things [ANDROID] [BUGFIX] [TextInput] - Did a thing to TextInput [CLI] [FEATURE] [local-cli/info/info.js] - CLI easier to do things with [DOCS] [BUGFIX] [GettingStarted.md] - Accidentally a thing/word [GENERAL] [ENHANCEMENT] [Yoga] - Added new yoga thing/position [INTERNAL] [FEATURE] [./scripts] - Added thing to script that nobody will see --> Closes https://github.com/facebook/react-native/pull/18136 Differential Revision: D7141076 Pulled By: hramos fbshipit-source-id: 18a92b8c60d7b43fa0ed22597ea46a35cff73c56
2018-03-03 00:59:33 +03:00
@"reactNativeVersion": RCTGetReactNativeVersion(),
};
}
@end