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
|
|
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
|
[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
|
|
|
var Inspector = require('Inspector');
|
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');
|
|
|
|
var WarningBox = require('WarningBox');
|
2015-02-20 04:10:52 +00:00
|
|
|
|
|
|
|
var invariant = require('invariant');
|
|
|
|
|
2015-05-26 18:16:25 +00:00
|
|
|
var AppContainer = React.createClass({
|
|
|
|
mixins: [Subscribable.Mixin],
|
|
|
|
|
|
|
|
getInitialState: function() {
|
|
|
|
return { inspector: null };
|
|
|
|
},
|
|
|
|
|
|
|
|
toggleElementInspector: function() {
|
|
|
|
var inspector = this.state.inspector
|
|
|
|
? 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() {
|
|
|
|
var shouldRenderWarningBox = __DEV__ && console.yellowBoxEnabled;
|
|
|
|
var warningBox = shouldRenderWarningBox ? <WarningBox /> : null;
|
|
|
|
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>
|
|
|
|
{warningBox}
|
|
|
|
{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-07-23 23:56:23 +00:00
|
|
|
// not when debugging in chrome
|
|
|
|
if (__DEV__ && !window.document) {
|
|
|
|
var setupDevtools = require('setupDevtools');
|
|
|
|
setupDevtools();
|
|
|
|
}
|
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-02-20 04:10:52 +00:00
|
|
|
}
|
|
|
|
|
2015-04-27 20:24:15 +00:00
|
|
|
var styles = StyleSheet.create({
|
|
|
|
appContainer: {
|
|
|
|
position: 'absolute',
|
|
|
|
left: 0,
|
|
|
|
top: 0,
|
|
|
|
right: 0,
|
|
|
|
bottom: 0,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2015-02-20 04:10:52 +00:00
|
|
|
module.exports = renderApplication;
|