Skip to content

Commit ef765d4

Browse files
yungstersfacebook-github-bot
authored andcommitted
RN: Move TOUCH_TARGET_DEBUG to PressabilityDebug
Summary: This is just cleanup. When I migrated components to `Pressability` instead of `Touchable`, I left `TOUCH_TARGET_DEBUG` alone to minimize moving pieces. But I had created `PressabilityDebug` as the eventual destination for this logic. Now that `Text` is migrated away from `Touchable` (see D26106824 (f275514)), this cleans up the final internal reference to `Touchable`. Changelog: [General][Changed] - `Touchable.renderDebugView` now accepts `ColorValue` instead of `string | number`. [General][Removed] - Removed `Touchable.TOUCH_TARGET_DEBUG` property. Reviewed By: kacieb Differential Revision: D26108570 fbshipit-source-id: 2694c9a9c29182ae04a77ba6c2e4406fcd5a277e
1 parent aad423d commit ef765d4

File tree

3 files changed

+18
-52
lines changed

3 files changed

+18
-52
lines changed

Libraries/Components/Touchable/Touchable.js

+6-47
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,12 @@ const BoundingDimensions = require('./BoundingDimensions');
1414
const Platform = require('../../Utilities/Platform');
1515
const Position = require('./Position');
1616
const React = require('react');
17-
const StyleSheet = require('../../StyleSheet/StyleSheet');
1817
const UIManager = require('../../ReactNative/UIManager');
19-
const View = require('../View/View');
2018
const SoundManager = require('../Sound/SoundManager');
2119

22-
const normalizeColor = require('../../StyleSheet/normalizeColor');
20+
import {PressabilityDebugView} from '../../Pressability/PressabilityDebug';
2321

22+
import type {ColorValue} from '../../StyleSheet/StyleSheet';
2423
import type {EdgeInsetsProp} from '../../StyleSheet/EdgeInsetsPropType';
2524
import type {PressEvent} from '../../Types/CoreEventTypes';
2625

@@ -899,62 +898,22 @@ TouchableMixin.withoutDefaultFocusAndBlur = TouchableMixinWithoutDefaultFocusAnd
899898

900899
const Touchable = {
901900
Mixin: TouchableMixin,
902-
TOUCH_TARGET_DEBUG: false, // Highlights all touchable targets. Toggle with Inspector.
903901
/**
904902
* Renders a debugging overlay to visualize touch target with hitSlop (might not work on Android).
905903
*/
906904
renderDebugView: ({
907905
color,
908906
hitSlop,
909907
}: {
910-
color: string | number,
908+
color: ColorValue,
911909
hitSlop: EdgeInsetsProp,
912910
...
913911
}): null | React.Node => {
914-
if (!Touchable.TOUCH_TARGET_DEBUG) {
915-
return null;
912+
if (__DEV__) {
913+
return <PressabilityDebugView color={color} hitSlop={hitSlop} />;
916914
}
917-
if (!__DEV__) {
918-
throw Error(
919-
'Touchable.TOUCH_TARGET_DEBUG should not be enabled in prod!',
920-
);
921-
}
922-
const debugHitSlopStyle = {};
923-
hitSlop = hitSlop || {top: 0, bottom: 0, left: 0, right: 0};
924-
for (const key in hitSlop) {
925-
debugHitSlopStyle[key] = -hitSlop[key];
926-
}
927-
const normalizedColor = normalizeColor(color);
928-
if (typeof normalizedColor !== 'number') {
929-
return null;
930-
}
931-
const hexColor =
932-
'#' + ('00000000' + normalizedColor.toString(16)).substr(-8);
933-
return (
934-
<View
935-
pointerEvents="none"
936-
style={[
937-
styles.debug,
938-
/* $FlowFixMe(>=0.111.0 site=react_native_fb) This comment suppresses
939-
* an error found when Flow v0.111 was deployed. To see the error,
940-
* delete this comment and run Flow. */
941-
{
942-
borderColor: hexColor.slice(0, -2) + '55', // More opaque
943-
backgroundColor: hexColor.slice(0, -2) + '0F', // Less opaque
944-
...debugHitSlopStyle,
945-
},
946-
]}
947-
/>
948-
);
915+
return null;
949916
},
950917
};
951918

952-
const styles = StyleSheet.create({
953-
debug: {
954-
position: 'absolute',
955-
borderWidth: 1,
956-
borderStyle: 'dashed',
957-
},
958-
});
959-
960919
module.exports = Touchable;

Libraries/Inspector/Inspector.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ const Dimensions = require('../Utilities/Dimensions');
1414
const InspectorOverlay = require('./InspectorOverlay');
1515
const InspectorPanel = require('./InspectorPanel');
1616
const Platform = require('../Utilities/Platform');
17+
const PressabilityDebug = require('../Pressability/PressabilityDebug');
1718
const React = require('react');
1819
const ReactNative = require('../Renderer/shims/ReactNative');
1920
const StyleSheet = require('../StyleSheet/StyleSheet');
20-
const Touchable = require('../Components/Touchable/Touchable');
2121
const View = require('../Components/View/View');
2222

2323
const invariant = require('invariant');
@@ -279,7 +279,7 @@ class Inspector extends React.Component<
279279
}
280280

281281
setTouchTargeting(val: boolean) {
282-
Touchable.TOUCH_TARGET_DEBUG = val;
282+
PressabilityDebug.setEnabled(val);
283283
this.props.onRequestRerenderApp(inspectedView => {
284284
this.setState({inspectedView});
285285
});
@@ -318,7 +318,7 @@ class Inspector extends React.Component<
318318
hierarchy={this.state.hierarchy}
319319
selection={this.state.selection}
320320
setSelection={this.setSelection.bind(this)}
321-
touchTargeting={Touchable.TOUCH_TARGET_DEBUG}
321+
touchTargeting={PressabilityDebug.isEnabled()}
322322
setTouchTargeting={this.setTouchTargeting.bind(this)}
323323
networking={this.state.networking}
324324
setNetworking={this.setNetworking.bind(this)}

Libraries/Pressability/PressabilityDebug.js

+9-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import normalizeColor from '../StyleSheet/normalizeColor';
1414
import type {ColorValue} from '../StyleSheet/StyleSheet';
1515

16-
import Touchable from '../Components/Touchable/Touchable';
1716
import View from '../Components/View/View';
1817
import * as React from 'react';
1918

@@ -73,9 +72,17 @@ export function PressabilityDebugView({color, hitSlop}: Props): React.Node {
7372
return null;
7473
}
7574

75+
let isDebugEnabled = false;
76+
7677
export function isEnabled(): boolean {
7778
if (__DEV__) {
78-
return Touchable.TOUCH_TARGET_DEBUG;
79+
return isDebugEnabled;
7980
}
8081
return false;
8182
}
83+
84+
export function setEnabled(value: boolean): void {
85+
if (__DEV__) {
86+
isDebugEnabled = value;
87+
}
88+
}

0 commit comments

Comments
 (0)