From 162d92da0e9eca20712200c3cd80a7a0c93daead Mon Sep 17 00:00:00 2001 From: Summer Kitahara Date: Mon, 26 Jun 2017 16:20:39 -0700 Subject: [PATCH] Adding an optional wrapper component to app components Summary: Changing AppContainer to render a wrapper component in it, if it exists. This wrapper is NOT a required property of AppContainer. Now, app-wide properties can be passed down via context to the container's children. Reviewed By: sahrens, fkgozali Differential Revision: D5283895 fbshipit-source-id: 8595e22c4b5ebf5d0e57f358152fba8a80cb2723 --- Libraries/ReactNative/AppContainer.js | 38 +++++++++++++++------- Libraries/ReactNative/AppRegistry.js | 10 +++++- Libraries/ReactNative/renderApplication.js | 27 +++++++-------- 3 files changed, 47 insertions(+), 28 deletions(-) diff --git a/Libraries/ReactNative/AppContainer.js b/Libraries/ReactNative/AppContainer.js index 8b739ee9f..d298cb63e 100644 --- a/Libraries/ReactNative/AppContainer.js +++ b/Libraries/ReactNative/AppContainer.js @@ -7,6 +7,7 @@ * of patent rights can be found in the PATENTS file in the same directory. * * @providesModule AppContainer + * @format * @flow */ @@ -26,6 +27,7 @@ type Context = { type Props = { children?: React.Children, rootTag: number, + WrapperComponent?: ?ReactClass<*>, }; type State = { inspector: ?React.Element<*>, @@ -62,12 +64,13 @@ class AppContainer extends React.Component { ? null : { + onRequestRerenderApp={updateInspectedViewTag => { this.setState( - (s) => ({mainKey: s.mainKey + 1}), - () => updateInspectedViewTag( - ReactNative.findNodeHandle(this._mainRef) - ) + s => ({mainKey: s.mainKey + 1}), + () => + updateInspectedViewTag( + ReactNative.findNodeHandle(this._mainRef), + ), ); }} />; @@ -93,15 +96,26 @@ class AppContainer extends React.Component { } } + let innerView = ( + { + this._mainRef = ref; + }}> + {this.props.children} + + ); + + const Wrapper = this.props.WrapperComponent; + if (Wrapper) { + innerView = {innerView}; + } return ( - {this._mainRef = ref;}}> - {this.props.children} - + {innerView} {yellowBox} {this.state.inspector} diff --git a/Libraries/ReactNative/AppRegistry.js b/Libraries/ReactNative/AppRegistry.js index 9bc22fc28..c51a447c9 100644 --- a/Libraries/ReactNative/AppRegistry.js +++ b/Libraries/ReactNative/AppRegistry.js @@ -43,6 +43,7 @@ export type Registry = { sections: Array, runnables: Runnables, }; +export type WrapperComponentProvider = any => ReactClass<*>; const runnables: Runnables = {}; let runCount = 1; @@ -51,6 +52,8 @@ const tasks: Map = new Map(); let componentProviderInstrumentationHook: ComponentProviderInstrumentationHook = (component: ComponentProvider) => component(); +let wrapperComponentProvider: ?WrapperComponentProvider; + /** *