Skip to content

Remove AnimatedEvent action type from NativeDetector - #3646

Merged
m-bert merged 4 commits into
nextfrom
@mbert/native-animated-events
Jul 31, 2025
Merged

Remove AnimatedEvent action type from NativeDetector#3646
m-bert merged 4 commits into
nextfrom
@mbert/native-animated-events

Conversation

@m-bert

@m-bert m-bert commented Jul 30, 2025

Copy link
Copy Markdown
Collaborator

Description

We came to a conclusion that current event handling may conflict with gesture relations, such as simultaneous when one of the gestures is using Animated. This PR removes AnimatedEvent action type from NativeDetector and adds flag to GestureHandler, which represents if handler should send events for Animated.

Status

  • Android ✅

  • iOS ✅

Test plan

Test pan1, pan2 and gesture from the code below.

Note

Since simultaneous relation is not yet implemented, only first pan works when gesture is used. On Android you can solve that ba commenting out otherHandler.cancel() in makeActive function (this line)

Tested on the following code:
import * as React from 'react';
import { Animated, Button, useAnimatedValue } from 'react-native';
import {
  GestureHandlerRootView,
  NativeDetector,
  useGesture,
} from 'react-native-gesture-handler';

export default function App() {
  const [visible, setVisible] = React.useState(true);

  const value = useAnimatedValue(0);
  const event = Animated.event(
    [{ nativeEvent: { handlerData: { translationX: value } } }],
    {
      useNativeDriver: true,
    }
  );

  const pan1 = useGesture('PanGestureHandler', {
    onUpdate: (e: any) => {
      console.log('Pan1 update:', e);
    },
  });

  const pan2 = useGesture('PanGestureHandler', {
    onUpdate: event,
    dispatchesAnimatedEvents: true,
  });

  const gesture = {
    tag: [pan1.tag, pan2.tag],
    gestureEvents: {
      onGestureHandlerStateChange: (e) => {
        pan1.gestureEvents.onGestureHandlerStateChange(e);
        pan2.gestureEvents.onGestureHandlerStateChange(e);
      },
      onGestureHandlerEvent: pan1.gestureEvents.onGestureHandlerEvent,
      onGestureHandlerAnimatedEvent:
        pan2.gestureEvents.onGestureHandlerAnimatedEvent,
      onGestureHandlerTouchEvent: (e) => {
        pan1.gestureEvents.onGestureHandlerTouchEvent(e);
        pan2.gestureEvents.onGestureHandlerTouchEvent(e);
      },
    },
    dispatchesAnimatedEvents: true, // Assuming this is always true for this example
  };

  return (
    <GestureHandlerRootView
      style={{ flex: 1, backgroundColor: 'white', paddingTop: 8 }}>
      <Button
        title="Toggle visibility"
        onPress={() => {
          setVisible(!visible);
        }}
      />

      {visible && (
        <NativeDetector gesture={gesture}>
          <Animated.View
            style={[
              {
                width: 150,
                height: 150,
                backgroundColor: 'blue',
                opacity: 0.5,
                borderWidth: 10,
                borderColor: 'green',
                marginTop: 20,
                marginLeft: 40,
              },
              { transform: [{ translateX: value }] },
            ]}
          />
        </NativeDetector>
      )}
    </GestureHandlerRootView>
  );
}

@m-bert
m-bert requested a review from j-piasecki July 30, 2025 11:27
@@ -176,6 +176,7 @@ - (instancetype)initWithReactTag:(NSNumber *)reactTag
state:(RNGestureHandlerState)state
extraData:(RNGestureHandlerEventExtraData *)extraData
forActionType:(NSInteger)actionType

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is action type needed now in the events?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like it is not. Removed in 9cc3073

withActionType:(RNGestureHandlerActionType)actionType
forRecognizer:(UIGestureRecognizer *)recognizer;
withActionType:(RNGestureHandlerActionType)actionType
withAnimatedEvent:(BOOL)useAnimatedEvent

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
withAnimatedEvent:(BOOL)useAnimatedEvent
forAnimated:(BOOL)forAnimated

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, looks better. Done in 118467e

state:(RNGestureHandlerState)state
extraData:(RNGestureHandlerEventExtraData *)extraData
forActionType:(NSInteger)actionType
withAnimatedEvent:(BOOL)useAnimatedEvent

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
withAnimatedEvent:(BOOL)useAnimatedEvent
forAnimated:(BOOL)forAnimated

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also done in 118467e

@m-bert
m-bert marked this pull request as ready for review July 30, 2025 11:49
@m-bert
m-bert merged commit 728a895 into next Jul 31, 2025
5 of 6 checks passed
@m-bert
m-bert deleted the @mbert/native-animated-events branch July 31, 2025 14:40
m-bert added a commit that referenced this pull request Aug 4, 2025
## Description

#3646 removed _animated native detector_ action type. However, now we have to pass `dispatchesAnimatedEvents` to gesture config, what was not done automatically. This PR fixes it.

## Test plan

Tested on `basic-example`
j-piasecki added a commit that referenced this pull request Aug 4, 2025
## Description


#3646
removed the Animated action type, but there are still references left to
`dispatchesAnimatedEvents` in the native detector, while the property
has been moved to the config of individual gestures.

This PR removes those references.

## Test plan

Check the native detector examples
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants