mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-03-29 22:41:56 +08:00
Unify renderApplication across iOS and Android
Reviewed By: spicyj Differential Revision: D3385860 fbshipit-source-id: 256a2d12691dc9fddc56eaf150697f07b830da92
This commit is contained in:
committed by
Facebook Github Bot 4
parent
8c29a52c54
commit
23027cd730
@@ -60,7 +60,7 @@ var AppContainer = React.createClass({
|
||||
return (
|
||||
<View style={styles.appContainer}>
|
||||
<View
|
||||
collapsable={false}
|
||||
collapsable={!this.state.inspector}
|
||||
key={this.state.mainKey}
|
||||
style={styles.appContainer} ref="main">
|
||||
{this.props.children}
|
||||
|
||||
@@ -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 ?
|
||||
<Inspector
|
||||
rootTag={this.props.rootTag}
|
||||
inspectedViewTag={this.state.rootNodeHandle}
|
||||
onRequestRerenderApp={(updateInspectedViewTag) => {
|
||||
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 =
|
||||
<View
|
||||
ref={this._setMainRef}
|
||||
key={this.state.mainKey}
|
||||
collapsable={!this.state.inspectorVisible}
|
||||
style={StyleSheet.absoluteFill}>
|
||||
<RootComponent
|
||||
{...this.props.initialProps}
|
||||
rootTag={this.props.rootTag}
|
||||
importantForAccessibility={this.state.rootImportanceForAccessibility}
|
||||
/>
|
||||
</View>;
|
||||
return __DEV__ ?
|
||||
<View style={StyleSheet.absoluteFill}>
|
||||
{appView}
|
||||
<YellowBox />
|
||||
{this.renderInspector()}
|
||||
</View> :
|
||||
appView;
|
||||
}
|
||||
});
|
||||
|
||||
function renderApplication<D, P, S>(
|
||||
RootComponent: ReactClass<P>,
|
||||
initialProps: P,
|
||||
rootTag: any
|
||||
) {
|
||||
invariant(
|
||||
rootTag,
|
||||
'Expect to have a valid rootTag, instead got ', rootTag
|
||||
);
|
||||
ReactNative.render(
|
||||
<AppContainer
|
||||
rootComponent={RootComponent}
|
||||
initialProps={initialProps}
|
||||
rootTag={rootTag}
|
||||
/>,
|
||||
rootTag
|
||||
);
|
||||
}
|
||||
|
||||
module.exports = renderApplication;
|
||||
@@ -18,9 +18,12 @@ var ReactNative = require('ReactNative');
|
||||
|
||||
var invariant = require('fbjs/lib/invariant');
|
||||
|
||||
function renderApplication<P>(
|
||||
RootComponent: ReactClass<P>,
|
||||
initialProps: P,
|
||||
// require BackAndroid so it sets the default handler that exits the app if no listeners respond
|
||||
require('BackAndroid');
|
||||
|
||||
function renderApplication<Props>(
|
||||
RootComponent: ReactClass<Props>,
|
||||
initialProps: Props,
|
||||
rootTag: any
|
||||
) {
|
||||
invariant(
|
||||
@@ -38,5 +41,4 @@ function renderApplication<P>(
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
module.exports = renderApplication;
|
||||
Reference in New Issue
Block a user