Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -253,11 +253,6 @@ - (void)handleTouchDown:(UIView *)sender forEvent:(UIEvent *)event
withExtraData:[RNGestureHandlerEventExtraData forPointerInside:YES
withNumberOfTouches:event.allTouches.count
withPointerType:_pointerType]];

[self sendActiveStateEventIfChangedForView:sender
extraData:[RNGestureHandlerEventExtraData forPointerInside:YES
withNumberOfTouches:event.allTouches.count
withPointerType:_pointerType]];
}

- (void)handleTouchUpOutside:(UIView *)sender forEvent:(UIEvent *)event
Expand All @@ -275,11 +270,12 @@ - (void)handleTouchUpOutside:(UIView *)sender forEvent:(UIEvent *)event

- (void)handleTouchUpInside:(UIView *)sender forEvent:(UIEvent *)event
{
[self sendEventsInState:RNGestureHandlerStateEnd
forViewWithTag:sender.reactTag
withExtraData:[RNGestureHandlerEventExtraData forPointerInside:YES
withNumberOfTouches:event.allTouches.count
withPointerType:_pointerType]];
RNGestureHandlerEventExtraData *extraData = [RNGestureHandlerEventExtraData forPointerInside:YES
withNumberOfTouches:event.allTouches.count
withPointerType:_pointerType];

[self sendActiveStateEventIfChangedForView:sender extraData:extraData];
[self sendEventsInState:RNGestureHandlerStateEnd forViewWithTag:sender.reactTag withExtraData:extraData];
Comment thread
j-piasecki marked this conversation as resolved.
}

- (void)handleDragExit:(UIView *)sender forEvent:(UIEvent *)event
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
const panGesture = renderHook(() =>
usePanGesture({
disableReanimated: true,
onBegin: (e) => onBegin(e),

Check warning on line 19 in packages/react-native-gesture-handler/src/__tests__/api_v3.test.tsx

View workflow job for this annotation

GitHub Actions / check

Unsafe return of an `any` typed value
onActivate: (e) => onStart(e),

Check warning on line 20 in packages/react-native-gesture-handler/src/__tests__/api_v3.test.tsx

View workflow job for this annotation

GitHub Actions / check

Unsafe return of an `any` typed value
})
).result.current;

Expand Down Expand Up @@ -128,13 +128,13 @@
render(<Example />);

const gesture = getByGestureTestId('touchable') as SingleGesture<
any,

Check warning on line 131 in packages/react-native-gesture-handler/src/__tests__/api_v3.test.tsx

View workflow job for this annotation

GitHub Actions / check

Unexpected any. Specify a different type
any,

Check warning on line 132 in packages/react-native-gesture-handler/src/__tests__/api_v3.test.tsx

View workflow job for this annotation

GitHub Actions / check

Unexpected any. Specify a different type
any
>;
const { jsEventHandler } = gesture.detectorCallbacks;

// Fire BEGAN
// Fire BEGAN — long press timer starts here
act(() => {
jsEventHandler?.({
oldState: State.UNDETERMINED,
Expand All @@ -145,7 +145,7 @@
});
});

// Fire ACTIVE — long press timer starts here (on iOS / non-Android)
// Fire ACTIVE
act(() => {
jsEventHandler?.({
oldState: State.BEGAN,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,37 +36,38 @@ class InnerBaseButton extends React.Component<BaseButtonWithRefProps> {
delayLongPress: 600,
};

private lastActive: boolean;
private lastIsPressed: boolean;
private longPressTimeout: ReturnType<typeof setTimeout> | undefined;
private longPressDetected: boolean;

constructor(props: BaseButtonWithRefProps) {
super(props);
this.lastActive = false;
this.lastIsPressed = false;
this.longPressDetected = false;
}

private handleEvent = ({
nativeEvent,
}: HandlerStateChangeEvent<NativeViewGestureHandlerPayload>) => {
const { state, oldState, pointerInside } = nativeEvent;
const active = pointerInside && state === State.ACTIVE;
const isPressed =
pointerInside && (state === State.BEGAN || state === State.ACTIVE);

if (active !== this.lastActive && this.props.onActiveStateChange) {
this.props.onActiveStateChange(active);
if (isPressed !== this.lastIsPressed && this.props.onActiveStateChange) {
this.props.onActiveStateChange(isPressed);
}

if (
!this.longPressDetected &&
oldState === State.ACTIVE &&
state !== State.CANCELLED &&
this.lastActive &&
this.lastIsPressed &&
this.props.onPress
) {
this.props.onPress(pointerInside);
}

if (!this.lastActive && state === State.BEGAN && pointerInside) {
if (!this.lastIsPressed && state === State.BEGAN && pointerInside) {
this.longPressDetected = false;
if (this.props.onLongPress) {
this.longPressTimeout = setTimeout(
Expand All @@ -93,7 +94,7 @@ class InnerBaseButton extends React.Component<BaseButtonWithRefProps> {
this.longPressTimeout = undefined;
}

this.lastActive = active;
this.lastIsPressed = isPressed;
};

private onLongPress = () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';
import { Component } from 'react';
import { Animated, Platform } from 'react-native';
import { Animated } from 'react-native';

import type {
GestureEvent,
Expand Down Expand Up @@ -174,10 +174,7 @@ export default class GenericTouchable extends Component<
// Need to handle case with external cancellation (e.g. by ScrollView)
this.moveToState(TOUCHABLE_STATE.UNDETERMINED);
} else if (
// This platform check is an implication of slightly different behavior of handlers on different platform.
// And Android "Active" state is achieving on first move of a finger, not on press in.
// On iOS event on "Began" is not delivered.
state === (Platform.OS !== 'android' ? State.ACTIVE : State.BEGAN) &&
state === State.BEGAN &&
this.STATE === TOUCHABLE_STATE.UNDETERMINED
) {
// Moving inside requires
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,16 @@ export const BaseButton = (props: BaseButtonProps) => {
};

const onDeactivate = (e: EndCallbackEventType) => {
props.onDeactivate?.(e);
};

const onFinalize = (e: EndCallbackEventType) => {
onActiveStateChange?.(false);

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

props.onDeactivate?.(e);
};

const onFinalize = (e: EndCallbackEventType) => {
if (longPressTimeout.current !== undefined) {
clearTimeout(longPressTimeout.current);
longPressTimeout.current = undefined;
Expand Down
Loading