Skip to content

Commit

Permalink
Use gesture-handler event type (software-mansion#2315)
Browse files Browse the repository at this point in the history
## Description

We had a problem with the casting event type. Because we used custom type from reanimated instead of event type from gesture-handler.
  • Loading branch information
piaskowyk authored Aug 23, 2021
1 parent 696f922 commit 56a1761
Showing 1 changed file with 16 additions and 23 deletions.
39 changes: 16 additions & 23 deletions src/reanimated2/hook/useAnimatedGestureHandler.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { MutableRefObject, useEffect, useRef } from 'react';
import { GestureHandlerStateChangeNativeEvent } from 'react-native-gesture-handler';
import {
GestureHandlerStateChangeNativeEvent,
State,
} from 'react-native-gesture-handler';
import { WorkletFunction } from '../commonTypes';
import { makeRemote } from '../core';
import { isWeb } from '../PlatformChecker';
Expand All @@ -15,14 +18,6 @@ interface Handler<T, TContext extends Context> extends WorkletFunction {
(event: T, context: TContext, isCanceledOrFailed?: boolean): void;
}

enum EventState {
FAILED = 1,
BEGAN,
CANCELLED,
ACTIVE,
END,
}

export interface GestureHandlers<T, TContext extends Context> {
[key: string]: Handler<T, TContext> | undefined;
onStart?: Handler<T, TContext>;
Expand Down Expand Up @@ -74,45 +69,43 @@ export function useAnimatedGestureHandler<
'worklet';
const event = useWeb ? e.nativeEvent : e;

if (event.state === EventState.BEGAN && handlers.onStart) {
if (event.state === State.BEGAN && handlers.onStart) {
handlers.onStart(event, context);
}
if (event.state === EventState.ACTIVE && handlers.onActive) {
if (event.state === State.ACTIVE && handlers.onActive) {
handlers.onActive(event, context);
}
if (
event.oldState === EventState.ACTIVE &&
event.state === EventState.END &&
event.oldState === State.ACTIVE &&
event.state === State.END &&
handlers.onEnd
) {
handlers.onEnd(event, context);
}
if (
event.oldState === EventState.BEGAN &&
event.state === EventState.FAILED &&
event.oldState === State.BEGAN &&
event.state === State.FAILED &&
handlers.onFail
) {
handlers.onFail(event, context);
}
if (
event.oldState === EventState.ACTIVE &&
event.state === EventState.CANCELLED &&
event.oldState === State.ACTIVE &&
event.state === State.CANCELLED &&
handlers.onCancel
) {
handlers.onCancel(event, context);
}
if (
(event.oldState === EventState.BEGAN ||
event.oldState === EventState.ACTIVE) &&
event.state !== EventState.BEGAN &&
event.state !== EventState.ACTIVE &&
(event.oldState === State.BEGAN || event.oldState === State.ACTIVE) &&
event.state !== State.BEGAN &&
event.state !== State.ACTIVE &&
handlers.onFinish
) {
handlers.onFinish(
event,
context,
event.state === EventState.CANCELLED ||
event.state === EventState.FAILED
event.state === State.CANCELLED || event.state === State.FAILED
);
}
};
Expand Down

0 comments on commit 56a1761

Please sign in to comment.