Skip to content

Commit d682753

Browse files
javachefacebook-github-bot
authored andcommitted
Support setting hitSlop with single value (JS) [re-land]
Summary: JS changes to support D32138347 (a96bdb7). This was previously reverted due to missing iOS Paper support. Changelog: [Android][Fixed] Enable hitSlop to be set using a single number. Original commit changeset: 91cfcc86582c Original Phabricator Diff: D32559015 (589b129) Reviewed By: yungsters Differential Revision: D33453327 fbshipit-source-id: d289a0a8b8208bc9c68e6ca537632b745e8196ed
1 parent 3f49e67 commit d682753

File tree

4 files changed

+13
-15
lines changed

4 files changed

+13
-15
lines changed

Libraries/Components/Pressable/Pressable.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import type {
2222
} from '../View/ViewAccessibility';
2323
import {PressabilityDebugView} from '../../Pressability/PressabilityDebug';
2424
import usePressability from '../../Pressability/usePressability';
25-
import {normalizeRect, type RectOrSize} from '../../StyleSheet/Rect';
25+
import {type RectOrSize} from '../../StyleSheet/Rect';
2626
import type {
2727
LayoutEvent,
2828
MouseEvent,
@@ -181,6 +181,7 @@ function Pressable(props: Props, forwardedRef): React.Node {
181181
delayLongPress,
182182
disabled,
183183
focusable,
184+
hitSlop,
184185
onHoverIn,
185186
onHoverOut,
186187
onLongPress,
@@ -201,8 +202,6 @@ function Pressable(props: Props, forwardedRef): React.Node {
201202

202203
const [pressed, setPressed] = usePressState(testOnly_pressed === true);
203204

204-
const hitSlop = normalizeRect(props.hitSlop);
205-
206205
const accessibilityState =
207206
disabled != null
208207
? {...props.accessibilityState, disabled}

Libraries/Components/View/ViewPropTypes.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import type {
1818
Layout,
1919
LayoutEvent,
2020
} from '../../Types/CoreEventTypes';
21-
import type {EdgeInsetsProp} from '../../StyleSheet/EdgeInsetsPropType';
21+
import type {EdgeInsetsOrSizeProp} from '../../StyleSheet/EdgeInsetsPropType';
2222
import type {Node} from 'react';
2323
import type {ViewStyleProp} from '../../StyleSheet/StyleSheet';
2424
import type {
@@ -481,7 +481,7 @@ export type ViewProps = $ReadOnly<{|
481481
*
482482
* See https://reactnative.dev/docs/view#hitslop
483483
*/
484-
hitSlop?: ?EdgeInsetsProp,
484+
hitSlop?: ?EdgeInsetsOrSizeProp,
485485

486486
/**
487487
* Controls whether the `View` can be the target of touch events.

Libraries/Pressability/PressabilityDebug.js

+5-9
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,14 @@
1010

1111
import normalizeColor from '../StyleSheet/normalizeColor';
1212
import type {ColorValue} from '../StyleSheet/StyleSheet';
13+
import {normalizeRect, type RectOrSize} from '../StyleSheet/Rect';
1314

1415
import View from '../Components/View/View';
1516
import * as React from 'react';
1617

1718
type Props = $ReadOnly<{|
1819
color: ColorValue,
19-
hitSlop: ?$ReadOnly<{|
20-
bottom?: ?number,
21-
left?: ?number,
22-
right?: ?number,
23-
top?: ?number,
24-
|}>,
20+
hitSlop: ?RectOrSize,
2521
|}>;
2622

2723
/**
@@ -39,16 +35,16 @@ type Props = $ReadOnly<{|
3935
* );
4036
*
4137
*/
42-
export function PressabilityDebugView({color, hitSlop}: Props): React.Node {
38+
export function PressabilityDebugView(props: Props): React.Node {
4339
if (__DEV__) {
4440
if (isEnabled()) {
45-
const normalizedColor = normalizeColor(color);
41+
const normalizedColor = normalizeColor(props.color);
4642
if (typeof normalizedColor !== 'number') {
4743
return null;
4844
}
4945
const baseColor =
5046
'#' + (normalizedColor ?? 0).toString(16).padStart(8, '0');
51-
47+
const hitSlop = normalizeRect(props.hitSlop);
5248
return (
5349
<View
5450
pointerEvents="none"

Libraries/StyleSheet/EdgeInsetsPropType.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010

1111
'use strict';
1212

13-
import type {Rect} from './Rect';
13+
import type {Rect, RectOrSize} from './Rect';
1414

15+
// TODO: allow all EdgeInsets-like property to be set using a single number
16+
// and unify EdgeInsetsProp with EdgeInsetsOrSizeProp
1517
export type EdgeInsetsProp = Rect;
18+
export type EdgeInsetsOrSizeProp = RectOrSize;

0 commit comments

Comments
 (0)