mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-23 03:50:11 +08:00
ReactNative sync (c3718c4...abce30f): the one about the Prepack optimizations
Reviewed By: sophiebits Differential Revision: D5626312 fbshipit-source-id: f8158ccb14f991b681fba34fb23933042266939d
This commit is contained in:
committed by
Facebook Github Bot
parent
6c2c2ecd8c
commit
e9780bdc0f
@@ -13,7 +13,6 @@
|
||||
|
||||
const ReactNativeStyleAttributes = require('ReactNativeStyleAttributes');
|
||||
const UIManager = require('UIManager');
|
||||
const UnimplementedView = require('UnimplementedView');
|
||||
|
||||
const createReactNativeComponentClass = require('createReactNativeComponentClass');
|
||||
const insetsDiffer = require('insetsDiffer');
|
||||
@@ -26,6 +25,7 @@ const verifyPropTypes = require('verifyPropTypes');
|
||||
/* $FlowFixMe(>=0.54.0 site=react_native_oss) This comment suppresses an error
|
||||
* found when Flow v0.54 was deployed. To see the error delete this comment and
|
||||
* run Flow. */
|
||||
const invariant = require('fbjs/lib/invariant');
|
||||
const warning = require('fbjs/lib/warning');
|
||||
|
||||
/**
|
||||
@@ -50,77 +50,86 @@ function requireNativeComponent(
|
||||
componentInterface?: ?ComponentInterface,
|
||||
extraConfig?: ?{nativeOnly?: Object},
|
||||
): React$ComponentType<any> | string {
|
||||
const viewConfig = UIManager[viewName];
|
||||
if (!viewConfig || !viewConfig.NativeProps) {
|
||||
warning(false, 'Native component for "%s" does not exist', viewName);
|
||||
return UnimplementedView;
|
||||
}
|
||||
// Don't load the ViewConfig from UIManager until it's needed for rendering.
|
||||
// Lazy-loading this can help avoid Prepack deopts.
|
||||
function getViewConfig() {
|
||||
const viewConfig = UIManager[viewName];
|
||||
|
||||
viewConfig.uiViewClassName = viewName;
|
||||
viewConfig.validAttributes = {};
|
||||
|
||||
// ReactNative `View.propTypes` have been deprecated in favor of
|
||||
// `ViewPropTypes`. In their place a temporary getter has been added with a
|
||||
// deprecated warning message. Avoid triggering that warning here by using
|
||||
// temporary workaround, __propTypesSecretDontUseThesePlease.
|
||||
// TODO (bvaughn) Revert this particular change any time after April 1
|
||||
if (componentInterface) {
|
||||
viewConfig.propTypes =
|
||||
typeof componentInterface.__propTypesSecretDontUseThesePlease === 'object'
|
||||
? componentInterface.__propTypesSecretDontUseThesePlease
|
||||
: componentInterface.propTypes;
|
||||
} else {
|
||||
viewConfig.propTypes = null;
|
||||
}
|
||||
|
||||
let baseModuleName = viewConfig.baseModuleName;
|
||||
let nativeProps = { ...viewConfig.NativeProps };
|
||||
while (baseModuleName) {
|
||||
const baseModule = UIManager[baseModuleName];
|
||||
if (!baseModule) {
|
||||
warning(false, 'Base module "%s" does not exist', baseModuleName);
|
||||
baseModuleName = null;
|
||||
} else {
|
||||
nativeProps = { ...nativeProps, ...baseModule.NativeProps };
|
||||
baseModuleName = baseModule.baseModuleName;
|
||||
}
|
||||
}
|
||||
|
||||
for (const key in nativeProps) {
|
||||
let useAttribute = false;
|
||||
const attribute = {};
|
||||
|
||||
const differ = TypeToDifferMap[nativeProps[key]];
|
||||
if (differ) {
|
||||
attribute.diff = differ;
|
||||
useAttribute = true;
|
||||
}
|
||||
|
||||
const processor = TypeToProcessorMap[nativeProps[key]];
|
||||
if (processor) {
|
||||
attribute.process = processor;
|
||||
useAttribute = true;
|
||||
}
|
||||
|
||||
viewConfig.validAttributes[key] = useAttribute ? attribute : true;
|
||||
}
|
||||
|
||||
// Unfortunately, the current set up puts the style properties on the top
|
||||
// level props object. We also need to add the nested form for API
|
||||
// compatibility. This allows these props on both the top level and the
|
||||
// nested style level. TODO: Move these to nested declarations on the
|
||||
// native side.
|
||||
viewConfig.validAttributes.style = ReactNativeStyleAttributes;
|
||||
|
||||
if (__DEV__) {
|
||||
componentInterface && verifyPropTypes(
|
||||
componentInterface,
|
||||
viewConfig,
|
||||
extraConfig && extraConfig.nativeOnly
|
||||
invariant(
|
||||
viewConfig != null &&
|
||||
!viewConfig.NativeProps != null,
|
||||
'Native component for "%s" does not exist',
|
||||
viewName
|
||||
);
|
||||
|
||||
viewConfig.uiViewClassName = viewName;
|
||||
viewConfig.validAttributes = {};
|
||||
|
||||
// ReactNative `View.propTypes` have been deprecated in favor of
|
||||
// `ViewPropTypes`. In their place a temporary getter has been added with a
|
||||
// deprecated warning message. Avoid triggering that warning here by using
|
||||
// temporary workaround, __propTypesSecretDontUseThesePlease.
|
||||
// TODO (bvaughn) Revert this particular change any time after April 1
|
||||
if (componentInterface) {
|
||||
viewConfig.propTypes =
|
||||
typeof componentInterface.__propTypesSecretDontUseThesePlease === 'object'
|
||||
? componentInterface.__propTypesSecretDontUseThesePlease
|
||||
: componentInterface.propTypes;
|
||||
} else {
|
||||
viewConfig.propTypes = null;
|
||||
}
|
||||
|
||||
let baseModuleName = viewConfig.baseModuleName;
|
||||
let nativeProps = { ...viewConfig.NativeProps };
|
||||
while (baseModuleName) {
|
||||
const baseModule = UIManager[baseModuleName];
|
||||
if (!baseModule) {
|
||||
warning(false, 'Base module "%s" does not exist', baseModuleName);
|
||||
baseModuleName = null;
|
||||
} else {
|
||||
nativeProps = { ...nativeProps, ...baseModule.NativeProps };
|
||||
baseModuleName = baseModule.baseModuleName;
|
||||
}
|
||||
}
|
||||
|
||||
for (const key in nativeProps) {
|
||||
let useAttribute = false;
|
||||
const attribute = {};
|
||||
|
||||
const differ = TypeToDifferMap[nativeProps[key]];
|
||||
if (differ) {
|
||||
attribute.diff = differ;
|
||||
useAttribute = true;
|
||||
}
|
||||
|
||||
const processor = TypeToProcessorMap[nativeProps[key]];
|
||||
if (processor) {
|
||||
attribute.process = processor;
|
||||
useAttribute = true;
|
||||
}
|
||||
|
||||
viewConfig.validAttributes[key] = useAttribute ? attribute : true;
|
||||
}
|
||||
|
||||
// Unfortunately, the current set up puts the style properties on the top
|
||||
// level props object. We also need to add the nested form for API
|
||||
// compatibility. This allows these props on both the top level and the
|
||||
// nested style level. TODO: Move these to nested declarations on the
|
||||
// native side.
|
||||
viewConfig.validAttributes.style = ReactNativeStyleAttributes;
|
||||
|
||||
if (__DEV__) {
|
||||
componentInterface && verifyPropTypes(
|
||||
componentInterface,
|
||||
viewConfig,
|
||||
extraConfig && extraConfig.nativeOnly
|
||||
);
|
||||
}
|
||||
|
||||
return viewConfig;
|
||||
}
|
||||
|
||||
return createReactNativeComponentClass(viewConfig);
|
||||
return createReactNativeComponentClass(viewName, getViewConfig);
|
||||
}
|
||||
|
||||
const TypeToDifferMap = {
|
||||
|
||||
Reference in New Issue
Block a user