React Nitro

Animations

Animate native view properties with timing curves and springs.

Call animate(duration, curve, changes) on the native view and call startAnimation() on the returned animator. Choose AnimationCurve.Linear for a constant rate or EaseIn, EaseOut, or EaseInOut to change how the motion accelerates.

Animate a press

The gestureRecognizers factory receives the native view. Call animate on it to describe a change to an animatable property. Start the returned animator to let the platform interpolate between values. This card shrinks while pressed and returns to its original scale on release or cancellation.

import {
  AnimationCurve, GestureRecognizerState, LongPressGestureRecognizer,
  Text, View, type ViewSpec,
} from 'react-nitro-renderer'

function attachPress(view: ViewSpec) {
  const press = new LongPressGestureRecognizer()
  press.minimumPressDuration = 0
  press.onLongPress = ({ state }) => {
    let scale: number
    if (state === GestureRecognizerState.Began) {
      scale = 0.96
    } else if (state === GestureRecognizerState.Ended || state === GestureRecognizerState.Cancelled) {
      scale = 1
    } else {
      return
    }

    const animator = view.animate(0.15, AnimationCurve.Linear, () => {
      view.setScale(scale, scale, scale)
    })
    animator.startAnimation()
  }
  return [press]
}

export function PressableCard() {
  return (
    <View layout={{ padding: 16 }} style={{ background: 0xe4efdcff }} gestureRecognizers={attachPress}>
      <Text>Hold to preview</Text>
    </View>
  )
}

The duration is in seconds. Animating scale changes the drawn size while layout keeps the original space reserved. Keep the animator if you need to call pauseAnimation() or stopAnimation().

Use a spring

When a card should settle back into position, animate its scale with animateSpring(duration, dampingRatio, changes). Start the resulting animator just as you would a timed animation.

function restoreSize(view: ViewSpec) {
  const spring = view.animateSpring(0.35, 0.8, () => {
    view.setScale(1, 1, 1)
  })
  spring.startAnimation()
}

To move a view between two navigation screens, give the source and destination a shared ID. Shared element transitions

On this page