Skip to content

Commit

Permalink
ReactNative sync (c3718c4...abce30f): the one about the Prepack optim…
Browse files Browse the repository at this point in the history
…izations

Reviewed By: sophiebits

Differential Revision: D5626312

fbshipit-source-id: f8158ccb14f991b681fba34fb23933042266939d
  • Loading branch information
Brian Vaughn authored and facebook-github-bot committed Sep 15, 2017
1 parent 6c2c2ec commit e9780bd
Show file tree
Hide file tree
Showing 10 changed files with 968 additions and 6,123 deletions.
42 changes: 23 additions & 19 deletions Libraries/ART/ReactNativeART.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,25 +101,29 @@ var TextAttributes = merge(RenderableAttributes, {

// Native Components

var NativeSurfaceView = createReactNativeComponentClass({
validAttributes: SurfaceViewAttributes,
uiViewClassName: 'ARTSurfaceView',
});

var NativeGroup = createReactNativeComponentClass({
validAttributes: GroupAttributes,
uiViewClassName: 'ARTGroup',
});

var NativeShape = createReactNativeComponentClass({
validAttributes: ShapeAttributes,
uiViewClassName: 'ARTShape',
});

var NativeText = createReactNativeComponentClass({
validAttributes: TextAttributes,
uiViewClassName: 'ARTText',
});
var NativeSurfaceView = createReactNativeComponentClass('ARTSurfaceView',
() => ({
validAttributes: SurfaceViewAttributes,
uiViewClassName: 'ARTSurfaceView',
}));

var NativeGroup = createReactNativeComponentClass('ARTGroup',
() => ({
validAttributes: GroupAttributes,
uiViewClassName: 'ARTGroup',
}));

var NativeShape = createReactNativeComponentClass('ARTShape',
() => ({
validAttributes: ShapeAttributes,
uiViewClassName: 'ARTShape',
}));

var NativeText = createReactNativeComponentClass('ARTText',
() => ({
validAttributes: TextAttributes,
uiViewClassName: 'ARTText',
}));

// Utilities

Expand Down
131 changes: 70 additions & 61 deletions Libraries/ReactNative/requireNativeComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

const ReactNativeStyleAttributes = require('ReactNativeStyleAttributes');
const UIManager = require('UIManager');
const UnimplementedView = require('UnimplementedView');

const createReactNativeComponentClass = require('createReactNativeComponentClass');
const insetsDiffer = require('insetsDiffer');
Expand All @@ -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');

/**
Expand All @@ -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;
}

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;
}
// 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];

invariant(
viewConfig != null &&
!viewConfig.NativeProps != null,
'Native component for "%s" does not exist',
viewName
);

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;
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 {
nativeProps = { ...nativeProps, ...baseModule.NativeProps };
baseModuleName = baseModule.baseModuleName;
viewConfig.propTypes = null;
}
}

for (const key in nativeProps) {
let useAttribute = false;
const attribute = {};

const differ = TypeToDifferMap[nativeProps[key]];
if (differ) {
attribute.diff = differ;
useAttribute = true;
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;
}
}

const processor = TypeToProcessorMap[nativeProps[key]];
if (processor) {
attribute.process = processor;
useAttribute = true;
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;
}

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
);
}

// 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 = {
Expand Down
2 changes: 1 addition & 1 deletion Libraries/Renderer/REVISION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
c3718c48f01fa6c2e04bd47226061769484c951b
abce30f771e07670b3efac6ffdcab1a7139556a9
Loading

0 comments on commit e9780bd

Please sign in to comment.