Skip to content

Commit d94ab44

Browse files
committed
reduce redundancy
1 parent 07ee909 commit d94ab44

File tree

13 files changed

+76
-548
lines changed

13 files changed

+76
-548
lines changed

packages/react-native-gesture-handler/src/components/Pressable/Pressable.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import { GestureObjects as Gesture } from '../../handlers/gestures/gestureObject
99
import { GestureDetector } from '../../handlers/gestures/GestureDetector';
1010
import {
1111
PressableEvent,
12-
PressableProps,
1312
PressableDimensions,
13+
LegacyPressableProps,
1414
} from './PressableProps';
1515
import {
1616
Insets,
@@ -40,7 +40,7 @@ import { PressableStateMachine } from './StateMachine';
4040
const DEFAULT_LONG_PRESS_DURATION = 500;
4141
const IS_TEST_ENV = isTestEnv();
4242

43-
const Pressable = (props: PressableProps) => {
43+
const Pressable = (props: LegacyPressableProps) => {
4444
const {
4545
testOnly_pressed,
4646
hitSlop,

packages/react-native-gesture-handler/src/components/Pressable/PressableProps.tsx

Lines changed: 42 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
View,
1010
} from 'react-native';
1111
import { RelationPropType } from '../utils';
12+
import { AnyGesture } from '../../v3/types';
1213

1314
export type PressableDimensions = { width: number; height: number };
1415

@@ -30,7 +31,47 @@ export type InnerPressableEvent = {
3031

3132
export type PressableEvent = { nativeEvent: InnerPressableEvent };
3233

33-
export interface PressableProps
34+
export interface LegacyPressableProps extends CommonPressableProps {
35+
/**
36+
* A gesture object or an array of gesture objects containing the configuration and callbacks to be
37+
* used with the Pressable's gesture handlers.
38+
*/
39+
simultaneousWithExternalGesture?: RelationPropType;
40+
41+
/**
42+
* A gesture object or an array of gesture objects containing the configuration and callbacks to be
43+
* used with the Pressable's gesture handlers.
44+
*/
45+
requireExternalGestureToFail?: RelationPropType;
46+
47+
/**
48+
* A gesture object or an array of gesture objects containing the configuration and callbacks to be
49+
* used with the Pressable's gesture handlers.
50+
*/
51+
blocksExternalGesture?: RelationPropType;
52+
}
53+
54+
export interface PressableProps extends CommonPressableProps {
55+
/**
56+
* A gesture object or an array of gesture objects containing the configuration and callbacks to be
57+
* used with the Pressable's gesture handlers.
58+
*/
59+
simultaneousWith?: AnyGesture;
60+
61+
/**
62+
* A gesture object or an array of gesture objects containing the configuration and callbacks to be
63+
* used with the Pressable's gesture handlers.
64+
*/
65+
requireToFail?: AnyGesture;
66+
67+
/**
68+
* A gesture object or an array of gesture objects containing the configuration and callbacks to be
69+
* used with the Pressable's gesture handlers.
70+
*/
71+
block?: AnyGesture;
72+
}
73+
74+
interface CommonPressableProps
3475
extends AccessibilityProps,
3576
Omit<ViewProps, 'children' | 'style' | 'hitSlop'> {
3677
/**
@@ -149,24 +190,6 @@ export interface PressableProps
149190
*/
150191
unstable_pressDelay?: number;
151192

152-
/**
153-
* A gesture object or an array of gesture objects containing the configuration and callbacks to be
154-
* used with the Pressable's gesture handlers.
155-
*/
156-
simultaneousWithExternalGesture?: RelationPropType;
157-
158-
/**
159-
* A gesture object or an array of gesture objects containing the configuration and callbacks to be
160-
* used with the Pressable's gesture handlers.
161-
*/
162-
requireExternalGestureToFail?: RelationPropType;
163-
164-
/**
165-
* A gesture object or an array of gesture objects containing the configuration and callbacks to be
166-
* used with the Pressable's gesture handlers.
167-
*/
168-
blocksExternalGesture?: RelationPropType;
169-
170193
/**
171194
* @deprecated This property is no longer used, and will be removed in the future.
172195
*/

packages/react-native-gesture-handler/src/components/Pressable/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export type {
2+
LegacyPressableProps,
23
PressableProps,
34
PressableStateCallbackType,
45
} from './PressableProps';

packages/react-native-gesture-handler/src/components/Pressable/utils.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
InnerPressableEvent,
1414
PressableEvent,
1515
} from './PressableProps';
16+
import { HoverGestureEvent, LongPressGestureEvent } from '../../v3';
1617

1718
const numberAsInset = (value: number): Insets => ({
1819
left: value,
@@ -45,9 +46,12 @@ const touchDataToPressEvent = (
4546
});
4647

4748
const gestureToPressEvent = (
48-
event: GestureStateChangeEvent<
49-
HoverGestureHandlerEventPayload | LongPressGestureHandlerEventPayload
50-
>,
49+
event:
50+
| GestureStateChangeEvent<
51+
HoverGestureHandlerEventPayload | LongPressGestureHandlerEventPayload
52+
>
53+
| HoverGestureEvent
54+
| LongPressGestureEvent,
5155
timestamp: number,
5256
targetId: number
5357
): InnerPressableEvent => ({
@@ -73,9 +77,12 @@ const isTouchWithinInset = (
7377
(touch?.locationY ?? 0) > -(inset.top ?? 0);
7478

7579
const gestureToPressableEvent = (
76-
event: GestureStateChangeEvent<
77-
HoverGestureHandlerEventPayload | LongPressGestureHandlerEventPayload
78-
>
80+
event:
81+
| GestureStateChangeEvent<
82+
HoverGestureHandlerEventPayload | LongPressGestureHandlerEventPayload
83+
>
84+
| HoverGestureEvent
85+
| LongPressGestureEvent
7986
): PressableEvent => {
8087
const timestamp = Date.now();
8188

packages/react-native-gesture-handler/src/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,9 @@ export type {
147147
} from './handlers/gestureHandlerTypesCompat';
148148

149149
export type {
150-
PressableProps as LegacyPressableProps,
151-
PressableStateCallbackType as LegacyPressableCallbackType,
150+
PressableProps,
151+
LegacyPressableProps,
152+
PressableStateCallbackType,
152153
} from './components/Pressable';
153154
export { default as LegacyPressable } from './components/Pressable';
154155

packages/react-native-gesture-handler/src/v3/components/Pressable/Pressable.tsx renamed to packages/react-native-gesture-handler/src/v3/components/Pressable.tsx

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ import React, {
66
useState,
77
} from 'react';
88
import {
9+
PressableDimensions,
910
PressableEvent,
1011
PressableProps,
11-
FullPressableDimensions,
12-
} from './PressableProps';
12+
} from '../../components/Pressable/PressableProps';
1313
import {
1414
Insets,
1515
LayoutChangeEvent,
@@ -23,21 +23,23 @@ import {
2323
gestureTouchToPressableEvent,
2424
isTouchWithinInset,
2525
gestureToPressableEvent,
26-
} from './utils';
27-
28-
import { getStatesConfig, StateMachineEvent } from './stateDefinitions';
29-
import { PressableStateMachine } from './StateMachine';
26+
} from '../../components/Pressable/utils';
27+
import {
28+
getStatesConfig,
29+
StateMachineEvent,
30+
} from '../../components/Pressable/stateDefinitions';
31+
import { PressableStateMachine } from '../../components/Pressable/StateMachine';
3032
import {
3133
useHoverGesture,
3234
useLongPressGesture,
3335
useNativeGesture,
3436
useSimultaneousGestures,
35-
} from '../../hooks';
36-
import { GestureDetector } from '../../detectors';
37-
import { PureNativeButton } from '../GestureButtons';
37+
} from '../hooks';
38+
import { GestureDetector } from '../detectors';
39+
import { PureNativeButton } from './GestureButtons';
3840

39-
import { PressabilityDebugView } from '../../../handlers/PressabilityDebugView';
40-
import { INT32_MAX } from '../../../utils';
41+
import { PressabilityDebugView } from '../../handlers/PressabilityDebugView';
42+
import { INT32_MAX } from '../../utils';
4143
const DEFAULT_LONG_PRESS_DURATION = 500;
4244
// const IS_TEST_ENV = isTestEnv();
4345

@@ -75,11 +77,9 @@ const Pressable = (props: PressableProps) => {
7577
const pressDelayTimeoutRef = useRef<number | null>(null);
7678
const isOnPressAllowed = useRef<boolean>(true);
7779
const isCurrentlyPressed = useRef<boolean>(false);
78-
const dimensions = useRef<FullPressableDimensions>({
80+
const dimensions = useRef<PressableDimensions>({
7981
width: 0,
8082
height: 0,
81-
x: 0,
82-
y: 0,
8383
});
8484

8585
const normalizedHitSlop: Insets = useMemo(

packages/react-native-gesture-handler/src/v3/components/Pressable/PressableProps.tsx

Lines changed: 0 additions & 180 deletions
This file was deleted.

0 commit comments

Comments
 (0)