Skip to content

fix(reanimated warning): use runOnJS for safe access to shared values #292

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions src/core/hooks/useAnimationAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
withSpring,
withTiming,
AnimateStyle,
runOnJS,
} from 'react-native-reanimated'
import { useDrag } from './useDrag'
import type { NotificationState } from './useNotificationsStates'
Expand Down Expand Up @@ -119,14 +120,17 @@ export const useAnimationAPI = ({

// Used to revoke transition (progress) value after canceling it with e.g. LongPressGestureHandler
const revokeTransitionAnimation = useCallback(() => {
switch (currentTransitionType.value) {
case 'out':
return dismiss()
case 'in':
case 'idle_active':
return resetTimer(dismiss, duration)
}
}, [currentTransitionType.value, dismiss, resetTimer, duration])
// Use runOnJS to safely access shared values and avoid Reanimated warning
runOnJS((transitionType: 'in' | 'out' | 'idle_active') => {
switch (transitionType) {
case 'out':
return dismiss()
case 'in':
case 'idle_active':
return resetTimer(dismiss, duration)
}
})(currentTransitionType.value)
}, [dismiss, resetTimer, duration, currentTransitionType])

const handleDragStateChange = dragStateHandler(dismiss, resetDrag)

Expand Down