Export native modules without RCT or RK prefix
Reviewed By: mmmulani Differential Revision: D3901600 fbshipit-source-id: 7d4a027f0f2478e2a9ac9916326b91279bec3cb3
This commit is contained in:
Родитель
ff79224d37
Коммит
31b158c9fe
|
@ -14,27 +14,6 @@
|
||||||
const BatchedBridge = require('BatchedBridge');
|
const BatchedBridge = require('BatchedBridge');
|
||||||
const RemoteModules = BatchedBridge.RemoteModules;
|
const RemoteModules = BatchedBridge.RemoteModules;
|
||||||
|
|
||||||
function normalizePrefix(moduleName: string): string {
|
|
||||||
return moduleName.replace(/^(RCT|RK)/, '');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Dirty hack to support old (RK) and new (RCT) native module name conventions.
|
|
||||||
* TODO 10487027: kill this behaviour
|
|
||||||
*/
|
|
||||||
Object.keys(RemoteModules).forEach((moduleName) => {
|
|
||||||
const strippedName = normalizePrefix(moduleName);
|
|
||||||
if (RemoteModules['RCT' + strippedName] && RemoteModules['RK' + strippedName]) {
|
|
||||||
throw new Error(
|
|
||||||
'Module cannot be registered as both RCT and RK: ' + moduleName
|
|
||||||
);
|
|
||||||
}
|
|
||||||
if (strippedName !== moduleName) {
|
|
||||||
RemoteModules[strippedName] = RemoteModules[moduleName];
|
|
||||||
delete RemoteModules[moduleName];
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Define lazy getters for each module.
|
* Define lazy getters for each module.
|
||||||
* These will return the module if already loaded, or load it if not.
|
* These will return the module if already loaded, or load it if not.
|
||||||
|
|
|
@ -11,8 +11,8 @@
|
||||||
*/
|
*/
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const Platform = require('Platform');
|
|
||||||
const NativeModules = require('NativeModules');
|
const NativeModules = require('NativeModules');
|
||||||
|
const Platform = require('Platform');
|
||||||
const { UIManager } = NativeModules;
|
const { UIManager } = NativeModules;
|
||||||
|
|
||||||
const findNodeHandle = require('react/lib/findNodeHandle');
|
const findNodeHandle = require('react/lib/findNodeHandle');
|
||||||
|
@ -64,11 +64,6 @@ UIManager.takeSnapshot = async function(
|
||||||
* namespace instead of UIManager, unlike Android.
|
* namespace instead of UIManager, unlike Android.
|
||||||
*/
|
*/
|
||||||
if (Platform.OS === 'ios') {
|
if (Platform.OS === 'ios') {
|
||||||
// Copied from NativeModules
|
|
||||||
function normalizePrefix(moduleName: string): string {
|
|
||||||
return moduleName.replace(/^(RCT|RK)/, '');
|
|
||||||
}
|
|
||||||
|
|
||||||
Object.keys(UIManager).forEach(viewName => {
|
Object.keys(UIManager).forEach(viewName => {
|
||||||
const viewConfig = UIManager[viewName];
|
const viewConfig = UIManager[viewName];
|
||||||
if (viewConfig.Manager) {
|
if (viewConfig.Manager) {
|
||||||
|
@ -82,7 +77,7 @@ if (Platform.OS === 'ios') {
|
||||||
return constants;
|
return constants;
|
||||||
}
|
}
|
||||||
constants = {};
|
constants = {};
|
||||||
const viewManager = NativeModules[normalizePrefix(viewConfig.Manager)];
|
const viewManager = NativeModules[viewConfig.Manager];
|
||||||
viewManager && Object.keys(viewManager).forEach(key => {
|
viewManager && Object.keys(viewManager).forEach(key => {
|
||||||
const value = viewManager[key];
|
const value = viewManager[key];
|
||||||
if (typeof value !== 'function') {
|
if (typeof value !== 'function') {
|
||||||
|
@ -102,7 +97,7 @@ if (Platform.OS === 'ios') {
|
||||||
return commands;
|
return commands;
|
||||||
}
|
}
|
||||||
commands = {};
|
commands = {};
|
||||||
const viewManager = NativeModules[normalizePrefix(viewConfig.Manager)];
|
const viewManager = NativeModules[viewConfig.Manager];
|
||||||
let index = 0;
|
let index = 0;
|
||||||
viewManager && Object.keys(viewManager).forEach(key => {
|
viewManager && Object.keys(viewManager).forEach(key => {
|
||||||
const value = viewManager[key];
|
const value = viewManager[key];
|
||||||
|
|
|
@ -235,9 +235,6 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithDelegate:(id<RCTBridgeDelegate>)dele
|
||||||
- (NSArray *)configForModuleName:(NSString *)moduleName
|
- (NSArray *)configForModuleName:(NSString *)moduleName
|
||||||
{
|
{
|
||||||
RCTModuleData *moduleData = _moduleDataByName[moduleName];
|
RCTModuleData *moduleData = _moduleDataByName[moduleName];
|
||||||
if (!moduleData) {
|
|
||||||
moduleData = _moduleDataByName[[@"RCT" stringByAppendingString:moduleName]];
|
|
||||||
}
|
|
||||||
if (moduleData) {
|
if (moduleData) {
|
||||||
#if RCT_DEV
|
#if RCT_DEV
|
||||||
if ([self.delegate respondsToSelector:@selector(whitelistedModulesForBridge:)]) {
|
if ([self.delegate respondsToSelector:@selector(whitelistedModulesForBridge:)]) {
|
||||||
|
@ -246,9 +243,8 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithDelegate:(id<RCTBridgeDelegate>)dele
|
||||||
@"Required config for %@, which was not whitelisted", moduleName);
|
@"Required config for %@, which was not whitelisted", moduleName);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
return moduleData.config;
|
|
||||||
}
|
}
|
||||||
return (id)kCFNull;
|
return moduleData.config;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)initModulesWithDispatchGroup:(dispatch_group_t)dispatchGroup
|
- (void)initModulesWithDispatchGroup:(dispatch_group_t)dispatchGroup
|
||||||
|
|
|
@ -67,9 +67,13 @@ NSString *RCTBridgeModuleNameForClass(Class cls)
|
||||||
if (name.length == 0) {
|
if (name.length == 0) {
|
||||||
name = NSStringFromClass(cls);
|
name = NSStringFromClass(cls);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ([name hasPrefix:@"RK"]) {
|
if ([name hasPrefix:@"RK"]) {
|
||||||
name = [name stringByReplacingCharactersInRange:(NSRange){0,@"RK".length} withString:@"RCT"];
|
name = [name substringFromIndex:2];
|
||||||
|
} else if ([name hasPrefix:@"RCT"]) {
|
||||||
|
name = [name substringFromIndex:3];
|
||||||
}
|
}
|
||||||
|
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -357,7 +357,7 @@ static NSThread *newJavaScriptThread(void)
|
||||||
RCT_PROFILE_BEGIN_EVENT(RCTProfileTagAlways, @"nativeRequireModuleConfig", @{ @"moduleName": moduleName });
|
RCT_PROFILE_BEGIN_EVENT(RCTProfileTagAlways, @"nativeRequireModuleConfig", @{ @"moduleName": moduleName });
|
||||||
NSArray *result = [strongSelf->_bridge configForModuleName:moduleName];
|
NSArray *result = [strongSelf->_bridge configForModuleName:moduleName];
|
||||||
RCT_PROFILE_END_EVENT(RCTProfileTagAlways, @"js_call,config");
|
RCT_PROFILE_END_EVENT(RCTProfileTagAlways, @"js_call,config");
|
||||||
return result;
|
return RCTNullIfNil(result);
|
||||||
};
|
};
|
||||||
|
|
||||||
context[@"nativeFlushQueueImmediate"] = ^(NSArray<NSArray *> *calls){
|
context[@"nativeFlushQueueImmediate"] = ^(NSArray<NSArray *> *calls){
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
#import "RCTShadowView.h"
|
#import "RCTShadowView.h"
|
||||||
#import "RCTUtils.h"
|
#import "RCTUtils.h"
|
||||||
#import "UIView+React.h"
|
#import "UIView+React.h"
|
||||||
|
#import "RCTBridgeModule.h"
|
||||||
|
|
||||||
typedef void (^RCTPropBlock)(id<RCTComponent> view, id json);
|
typedef void (^RCTPropBlock)(id<RCTComponent> view, id json);
|
||||||
|
|
||||||
|
@ -58,11 +59,23 @@ typedef void (^RCTPropBlock)(id<RCTComponent> view, id json);
|
||||||
_viewPropBlocks = [NSMutableDictionary new];
|
_viewPropBlocks = [NSMutableDictionary new];
|
||||||
_shadowPropBlocks = [NSMutableDictionary new];
|
_shadowPropBlocks = [NSMutableDictionary new];
|
||||||
|
|
||||||
_name = RCTBridgeModuleNameForClass(_managerClass);
|
// Hackety hack, this partially re-implements RCTBridgeModuleNameForClass
|
||||||
RCTAssert(_name.length, @"Invalid moduleName '%@'", _name);
|
// We want to get rid of RCT and RK prefixes, but a lot of JS code still references
|
||||||
if ([_name hasSuffix:@"Manager"]) {
|
// view names by prefix. So, while RCTBridgeModuleNameForClass now drops these
|
||||||
_name = [_name substringToIndex:_name.length - @"Manager".length];
|
// prefixes by default, we'll still keep them around here.
|
||||||
|
NSString *name = [managerClass moduleName];
|
||||||
|
if (name.length == 0) {
|
||||||
|
name = NSStringFromClass(managerClass);
|
||||||
}
|
}
|
||||||
|
if ([name hasPrefix:@"RK"]) {
|
||||||
|
name = [name stringByReplacingCharactersInRange:(NSRange){0, @"RK".length} withString:@"RCT"];
|
||||||
|
}
|
||||||
|
if ([name hasSuffix:@"Manager"]) {
|
||||||
|
name = [name substringToIndex:name.length - @"Manager".length];
|
||||||
|
}
|
||||||
|
|
||||||
|
RCTAssert(name.length, @"Invalid moduleName '%@'", name);
|
||||||
|
_name = name;
|
||||||
|
|
||||||
_implementsUIBlockToAmendWithShadowViewRegistry = NO;
|
_implementsUIBlockToAmendWithShadowViewRegistry = NO;
|
||||||
Class cls = _managerClass;
|
Class cls = _managerClass;
|
||||||
|
|
Загрузка…
Ссылка в новой задаче