@@ -9,17 +9,20 @@ import type { LayoutChangeEvent } from 'react-native';
99import { I18nManager , StyleSheet , View } from 'react-native' ;
1010import Animated , {
1111 interpolate ,
12+ isSharedValue ,
1213 measure ,
1314 ReduceMotion ,
14- runOnJS ,
15- runOnUI ,
1615 useAnimatedRef ,
1716 useAnimatedStyle ,
1817 useSharedValue ,
1918 withSpring ,
2019} from 'react-native-reanimated' ;
20+ import {
21+ isWorkletRuntime ,
22+ scheduleOnRN ,
23+ scheduleOnUI ,
24+ } from 'react-native-worklets' ;
2125
22- import { Reanimated } from '../../handlers/gestures/reanimatedWrapper' ;
2326import { tagMessage } from '../../utils' ;
2427import { GestureDetector } from '../../v3/detectors' ;
2528import type { PanGestureActiveEvent } from '../../v3/hooks/gestures' ;
@@ -89,22 +92,22 @@ const Swipeable = (props: SwipeableProps) => {
8992
9093 // eslint-disable-next-line react-hooks/rules-of-hooks
9194 useEffect ( ( ) => {
92- if ( ! Reanimated ?. isSharedValue < number > ( dragOffsetFromRight ) ) {
95+ if ( ! isSharedValue < number > ( dragOffsetFromRight ) ) {
9396 return ;
9497 }
9598
9699 const listenerId = Math . random ( ) + SHARED_VALUE_OFFSET ;
97100
98- Reanimated ?. runOnUI ( ( ) => {
101+ scheduleOnUI ( ( ) => {
99102 'worklet' ;
100103 dragOffsetFromRight . addListener ( listenerId , checkValue ) ;
101- } ) ( ) ;
104+ } ) ;
102105
103106 return ( ) => {
104- Reanimated ?. runOnUI ( ( ) => {
107+ scheduleOnUI ( ( ) => {
105108 'worklet' ;
106109 dragOffsetFromRight . removeListener ( listenerId ) ;
107- } ) ( ) ;
110+ } ) ;
108111 } ;
109112 } , [ dragOffsetFromRight , checkValue ] ) ;
110113 }
@@ -190,13 +193,15 @@ const Swipeable = (props: SwipeableProps) => {
190193 'worklet' ;
191194
192195 if ( onSwipeableWillOpen && toValue !== 0 ) {
193- runOnJS ( onSwipeableWillOpen ) (
196+ scheduleOnRN (
197+ onSwipeableWillOpen ,
194198 toValue > 0 ? SwipeDirection . RIGHT : SwipeDirection . LEFT
195199 ) ;
196200 }
197201
198202 if ( onSwipeableWillClose && toValue === 0 ) {
199- runOnJS ( onSwipeableWillClose ) (
203+ scheduleOnRN (
204+ onSwipeableWillClose ,
200205 fromValue > 0 ? SwipeDirection . LEFT : SwipeDirection . RIGHT
201206 ) ;
202207 }
@@ -209,13 +214,15 @@ const Swipeable = (props: SwipeableProps) => {
209214 'worklet' ;
210215
211216 if ( onSwipeableOpen && toValue !== 0 ) {
212- runOnJS ( onSwipeableOpen ) (
217+ scheduleOnRN (
218+ onSwipeableOpen ,
213219 toValue > 0 ? SwipeDirection . RIGHT : SwipeDirection . LEFT
214220 ) ;
215221 }
216222
217223 if ( onSwipeableClose && toValue === 0 ) {
218- runOnJS ( onSwipeableClose ) (
224+ scheduleOnRN (
225+ onSwipeableClose ,
219226 fromValue > 0 ? SwipeDirection . LEFT : SwipeDirection . RIGHT
220227 ) ;
221228 }
@@ -328,37 +335,37 @@ const Swipeable = (props: SwipeableProps) => {
328335 ( ) => ( {
329336 close ( ) {
330337 'worklet' ;
331- if ( _WORKLET ) {
338+ if ( isWorkletRuntime ( ) ) {
332339 animateRow ( 0 ) ;
333340 return ;
334341 }
335- runOnUI ( ( ) => {
342+ scheduleOnUI ( ( ) => {
336343 animateRow ( 0 ) ;
337- } ) ( ) ;
344+ } ) ;
338345 } ,
339346 openLeft ( ) {
340347 'worklet' ;
341- if ( _WORKLET ) {
348+ if ( isWorkletRuntime ( ) ) {
342349 updateElementWidths ( ) ;
343350 animateRow ( leftWidth . value ) ;
344351 return ;
345352 }
346- runOnUI ( ( ) => {
353+ scheduleOnUI ( ( ) => {
347354 updateElementWidths ( ) ;
348355 animateRow ( leftWidth . value ) ;
349- } ) ( ) ;
356+ } ) ;
350357 } ,
351358 openRight ( ) {
352359 'worklet' ;
353- if ( _WORKLET ) {
360+ if ( isWorkletRuntime ( ) ) {
354361 updateElementWidths ( ) ;
355362 animateRow ( - rightWidth . value ) ;
356363 return ;
357364 }
358- runOnUI ( ( ) => {
365+ scheduleOnUI ( ( ) => {
359366 updateElementWidths ( ) ;
360367 animateRow ( - rightWidth . value ) ;
361- } ) ( ) ;
368+ } ) ;
362369 } ,
363370 reset ( ) {
364371 'worklet' ;
@@ -544,9 +551,9 @@ const Swipeable = (props: SwipeableProps) => {
544551 if ( ! dragStarted . value ) {
545552 dragStarted . value = true ;
546553 if ( rowState . value === 0 && onSwipeableOpenStartDrag ) {
547- runOnJS ( onSwipeableOpenStartDrag ) ( direction ) ;
554+ scheduleOnRN ( onSwipeableOpenStartDrag , direction ) ;
548555 } else if ( onSwipeableCloseStartDrag ) {
549- runOnJS ( onSwipeableCloseStartDrag ) ( direction ) ;
556+ scheduleOnRN ( onSwipeableCloseStartDrag , direction ) ;
550557 }
551558 }
552559
0 commit comments