Skip to content

Commit

Permalink
Support setting hitSlop with single value (JS) [re-land]
Browse files Browse the repository at this point in the history
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
  • Loading branch information
javache authored and facebook-github-bot committed Jan 31, 2022
1 parent 3f49e67 commit d682753
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 15 deletions.
5 changes: 2 additions & 3 deletions Libraries/Components/Pressable/Pressable.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import type {
} from '../View/ViewAccessibility';
import {PressabilityDebugView} from '../../Pressability/PressabilityDebug';
import usePressability from '../../Pressability/usePressability';
import {normalizeRect, type RectOrSize} from '../../StyleSheet/Rect';
import {type RectOrSize} from '../../StyleSheet/Rect';
import type {
LayoutEvent,
MouseEvent,
Expand Down Expand Up @@ -181,6 +181,7 @@ function Pressable(props: Props, forwardedRef): React.Node {
delayLongPress,
disabled,
focusable,
hitSlop,
onHoverIn,
onHoverOut,
onLongPress,
Expand All @@ -201,8 +202,6 @@ function Pressable(props: Props, forwardedRef): React.Node {

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

const hitSlop = normalizeRect(props.hitSlop);

const accessibilityState =
disabled != null
? {...props.accessibilityState, disabled}
Expand Down
4 changes: 2 additions & 2 deletions Libraries/Components/View/ViewPropTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import type {
Layout,
LayoutEvent,
} from '../../Types/CoreEventTypes';
import type {EdgeInsetsProp} from '../../StyleSheet/EdgeInsetsPropType';
import type {EdgeInsetsOrSizeProp} from '../../StyleSheet/EdgeInsetsPropType';
import type {Node} from 'react';
import type {ViewStyleProp} from '../../StyleSheet/StyleSheet';
import type {
Expand Down Expand Up @@ -481,7 +481,7 @@ export type ViewProps = $ReadOnly<{|
*
* See https://reactnative.dev/docs/view#hitslop
*/
hitSlop?: ?EdgeInsetsProp,
hitSlop?: ?EdgeInsetsOrSizeProp,

/**
* Controls whether the `View` can be the target of touch events.
Expand Down
14 changes: 5 additions & 9 deletions Libraries/Pressability/PressabilityDebug.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,14 @@

import normalizeColor from '../StyleSheet/normalizeColor';
import type {ColorValue} from '../StyleSheet/StyleSheet';
import {normalizeRect, type RectOrSize} from '../StyleSheet/Rect';

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

type Props = $ReadOnly<{|
color: ColorValue,
hitSlop: ?$ReadOnly<{|
bottom?: ?number,
left?: ?number,
right?: ?number,
top?: ?number,
|}>,
hitSlop: ?RectOrSize,
|}>;

/**
Expand All @@ -39,16 +35,16 @@ type Props = $ReadOnly<{|
* );
*
*/
export function PressabilityDebugView({color, hitSlop}: Props): React.Node {
export function PressabilityDebugView(props: Props): React.Node {
if (__DEV__) {
if (isEnabled()) {
const normalizedColor = normalizeColor(color);
const normalizedColor = normalizeColor(props.color);
if (typeof normalizedColor !== 'number') {
return null;
}
const baseColor =
'#' + (normalizedColor ?? 0).toString(16).padStart(8, '0');

const hitSlop = normalizeRect(props.hitSlop);
return (
<View
pointerEvents="none"
Expand Down
5 changes: 4 additions & 1 deletion Libraries/StyleSheet/EdgeInsetsPropType.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@

'use strict';

import type {Rect} from './Rect';
import type {Rect, RectOrSize} from './Rect';

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

0 comments on commit d682753

Please sign in to comment.