software-mansion / react-native-gesture-handler

Declarative API exposing platform native touch and gesture system to React Native.
https://docs.swmansion.com/react-native-gesture-handler/
MIT License
6.13k stars 982 forks source link

ReanimatedSwipeable Error: Tried to modify key `velocity` of an object which has already passed to a worklet #3080

Closed ucheNkadiCode closed 2 months ago

ucheNkadiCode commented 2 months ago

Description

I changed from the Swipeable Object to the ReanimatedObject because Swipeable has been deprecated in gesture handler

Steps to reproduce

My code (abbreviated)

import Swipeable, {
  SwipeableMethods,
} from "react-native-gesture-handler/ReanimatedSwipeable";

export const NoteRow: React.FC<NoteRowProps> = 
  ({
... 
const swipeableRef = useRef<SwipeableMethods | null>(null);
    const openCardActions = useCallback(() => {
      swipeableRef.current?.openRight();
    }, []);
    const closeCardActions = useCallback(() => {
      swipeableRef.current?.close();
    }, []);

 <Swipeable
          ref={(ref) => (swipeableRef.current = ref)}
          renderRightActions={renderRightActions}
          onBegan={() => {
            console.log(`On began`);
            handleSwipe(
              queueItemID ? queueItemID : workoutToShow.workoutID,
              typeof cardIndex === "number" ? cardIndex : undefined
            );
          }}
          rightThreshold={ScreenUtils.getWidth() * 0.1}
          enabled={enableSwipe}
        >
...
</Swipeable

With this warning - react native points to this file -> ReanimatedSwipeable.tsx

// Velocity is in px, while progress is in %
        springConfig.velocity = 0;

in the const animateRow = useCallback( function. My workaround was reverting back to the deprecated Swipeable

Snack or a link to a repository

don't have a link

Gesture Handler version

^2.18.1

React Native version

0.75.2

Platforms

iOS

JavaScript runtime

Hermes

Workflow

React Native (without Expo)

Architecture

None

Build type

Debug mode

Device

iOS simulator

Device model

No response

Acknowledgements

Yes

github-actions[bot] commented 2 months ago

Hey! 👋

The issue doesn't seem to contain a minimal reproduction.

Could you provide a snack or a link to a GitHub repository under your username that reproduces the problem?

j-piasecki commented 2 months ago

This problem should be fixed by https://github.com/software-mansion/react-native-gesture-handler/pull/3045. Please update to React Native Gesture Handler 2.19.0.

ucheNkadiCode commented 2 months ago

As always, thank you so much for the work y'all do ❤️