mgcrea / react-native-dnd

Modern and easy-to-use drag&drop library for react-native.
https://mgcrea.github.io/react-native-dnd/
MIT License
135 stars 12 forks source link

Getting error on DndProvider methods #10

Closed Rc85 closed 9 months ago

Rc85 commented 9 months ago

If I invoke the on methods, I get ReanimatedError: [Reanimated] Tried to synchronously call a non-worklet function on the UI thread.

<DndProvider onDragEnd={(e) => console.log('drag', e)} onBegin={(e) => console.log('begin', e)}>

</DndProvider>

If I don't invoke those method, no error.

mgcrea commented 9 months ago

These method must be flagged as worklet with the "worklet" tag since they run on the UI thread by default, you can still use runOnJS there if you need to run on the JS thread (eg. setState, etc.).


const onDragEnd = (e) => {
  "worklet";
  console.log('drag', e);
}

return <DndProvider onDragEnd={onDragEnd}>

</DndProvider>