mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-23 20:01:01 +08:00
Export native modules without RCT or RK prefix
Reviewed By: mmmulani Differential Revision: D3901600 fbshipit-source-id: 7d4a027f0f2478e2a9ac9916326b91279bec3cb3
This commit is contained in:
committed by
Facebook Github Bot 8
parent
ff79224d37
commit
31b158c9fe
@@ -14,27 +14,6 @@
|
||||
const BatchedBridge = require('BatchedBridge');
|
||||
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.
|
||||
* These will return the module if already loaded, or load it if not.
|
||||
|
||||
@@ -11,8 +11,8 @@
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
const Platform = require('Platform');
|
||||
const NativeModules = require('NativeModules');
|
||||
const Platform = require('Platform');
|
||||
const { UIManager } = NativeModules;
|
||||
|
||||
const findNodeHandle = require('react/lib/findNodeHandle');
|
||||
@@ -64,11 +64,6 @@ UIManager.takeSnapshot = async function(
|
||||
* namespace instead of UIManager, unlike Android.
|
||||
*/
|
||||
if (Platform.OS === 'ios') {
|
||||
// Copied from NativeModules
|
||||
function normalizePrefix(moduleName: string): string {
|
||||
return moduleName.replace(/^(RCT|RK)/, '');
|
||||
}
|
||||
|
||||
Object.keys(UIManager).forEach(viewName => {
|
||||
const viewConfig = UIManager[viewName];
|
||||
if (viewConfig.Manager) {
|
||||
@@ -82,7 +77,7 @@ if (Platform.OS === 'ios') {
|
||||
return constants;
|
||||
}
|
||||
constants = {};
|
||||
const viewManager = NativeModules[normalizePrefix(viewConfig.Manager)];
|
||||
const viewManager = NativeModules[viewConfig.Manager];
|
||||
viewManager && Object.keys(viewManager).forEach(key => {
|
||||
const value = viewManager[key];
|
||||
if (typeof value !== 'function') {
|
||||
@@ -102,7 +97,7 @@ if (Platform.OS === 'ios') {
|
||||
return commands;
|
||||
}
|
||||
commands = {};
|
||||
const viewManager = NativeModules[normalizePrefix(viewConfig.Manager)];
|
||||
const viewManager = NativeModules[viewConfig.Manager];
|
||||
let index = 0;
|
||||
viewManager && Object.keys(viewManager).forEach(key => {
|
||||
const value = viewManager[key];
|
||||
|
||||
Reference in New Issue
Block a user