2015-02-20 04:10:52 +00:00
|
|
|
/**
|
2015-03-23 20:35:08 +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.
|
2015-02-20 04:10:52 +00:00
|
|
|
*
|
|
|
|
* @providesModule renderApplication
|
2015-12-02 03:09:01 +00:00
|
|
|
* @noflow
|
2015-02-20 04:10:52 +00:00
|
|
|
*/
|
2015-11-20 21:05:34 +00:00
|
|
|
|
2015-02-20 04:10:52 +00:00
|
|
|
'use strict';
|
|
|
|
|
2015-05-26 18:16:25 +00:00
|
|
|
var RCTDeviceEventEmitter = require('RCTDeviceEventEmitter');
|
2015-02-20 04:10:52 +00:00
|
|
|
var React = require('React');
|
2015-04-27 20:24:15 +00:00
|
|
|
var StyleSheet = require('StyleSheet');
|
2015-05-26 18:16:25 +00:00
|
|
|
var Subscribable = require('Subscribable');
|
2015-04-27 20:24:15 +00:00
|
|
|
var View = require('View');
|
2015-02-20 04:10:52 +00:00
|
|
|
|
|
|
|
var invariant = require('invariant');
|
|
|
|
|
2015-11-18 17:11:09 +00:00
|
|
|
var Inspector = __DEV__ ? require('Inspector') : null;
|
2015-11-20 21:05:34 +00:00
|
|
|
var YellowBox = __DEV__ ? require('YellowBox') : null;
|
2015-11-18 17:11:09 +00:00
|
|
|
|
2015-05-26 18:16:25 +00:00
|
|
|
var AppContainer = React.createClass({
|
|
|
|
mixins: [Subscribable.Mixin],
|
|
|
|
|
|
|
|
getInitialState: function() {
|
|
|
|
return { inspector: null };
|
|
|
|
},
|
|
|
|
|
|
|
|
toggleElementInspector: function() {
|
2015-11-18 17:11:09 +00:00
|
|
|
var inspector = !__DEV__ || this.state.inspector
|
2015-05-26 18:16:25 +00:00
|
|
|
? null
|
[ReactNative] refactor the inspector
Summary:
The `InspectorOverlay` component was getting unwieldy, so I broke it into three components:
- Inspector
- InspectorOverlay
- InspectorPanel
and added @flow types.
The inspector was also living under the `ReactIOS` directory, and I moved it
up into the `Libraries` directory, as the inspector will soon be usable [on
Android](https://phabricator.fb.com/D2138319).
All features of the inspector should remain functional, with the addition of
one feature:
- you can toggle "touch to inspect" by tapping the "Inspect" button at the
bottom of the inspection panel. When inspection is disabled, the panel remains, but you can interact with
the app normally without touches being intercepted
@public
Test Plan:
Open the inspector:
- touch to inspect things, verify that margin, padding, size and position are
reported correctly, and that the component hierarchy is navigable.
- tap the "Inspect" button, and verify that you can interact with the app
normally.
{F22548949}
[Video of toggling inspection](https://www.latest.facebook.com/pxlcld/mrs9)
2015-06-11 20:50:48 +00:00
|
|
|
: <Inspector
|
2015-05-26 18:16:25 +00:00
|
|
|
rootTag={this.props.rootTag}
|
|
|
|
inspectedViewTag={React.findNodeHandle(this.refs.main)}
|
|
|
|
/>;
|
|
|
|
this.setState({inspector});
|
|
|
|
},
|
|
|
|
|
|
|
|
componentDidMount: function() {
|
|
|
|
this.addListenerOn(
|
|
|
|
RCTDeviceEventEmitter,
|
|
|
|
'toggleElementInspector',
|
|
|
|
this.toggleElementInspector
|
|
|
|
);
|
|
|
|
},
|
|
|
|
|
|
|
|
render: function() {
|
2015-11-20 21:05:34 +00:00
|
|
|
let yellowBox = null;
|
|
|
|
if (__DEV__) {
|
|
|
|
yellowBox = <YellowBox />;
|
|
|
|
}
|
2015-05-26 18:16:25 +00:00
|
|
|
return (
|
|
|
|
<View style={styles.appContainer}>
|
2015-07-10 17:52:59 +00:00
|
|
|
<View collapsible={false} style={styles.appContainer} ref="main">
|
2015-05-26 18:16:25 +00:00
|
|
|
{this.props.children}
|
|
|
|
</View>
|
2015-11-20 21:05:34 +00:00
|
|
|
{yellowBox}
|
2015-05-26 18:16:25 +00:00
|
|
|
{this.state.inspector}
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-03-24 18:30:58 +00:00
|
|
|
function renderApplication<D, P, S>(
|
|
|
|
RootComponent: ReactClass<D, P, S>,
|
|
|
|
initialProps: P,
|
|
|
|
rootTag: any
|
|
|
|
) {
|
2015-02-20 04:10:52 +00:00
|
|
|
invariant(
|
|
|
|
rootTag,
|
|
|
|
'Expect to have a valid rootTag, instead got ', rootTag
|
|
|
|
);
|
2015-11-20 21:05:34 +00:00
|
|
|
/* eslint-disable jsx-no-undef-with-namespace */
|
2015-03-27 21:29:55 +00:00
|
|
|
React.render(
|
2015-05-26 18:16:25 +00:00
|
|
|
<AppContainer rootTag={rootTag}>
|
2015-04-27 20:24:15 +00:00
|
|
|
<RootComponent
|
|
|
|
{...initialProps}
|
2015-06-24 17:14:37 +00:00
|
|
|
rootTag={rootTag}
|
2015-04-27 20:24:15 +00:00
|
|
|
/>
|
2015-05-26 18:16:25 +00:00
|
|
|
</AppContainer>,
|
2015-03-11 20:25:40 +00:00
|
|
|
rootTag
|
|
|
|
);
|
2015-11-20 21:05:34 +00:00
|
|
|
/* eslint-enable jsx-no-undef-with-namespace */
|
2015-02-20 04:10:52 +00:00
|
|
|
}
|
|
|
|
|
2015-04-27 20:24:15 +00:00
|
|
|
var styles = StyleSheet.create({
|
|
|
|
appContainer: {
|
2015-10-26 22:39:04 +00:00
|
|
|
flex: 1,
|
2015-04-27 20:24:15 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2015-02-20 04:10:52 +00:00
|
|
|
module.exports = renderApplication;
|