Hook up touchable debugging to Inspector button

Reviewed By: vjeux

Differential Revision: D3188719

fb-gh-sync-id: 271e902399900242f577a77807868bd2a28add37
fbshipit-source-id: 271e902399900242f577a77807868bd2a28add37
This commit is contained in:
Spencer Ahrens 2016-04-16 11:56:07 -07:00 committed by Facebook Github Bot 3
parent fb6133efcf
commit d5c1de7708
5 changed files with 44 additions and 14 deletions

View File

@ -724,7 +724,7 @@ var TouchableMixin = {
var Touchable = { var Touchable = {
Mixin: TouchableMixin, Mixin: TouchableMixin,
TOUCH_TARGET_DEBUG: false, // Set this locally to help debug touch targets. TOUCH_TARGET_DEBUG: false, // Highlights all touchable targets. Toggle with Inspector.
/** /**
* Renders a debugging overlay to visualize touch target with hitSlop (might not work on Android). * Renders a debugging overlay to visualize touch target with hitSlop (might not work on Android).
*/ */

View File

@ -18,6 +18,7 @@ var InspectorUtils = require('InspectorUtils');
var React = require('React'); var React = require('React');
var ReactNative = require('ReactNative'); var ReactNative = require('ReactNative');
var StyleSheet = require('StyleSheet'); var StyleSheet = require('StyleSheet');
var Touchable = require('Touchable');
var UIManager = require('NativeModules').UIManager; var UIManager = require('NativeModules').UIManager;
var View = require('View'); var View = require('View');
@ -38,6 +39,7 @@ class Inspector extends React.Component {
inspecting: true, inspecting: true,
perfing: false, perfing: false,
inspected: null, inspected: null,
inspectedViewTag: this.props.inspectedViewTag,
}; };
} }
@ -61,6 +63,10 @@ class Inspector extends React.Component {
} }
} }
componentWillReceiveProps(newProps: Object) {
this.setState({inspectedViewTag: newProps.inspectedViewTag});
}
attachToDevtools(agent: Object) { attachToDevtools(agent: Object) {
var _hideWait = null; var _hideWait = null;
var hlSub = agent.sub('highlight', ({node, name, props}) => { var hlSub = agent.sub('highlight', ({node, name, props}) => {
@ -148,6 +154,13 @@ class Inspector extends React.Component {
}); });
} }
setTouchTargetting(val: bool) {
Touchable.TOUCH_TARGET_DEBUG = val;
this.props.onRequestRerenderApp((inspectedViewTag) => {
this.setState({inspectedViewTag});
});
}
render() { render() {
var panelContainerStyle = (this.state.panelPos === 'bottom') ? {bottom: 0} : {top: 0}; var panelContainerStyle = (this.state.panelPos === 'bottom') ? {bottom: 0} : {top: 0};
return ( return (
@ -156,7 +169,7 @@ class Inspector extends React.Component {
<InspectorOverlay <InspectorOverlay
rootTag={this.props.rootTag} rootTag={this.props.rootTag}
inspected={this.state.inspected} inspected={this.state.inspected}
inspectedViewTag={this.props.inspectedViewTag} inspectedViewTag={this.state.inspectedViewTag}
onTouchInstance={this.onTouchInstance.bind(this)} onTouchInstance={this.onTouchInstance.bind(this)}
/>} />}
<View style={[styles.panelContainer, panelContainerStyle]}> <View style={[styles.panelContainer, panelContainerStyle]}>
@ -170,6 +183,8 @@ class Inspector extends React.Component {
hierarchy={this.state.hierarchy} hierarchy={this.state.hierarchy}
selection={this.state.selection} selection={this.state.selection}
setSelection={this.setSelection.bind(this)} setSelection={this.setSelection.bind(this)}
touchTargetting={Touchable.TOUCH_TARGET_DEBUG}
setTouchTargetting={this.setTouchTargetting.bind(this)}
/> />
</View> </View>
</View> </View>

View File

@ -70,10 +70,11 @@ class InspectorPanel extends React.Component {
pressed={this.props.perfing} pressed={this.props.perfing}
onClick={this.props.setPerfing} onClick={this.props.setPerfing}
/> />
<Button title={'Touchables'}
pressed={this.props.touchTargetting}
onClick={this.props.setTouchTargetting}
/>
</View> </View>
<Text style={styles.buttonText}>
{'Touchable.TOUCH_TARGET_DEBUG is ' + Touchable.TOUCH_TARGET_DEBUG}
</Text>
</View> </View>
); );
} }
@ -86,6 +87,8 @@ InspectorPanel.propTypes = {
inspected: PropTypes.object, inspected: PropTypes.object,
perfing: PropTypes.bool, perfing: PropTypes.bool,
setPerfing: PropTypes.func, setPerfing: PropTypes.func,
touchTargetting: PropTypes.bool,
setTouchTargetting: PropTypes.func,
}; };
class Button extends React.Component { class Button extends React.Component {

View File

@ -32,10 +32,10 @@ var AppContainer = React.createClass({
getInitialState: function() { getInitialState: function() {
return { return {
enabled: __DEV__,
inspectorVisible: false, inspectorVisible: false,
rootNodeHandle: null, rootNodeHandle: null,
rootImportanceForAccessibility: 'auto', rootImportanceForAccessibility: 'auto',
mainKey: 1,
}; };
}, },
@ -61,6 +61,12 @@ var AppContainer = React.createClass({
<Inspector <Inspector
rootTag={this.props.rootTag} rootTag={this.props.rootTag}
inspectedViewTag={this.state.rootNodeHandle} inspectedViewTag={this.state.rootNodeHandle}
onRequestRerenderApp={(updateInspectedViewTag) => {
this.setState(
(s) => ({mainKey: s.mainKey + 1}),
() => updateInspectedViewTag(ReactNative.findNodeHandle(this.refs.main))
);
}}
/> : /> :
null; null;
}, },
@ -84,6 +90,7 @@ var AppContainer = React.createClass({
var appView = var appView =
<View <View
ref="main" ref="main"
key={this.state.mainKey}
collapsable={!this.state.inspectorVisible} collapsable={!this.state.inspectorVisible}
style={styles.appContainer}> style={styles.appContainer}>
<RootComponent <RootComponent
@ -93,14 +100,10 @@ var AppContainer = React.createClass({
<Portal <Portal
onModalVisibilityChanged={this.setRootAccessibility}/> onModalVisibilityChanged={this.setRootAccessibility}/>
</View>; </View>;
let yellowBox = null; return __DEV__ ?
if (__DEV__) {
yellowBox = <YellowBox />;
}
return this.state.enabled ?
<View style={styles.appContainer}> <View style={styles.appContainer}>
{appView} {appView}
{yellowBox} <YellowBox />
{this.renderInspector()} {this.renderInspector()}
</View> : </View> :
appView; appView;

View File

@ -28,7 +28,7 @@ var AppContainer = React.createClass({
mixins: [Subscribable.Mixin], mixins: [Subscribable.Mixin],
getInitialState: function() { getInitialState: function() {
return { inspector: null }; return { inspector: null, mainKey: 1 };
}, },
toggleElementInspector: function() { toggleElementInspector: function() {
@ -37,6 +37,12 @@ var AppContainer = React.createClass({
: <Inspector : <Inspector
rootTag={this.props.rootTag} rootTag={this.props.rootTag}
inspectedViewTag={ReactNative.findNodeHandle(this.refs.main)} inspectedViewTag={ReactNative.findNodeHandle(this.refs.main)}
onRequestRerenderApp={(updateInspectedViewTag) => {
this.setState(
(s) => ({mainKey: s.mainKey + 1}),
() => updateInspectedViewTag(ReactNative.findNodeHandle(this.refs.main))
);
}}
/>; />;
this.setState({inspector}); this.setState({inspector});
}, },
@ -56,7 +62,10 @@ var AppContainer = React.createClass({
} }
return ( return (
<View style={styles.appContainer}> <View style={styles.appContainer}>
<View collapsible={false} style={styles.appContainer} ref="main"> <View
collapsible={false}
key={this.state.mainKey}
style={styles.appContainer} ref="main">
{this.props.children} {this.props.children}
</View> </View>
{yellowBox} {yellowBox}