Skip to content

Commit 2154bfd

Browse files
authored
[General] Remove onActiveStateChange from Touchable (#4101)
## Description Removes `onActiveStateChange` from the `Touchable` component. With `onPressIn` and `onPressOut`, this callback seems redundant and confusing since the state transitions regarding the button are inconsistent between platforms. ## Test plan Static checks
1 parent f071853 commit 2154bfd

4 files changed

Lines changed: 8 additions & 49 deletions

File tree

packages/docs-gesture-handler/docs/components/touchable.mdx

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -285,14 +285,6 @@ onLongPress?: () => void;
285285
Triggered when the button gets pressed for at least [`delayLongPress`](#delaylongpress) milliseconds.
286286

287287

288-
### onActiveStateChange
289-
290-
```ts
291-
onActiveStateChange?: (active: boolean) => void;
292-
```
293-
294-
Triggered when the button transitions between active and inactive states. It passes the current active state as a boolean variable to the method as the first parameter.
295-
296288
### delayLongPress
297289

298290
```ts

packages/react-native-gesture-handler/src/__tests__/api_v3.test.tsx

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -107,31 +107,6 @@ describe('[API v3] Components', () => {
107107
expect(pressFn).not.toHaveBeenCalled();
108108
});
109109

110-
test('calls onActiveStateChange with correct values', () => {
111-
const activeStateFn = jest.fn();
112-
113-
const Example = () => (
114-
<GestureHandlerRootView>
115-
<Touchable testID="touchable" onActiveStateChange={activeStateFn} />
116-
</GestureHandlerRootView>
117-
);
118-
119-
render(<Example />);
120-
const gesture = getByGestureTestId('touchable');
121-
122-
act(() => {
123-
fireGestureHandler(gesture, [
124-
{ oldState: State.UNDETERMINED, state: State.BEGAN },
125-
{ oldState: State.BEGAN, state: State.ACTIVE },
126-
{ oldState: State.ACTIVE, state: State.END },
127-
]);
128-
});
129-
130-
expect(activeStateFn).toHaveBeenCalledTimes(2);
131-
expect(activeStateFn).toHaveBeenNthCalledWith(1, true);
132-
expect(activeStateFn).toHaveBeenNthCalledWith(2, false);
133-
});
134-
135110
test('calls onLongPress after delayLongPress and suppresses onPress', () => {
136111
jest.useFakeTimers();
137112

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

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ export const Touchable = (props: TouchableProps) => {
3232
onPress,
3333
onPressIn,
3434
onPressOut,
35-
onActiveStateChange,
3635
children,
3736
disabled = false,
3837
ref,
@@ -71,27 +70,20 @@ export const Touchable = (props: TouchableProps) => {
7170
[startLongPressTimer, onPressIn]
7271
);
7372

74-
const onActivate = useCallback(
75-
(e: CallbackEventType) => {
76-
onActiveStateChange?.(true);
77-
78-
if (!e.pointerInside && longPressTimeout.current !== undefined) {
79-
clearTimeout(longPressTimeout.current);
80-
longPressTimeout.current = undefined;
81-
}
82-
},
83-
[onActiveStateChange]
84-
);
73+
const onActivate = useCallback((e: CallbackEventType) => {
74+
if (!e.pointerInside && longPressTimeout.current !== undefined) {
75+
clearTimeout(longPressTimeout.current);
76+
longPressTimeout.current = undefined;
77+
}
78+
}, []);
8579

8680
const onDeactivate = useCallback(
8781
(e: EndCallbackEventType) => {
88-
onActiveStateChange?.(false);
89-
9082
if (!e.canceled && !longPressDetected.current) {
9183
onPress?.(e.pointerInside);
9284
}
9385
},
94-
[onActiveStateChange, onPress]
86+
[onPress]
9587
);
9688

9789
const onFinalize = useCallback(

packages/react-native-gesture-handler/src/v3/components/Touchable/TouchableProps.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ type PressableAndroidRippleConfig = {
1818
type RippleProps = 'rippleColor' | 'rippleRadius' | 'borderless' | 'foreground';
1919

2020
export type TouchableProps = Omit<ButtonProps, RippleProps | 'enabled'> &
21-
Omit<BaseButtonProps, keyof RawButtonProps> & {
21+
Omit<BaseButtonProps, keyof RawButtonProps | 'onActiveStateChange'> & {
2222
/**
2323
* Configuration for the ripple effect on Android.
2424
*/

0 commit comments

Comments
 (0)