Skip to content

Commit

Permalink
feat: Tweak shared element animation to make it much smoother (#6336)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrousavy authored Nov 14, 2024
1 parent 7d34f6b commit 05312cc
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/view/com/lightbox/ImageViewing/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import Animated, {
useSharedValue,
withDecay,
withSpring,
WithSpringConfig,
} from 'react-native-reanimated'
import {
Edge,
Expand Down Expand Up @@ -62,8 +63,18 @@ const EDGES =
? (['top', 'bottom', 'left', 'right'] satisfies Edge[])
: (['left', 'right'] satisfies Edge[]) // iOS, so no top/bottom safe area

const SLOW_SPRING = {stiffness: isIOS ? 180 : 250}
const FAST_SPRING = {stiffness: 700}
const SLOW_SPRING: WithSpringConfig = {
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({
lightbox: nextLightbox,
Expand Down Expand Up @@ -706,7 +717,7 @@ function interpolateTransform(
}
}

function withClampedSpring(value: any, {stiffness}: {stiffness: number}) {
function withClampedSpring(value: any, config: WithSpringConfig) {
'worklet'
return withSpring(value, {overshootClamping: true, stiffness})
return withSpring(value, {...config, overshootClamping: true})
}

0 comments on commit 05312cc

Please sign in to comment.