Skip to content

Commit 2ddda66

Browse files
committed
Activate ios buttons on pointer up
1 parent 9b87dbc commit 2ddda66

4 files changed

Lines changed: 14 additions & 15 deletions

File tree

packages/react-native-gesture-handler/apple/Handlers/RNNativeViewHandler.mm

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -275,11 +275,12 @@ - (void)handleTouchUpOutside:(UIView *)sender forEvent:(UIEvent *)event
275275

276276
- (void)handleTouchUpInside:(UIView *)sender forEvent:(UIEvent *)event
277277
{
278-
[self sendEventsInState:RNGestureHandlerStateEnd
279-
forViewWithTag:sender.reactTag
280-
withExtraData:[RNGestureHandlerEventExtraData forPointerInside:YES
281-
withNumberOfTouches:event.allTouches.count
282-
withPointerType:_pointerType]];
278+
RNGestureHandlerEventExtraData *extraData = [RNGestureHandlerEventExtraData forPointerInside:YES
279+
withNumberOfTouches:event.allTouches.count
280+
withPointerType:_pointerType];
281+
282+
[self sendActiveStateEventIfChangedForView:sender extraData:extraData];
283+
[self sendEventsInState:RNGestureHandlerStateEnd forViewWithTag:sender.reactTag withExtraData:extraData];
283284
}
284285

285286
- (void)handleDragExit:(UIView *)sender forEvent:(UIEvent *)event

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ class InnerBaseButton extends React.Component<BaseButtonWithRefProps> {
5050
nativeEvent,
5151
}: HandlerStateChangeEvent<NativeViewGestureHandlerPayload>) => {
5252
const { state, oldState, pointerInside } = nativeEvent;
53-
const active = pointerInside && state === State.ACTIVE;
53+
const active =
54+
pointerInside && (state === State.BEGAN || state === State.ACTIVE);
5455

5556
if (active !== this.lastActive && this.props.onActiveStateChange) {
5657
this.props.onActiveStateChange(active);

packages/react-native-gesture-handler/src/components/touchables/GenericTouchable.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as React from 'react';
22
import { Component } from 'react';
3-
import { Animated, Platform } from 'react-native';
3+
import { Animated } from 'react-native';
44

55
import type {
66
GestureEvent,
@@ -174,10 +174,7 @@ export default class GenericTouchable extends Component<
174174
// Need to handle case with external cancellation (e.g. by ScrollView)
175175
this.moveToState(TOUCHABLE_STATE.UNDETERMINED);
176176
} else if (
177-
// This platform check is an implication of slightly different behavior of handlers on different platform.
178-
// And Android "Active" state is achieving on first move of a finger, not on press in.
179-
// On iOS event on "Began" is not delivered.
180-
state === (Platform.OS !== 'android' ? State.ACTIVE : State.BEGAN) &&
177+
state === State.BEGAN &&
181178
this.STATE === TOUCHABLE_STATE.UNDETERMINED
182179
) {
183180
// Moving inside requires

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,16 +69,16 @@ export const BaseButton = (props: BaseButtonProps) => {
6969
};
7070

7171
const onDeactivate = (e: EndCallbackEventType) => {
72+
props.onDeactivate?.(e);
73+
};
74+
75+
const onFinalize = (e: EndCallbackEventType) => {
7276
onActiveStateChange?.(false);
7377

7478
if (!e.canceled && !longPressDetected.current) {
7579
onPress?.(e.pointerInside);
7680
}
7781

78-
props.onDeactivate?.(e);
79-
};
80-
81-
const onFinalize = (e: EndCallbackEventType) => {
8282
if (longPressTimeout.current !== undefined) {
8383
clearTimeout(longPressTimeout.current);
8484
longPressTimeout.current = undefined;

0 commit comments

Comments
 (0)