Animations & Worklets

@solidnative-dev/animation compiles declarative animation graphs into bounded native worklets that execute directly on the platform UI thread (CADisplayLink on iOS, Choreographer on Android)—never crossing the JS bridge per frame.

Define and attach a UI-thread animation#

tsx
/** @jsxImportSource @solidnative-dev/core */
import { createSignal } from "solid-js";
import { Button, View } from "@solidnative-dev/core";
import { createUIWorkletGraph } from "@solidnative-dev/animation";
import { createNativeViewAnimation } from "@solidnative-dev/animation/native";

const cardGraph = createUIWorkletGraph(
  { progress: 0 },
  ({ progress }, { interpolate }) => ({
    translateY: interpolate(progress, [0, 1], [0, -18]),
    scaleX: interpolate(progress, [0, 1], [1, 1.05]),
    scaleY: interpolate(progress, [0, 1], [1, 1.05]),
    opacity: interpolate(progress, [0, 1], [0.85, 1]),
  }),
);

export function AnimatedCard() {
  const [expanded, setExpanded] = createSignal(false);
  const anim = createNativeViewAnimation(cardGraph);

  const toggle = async () => {
    if (!(await anim.ready)) return;
    const next = !expanded();
    anim.spring(
      { progress: next ? 1 : 0 },
      {
        mass: 1,
        stiffness: 220,
        damping: 22,
        initialVelocity: 0,
        restSpeedThreshold: 0.01,
        restDisplacementThreshold: 0.005,
        maximumDurationMilliseconds: 3_000,
      },
    );
    setExpanded(next);
  };

  return (
    <View ref={anim.ref}>
      <Button title="Toggle spring" onPress={toggle} />
    </View>
  );
}

Built-in motion primitives#

Every NativeViewAnimation handle supports:

MethodBehavior
anim.update(inputs)Immediate UI-thread sample without waiting for a React-style render
anim.animate(inputs, timing)Eased timing (linear, ease-in, ease-out, ease-in-out)
anim.animateKeyframes(frames)Multi-step timed sequences on the native thread
anim.spring(inputs, spring)Physics spring with configurable mass, stiffness, damping, and velocity
anim.decay(velocities, decay)Inertial deceleration for flick/fling gestures
anim.attachPanGesture(config)Native pan gesture driving inputs directly on the UI thread with velocity handoff to decay or spring

Hardware proof (iPhone 17 Pro, 120 Hz)#

Verified in Release mode on physical iPhone 17 Pro (iOS 27.2.1, React Native 0.88.1 Fabric backend):

  • 601 continuous frames (600 / 600 locked 120 Hz CADisplayLink intervals)
  • 0 dropped frames · p50 / p95 / p99 = 8.335 ms · max 8.367 ms