feat: Tweak shared element animation to make it much smoother (#6336)

This commit is contained in:
Marc Rousavy
2024-11-14 19:37:41 +00:00
committed by GitHub
parent 7d34f6bb5c
commit 05312cce33
+15 -4
View File
@@ -32,6 +32,7 @@ import Animated, {
useSharedValue, useSharedValue,
withDecay, withDecay,
withSpring, withSpring,
WithSpringConfig,
} from 'react-native-reanimated' } from 'react-native-reanimated'
import { import {
Edge, Edge,
@@ -62,8 +63,18 @@ const EDGES =
? (['top', 'bottom', 'left', 'right'] satisfies Edge[]) ? (['top', 'bottom', 'left', 'right'] satisfies Edge[])
: (['left', 'right'] satisfies Edge[]) // iOS, so no top/bottom safe area : (['left', 'right'] satisfies Edge[]) // iOS, so no top/bottom safe area
const SLOW_SPRING = {stiffness: isIOS ? 180 : 250} const SLOW_SPRING: WithSpringConfig = {
const FAST_SPRING = {stiffness: 700} mass: isIOS ? 1.5 : 1,
damping: 300,
stiffness: 800,
restDisplacementThreshold: 0.01,
}
const FAST_SPRING: WithSpringConfig = {
mass: isIOS ? 1.5 : 1,
damping: 150,
stiffness: 900,
restDisplacementThreshold: 0.01,
}
export default function ImageViewRoot({ export default function ImageViewRoot({
lightbox: nextLightbox, lightbox: nextLightbox,
@@ -706,7 +717,7 @@ function interpolateTransform(
} }
} }
function withClampedSpring(value: any, {stiffness}: {stiffness: number}) { function withClampedSpring(value: any, config: WithSpringConfig) {
'worklet' 'worklet'
return withSpring(value, {overshootClamping: true, stiffness}) return withSpring(value, {...config, overshootClamping: true})
} }