From 23027cd730bb6eb63277b251378713b08a083d9e Mon Sep 17 00:00:00 2001 From: Alex Kotliarskyi Date: Mon, 13 Jun 2016 16:34:48 -0700 Subject: [PATCH] Unify renderApplication across iOS and Android Reviewed By: spicyj Differential Revision: D3385860 fbshipit-source-id: 256a2d12691dc9fddc56eaf150697f07b830da92 --- Libraries/ReactIOS/AppContainer.js | 2 +- .../ReactIOS/renderApplication.android.js | 124 ------------------ ...pplication.ios.js => renderApplication.js} | 10 +- 3 files changed, 7 insertions(+), 129 deletions(-) delete mode 100644 Libraries/ReactIOS/renderApplication.android.js rename Libraries/ReactIOS/{renderApplication.ios.js => renderApplication.js} (79%) diff --git a/Libraries/ReactIOS/AppContainer.js b/Libraries/ReactIOS/AppContainer.js index a3f3fbe98..d49653db7 100644 --- a/Libraries/ReactIOS/AppContainer.js +++ b/Libraries/ReactIOS/AppContainer.js @@ -60,7 +60,7 @@ var AppContainer = React.createClass({ return ( {this.props.children} diff --git a/Libraries/ReactIOS/renderApplication.android.js b/Libraries/ReactIOS/renderApplication.android.js deleted file mode 100644 index 5b5ec232e..000000000 --- a/Libraries/ReactIOS/renderApplication.android.js +++ /dev/null @@ -1,124 +0,0 @@ -/** - * Copyright (c) 2015-present, Facebook, Inc. - * All rights reserved. - * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. - * - * @providesModule renderApplication - */ - -'use strict'; - -const Inspector = require('Inspector'); -const RCTDeviceEventEmitter = require('RCTDeviceEventEmitter'); -const React = require('React'); -const ReactNative = require('ReactNative'); -const StyleSheet = require('StyleSheet'); -const Subscribable = require('Subscribable'); -const View = require('View'); - -const invariant = require('fbjs/lib/invariant'); - -const YellowBox = __DEV__ ? require('YellowBox') : null; - -// require BackAndroid so it sets the default handler that exits the app if no listeners respond -require('BackAndroid'); - -const AppContainer = React.createClass({ - mixins: [Subscribable.Mixin], - - getInitialState: function() { - return { - inspectorVisible: false, - rootNodeHandle: null, - rootImportanceForAccessibility: 'auto', - mainKey: 1, - }; - }, - - toggleElementInspector: function() { - this.setState({ - inspectorVisible: !this.state.inspectorVisible, - rootNodeHandle: ReactNative.findNodeHandle(this._mainRef), - }); - }, - - componentDidMount: function() { - this.addListenerOn( - RCTDeviceEventEmitter, - 'toggleElementInspector', - this.toggleElementInspector - ); - - this._unmounted = false; - }, - - renderInspector: function() { - return this.state.inspectorVisible ? - { - this.setState( - (s) => ({mainKey: s.mainKey + 1}), - () => updateInspectedViewTag(ReactNative.findNodeHandle(this._mainRef)) - ); - }} - /> : - null; - }, - - componentWillUnmount: function() { - this._unmounted = true; - }, - - _setMainRef: function(ref) { - this._mainRef = ref; - }, - - render: function() { - const RootComponent = this.props.rootComponent; - const appView = - - - ; - return __DEV__ ? - - {appView} - - {this.renderInspector()} - : - appView; - } -}); - -function renderApplication( - RootComponent: ReactClass

, - initialProps: P, - rootTag: any -) { - invariant( - rootTag, - 'Expect to have a valid rootTag, instead got ', rootTag - ); - ReactNative.render( - , - rootTag - ); -} - -module.exports = renderApplication; diff --git a/Libraries/ReactIOS/renderApplication.ios.js b/Libraries/ReactIOS/renderApplication.js similarity index 79% rename from Libraries/ReactIOS/renderApplication.ios.js rename to Libraries/ReactIOS/renderApplication.js index 53433d8c2..3fa622f85 100644 --- a/Libraries/ReactIOS/renderApplication.ios.js +++ b/Libraries/ReactIOS/renderApplication.js @@ -18,9 +18,12 @@ var ReactNative = require('ReactNative'); var invariant = require('fbjs/lib/invariant'); -function renderApplication

( - RootComponent: ReactClass

, - initialProps: P, +// require BackAndroid so it sets the default handler that exits the app if no listeners respond +require('BackAndroid'); + +function renderApplication( + RootComponent: ReactClass, + initialProps: Props, rootTag: any ) { invariant( @@ -38,5 +41,4 @@ function renderApplication

( ); } - module.exports = renderApplication;