Skip to content

Commit d5c1de7

Browse files
sahrensFacebook Github Bot 3
authored andcommitted
Hook up touchable debugging to Inspector button
Reviewed By: vjeux Differential Revision: D3188719 fb-gh-sync-id: 271e902399900242f577a77807868bd2a28add37 fbshipit-source-id: 271e902399900242f577a77807868bd2a28add37
1 parent fb6133e commit d5c1de7

File tree

5 files changed

+44
-14
lines changed

5 files changed

+44
-14
lines changed

Libraries/Components/Touchable/Touchable.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -724,7 +724,7 @@ var TouchableMixin = {
724724

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

Libraries/Inspector/Inspector.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ var InspectorUtils = require('InspectorUtils');
1818
var React = require('React');
1919
var ReactNative = require('ReactNative');
2020
var StyleSheet = require('StyleSheet');
21+
var Touchable = require('Touchable');
2122
var UIManager = require('NativeModules').UIManager;
2223
var View = require('View');
2324

@@ -38,6 +39,7 @@ class Inspector extends React.Component {
3839
inspecting: true,
3940
perfing: false,
4041
inspected: null,
42+
inspectedViewTag: this.props.inspectedViewTag,
4143
};
4244
}
4345

@@ -61,6 +63,10 @@ class Inspector extends React.Component {
6163
}
6264
}
6365

66+
componentWillReceiveProps(newProps: Object) {
67+
this.setState({inspectedViewTag: newProps.inspectedViewTag});
68+
}
69+
6470
attachToDevtools(agent: Object) {
6571
var _hideWait = null;
6672
var hlSub = agent.sub('highlight', ({node, name, props}) => {
@@ -148,6 +154,13 @@ class Inspector extends React.Component {
148154
});
149155
}
150156

157+
setTouchTargetting(val: bool) {
158+
Touchable.TOUCH_TARGET_DEBUG = val;
159+
this.props.onRequestRerenderApp((inspectedViewTag) => {
160+
this.setState({inspectedViewTag});
161+
});
162+
}
163+
151164
render() {
152165
var panelContainerStyle = (this.state.panelPos === 'bottom') ? {bottom: 0} : {top: 0};
153166
return (
@@ -156,7 +169,7 @@ class Inspector extends React.Component {
156169
<InspectorOverlay
157170
rootTag={this.props.rootTag}
158171
inspected={this.state.inspected}
159-
inspectedViewTag={this.props.inspectedViewTag}
172+
inspectedViewTag={this.state.inspectedViewTag}
160173
onTouchInstance={this.onTouchInstance.bind(this)}
161174
/>}
162175
<View style={[styles.panelContainer, panelContainerStyle]}>
@@ -170,6 +183,8 @@ class Inspector extends React.Component {
170183
hierarchy={this.state.hierarchy}
171184
selection={this.state.selection}
172185
setSelection={this.setSelection.bind(this)}
186+
touchTargetting={Touchable.TOUCH_TARGET_DEBUG}
187+
setTouchTargetting={this.setTouchTargetting.bind(this)}
173188
/>
174189
</View>
175190
</View>

Libraries/Inspector/InspectorPanel.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,11 @@ class InspectorPanel extends React.Component {
7070
pressed={this.props.perfing}
7171
onClick={this.props.setPerfing}
7272
/>
73+
<Button title={'Touchables'}
74+
pressed={this.props.touchTargetting}
75+
onClick={this.props.setTouchTargetting}
76+
/>
7377
</View>
74-
<Text style={styles.buttonText}>
75-
{'Touchable.TOUCH_TARGET_DEBUG is ' + Touchable.TOUCH_TARGET_DEBUG}
76-
</Text>
7778
</View>
7879
);
7980
}
@@ -86,6 +87,8 @@ InspectorPanel.propTypes = {
8687
inspected: PropTypes.object,
8788
perfing: PropTypes.bool,
8889
setPerfing: PropTypes.func,
90+
touchTargetting: PropTypes.bool,
91+
setTouchTargetting: PropTypes.func,
8992
};
9093

9194
class Button extends React.Component {

Libraries/ReactIOS/renderApplication.android.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ var AppContainer = React.createClass({
3232

3333
getInitialState: function() {
3434
return {
35-
enabled: __DEV__,
3635
inspectorVisible: false,
3736
rootNodeHandle: null,
3837
rootImportanceForAccessibility: 'auto',
38+
mainKey: 1,
3939
};
4040
},
4141

@@ -61,6 +61,12 @@ var AppContainer = React.createClass({
6161
<Inspector
6262
rootTag={this.props.rootTag}
6363
inspectedViewTag={this.state.rootNodeHandle}
64+
onRequestRerenderApp={(updateInspectedViewTag) => {
65+
this.setState(
66+
(s) => ({mainKey: s.mainKey + 1}),
67+
() => updateInspectedViewTag(ReactNative.findNodeHandle(this.refs.main))
68+
);
69+
}}
6470
/> :
6571
null;
6672
},
@@ -84,6 +90,7 @@ var AppContainer = React.createClass({
8490
var appView =
8591
<View
8692
ref="main"
93+
key={this.state.mainKey}
8794
collapsable={!this.state.inspectorVisible}
8895
style={styles.appContainer}>
8996
<RootComponent
@@ -93,14 +100,10 @@ var AppContainer = React.createClass({
93100
<Portal
94101
onModalVisibilityChanged={this.setRootAccessibility}/>
95102
</View>;
96-
let yellowBox = null;
97-
if (__DEV__) {
98-
yellowBox = <YellowBox />;
99-
}
100-
return this.state.enabled ?
103+
return __DEV__ ?
101104
<View style={styles.appContainer}>
102105
{appView}
103-
{yellowBox}
106+
<YellowBox />
104107
{this.renderInspector()}
105108
</View> :
106109
appView;

Libraries/ReactIOS/renderApplication.ios.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ var AppContainer = React.createClass({
2828
mixins: [Subscribable.Mixin],
2929

3030
getInitialState: function() {
31-
return { inspector: null };
31+
return { inspector: null, mainKey: 1 };
3232
},
3333

3434
toggleElementInspector: function() {
@@ -37,6 +37,12 @@ var AppContainer = React.createClass({
3737
: <Inspector
3838
rootTag={this.props.rootTag}
3939
inspectedViewTag={ReactNative.findNodeHandle(this.refs.main)}
40+
onRequestRerenderApp={(updateInspectedViewTag) => {
41+
this.setState(
42+
(s) => ({mainKey: s.mainKey + 1}),
43+
() => updateInspectedViewTag(ReactNative.findNodeHandle(this.refs.main))
44+
);
45+
}}
4046
/>;
4147
this.setState({inspector});
4248
},
@@ -56,7 +62,10 @@ var AppContainer = React.createClass({
5662
}
5763
return (
5864
<View style={styles.appContainer}>
59-
<View collapsible={false} style={styles.appContainer} ref="main">
65+
<View
66+
collapsible={false}
67+
key={this.state.mainKey}
68+
style={styles.appContainer} ref="main">
6069
{this.props.children}
6170
</View>
6271
{yellowBox}

0 commit comments

Comments
 (0)