2016-06-08 21:30:46 +00:00
|
|
|
/**
|
|
|
|
* 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 AppContainer
|
|
|
|
* @noflow
|
|
|
|
*/
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var RCTDeviceEventEmitter = require('RCTDeviceEventEmitter');
|
|
|
|
var React = require('React');
|
2016-07-05 13:34:00 +00:00
|
|
|
var ReactNative = require('react/lib/ReactNative');
|
2016-06-08 21:30:46 +00:00
|
|
|
var Subscribable = require('Subscribable');
|
|
|
|
var StyleSheet = require('StyleSheet');
|
|
|
|
var View = require('View');
|
|
|
|
|
|
|
|
var Inspector = __DEV__ ? require('Inspector') : null;
|
|
|
|
var YellowBox = __DEV__ ? require('YellowBox') : null;
|
|
|
|
|
|
|
|
var AppContainer = React.createClass({
|
|
|
|
mixins: [Subscribable.Mixin],
|
|
|
|
|
|
|
|
getInitialState: function() {
|
|
|
|
return { inspector: null, mainKey: 1 };
|
|
|
|
},
|
|
|
|
|
|
|
|
toggleElementInspector: function() {
|
|
|
|
var inspector = !__DEV__ || this.state.inspector
|
|
|
|
? null
|
|
|
|
: <Inspector
|
|
|
|
inspectedViewTag={ReactNative.findNodeHandle(this.refs.main)}
|
|
|
|
onRequestRerenderApp={(updateInspectedViewTag) => {
|
|
|
|
this.setState(
|
|
|
|
(s) => ({mainKey: s.mainKey + 1}),
|
|
|
|
() => updateInspectedViewTag(ReactNative.findNodeHandle(this.refs.main))
|
|
|
|
);
|
|
|
|
}}
|
|
|
|
/>;
|
|
|
|
this.setState({inspector});
|
|
|
|
},
|
|
|
|
|
|
|
|
componentDidMount: function() {
|
|
|
|
this.addListenerOn(
|
|
|
|
RCTDeviceEventEmitter,
|
|
|
|
'toggleElementInspector',
|
|
|
|
this.toggleElementInspector
|
|
|
|
);
|
|
|
|
},
|
|
|
|
|
|
|
|
render: function() {
|
|
|
|
let yellowBox = null;
|
|
|
|
if (__DEV__) {
|
|
|
|
yellowBox = <YellowBox />;
|
|
|
|
}
|
|
|
|
return (
|
|
|
|
<View style={styles.appContainer}>
|
|
|
|
<View
|
2016-06-13 23:34:48 +00:00
|
|
|
collapsable={!this.state.inspector}
|
2016-06-08 21:30:46 +00:00
|
|
|
key={this.state.mainKey}
|
|
|
|
style={styles.appContainer} ref="main">
|
|
|
|
{this.props.children}
|
|
|
|
</View>
|
|
|
|
{yellowBox}
|
|
|
|
{this.state.inspector}
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
var styles = StyleSheet.create({
|
|
|
|
appContainer: {
|
|
|
|
flex: 1,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = AppContainer;
|