Skip to content

Commit

Permalink
Remove extra component wrapper from View
Browse files Browse the repository at this point in the history
Summary:
View needed this wrapper to add a dev time warning about text children. Text children became supported and this warning was removed in facebook#23195

This check is no longer necessary and we can reduce the overhead and improve the performance of View by removing this.

Reviewed By: rickhanlonii

Differential Revision: D15914658

fbshipit-source-id: 6456a9cb356245fa8104036b2948aa5c5bf39e0f
  • Loading branch information
elicwhite authored and M-i-k-e-l committed Mar 10, 2020
1 parent df41408 commit a789052
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 19 deletions.
18 changes: 1 addition & 17 deletions Libraries/Components/View/View.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

'use strict';

const React = require('react');
const ViewNativeComponent = require('./ViewNativeComponent');

import type {ViewProps} from './ViewPropTypes';
Expand All @@ -24,19 +23,4 @@ export type Props = ViewProps;
*
* @see http://facebook.github.io/react-native/docs/view.html
*/

let ViewToExport = ViewNativeComponent;
if (__DEV__) {
if (!global.__RCTProfileIsProfiling) {
const View = (
props: Props,
forwardedRef: React.Ref<typeof ViewNativeComponent>,
) => {
return <ViewNativeComponent {...props} ref={forwardedRef} />;
};
ViewToExport = React.forwardRef(View);
ViewToExport.displayName = 'View';
}
}

module.exports = ((ViewToExport: $FlowFixMe): typeof ViewNativeComponent);
module.exports = ((ViewNativeComponent: $FlowFixMe): typeof ViewNativeComponent);
13 changes: 11 additions & 2 deletions jest/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -331,12 +331,21 @@ jest
.mock('../Libraries/ReactNative/requireNativeComponent', () => {
const React = require('react');

return viewName =>
class extends React.Component {
return viewName => {
const Component = class extends React.Component {
render() {
return React.createElement(viewName, this.props, this.props.children);
}
};

if (viewName === 'RCTView') {
Component.displayName = 'View';
} else {
Component.displayName = viewName;
}

return Component;
};
})
.mock(
'../Libraries/Utilities/verifyComponentAttributeEquivalence',
Expand Down

0 comments on commit a789052

Please sign in to comment.