Skip to content

Animations

In PAM Native, PHP describes motion once and the platform runs it. Every animation is encoded into the render tree, handed to the native renderer and played on the UI thread (Android Choreographer, iOS CADisplayLink and Core Animation). No frame ever waits for PHP, so animations stay smooth while PHP is busy, and an idle PHP worker costs no CPU.

Pick the smallest tool that does the job:

Tool Use it for
CSS transition A property changes and should ease to its new value.
->animate() The same, from typed PHP.
Animation programs Timed or spring sequences, like a like-button bounce. Replay on demand.
@keyframes and Animated A fixed timeline such as an entrance.
AnimationPreset and TapEffect Ready-made motions: heart burst, pulse, shimmer, fade-in-up.
Drag Motion that follows the finger; see Gestures.

Animatable properties are compositor-only: opacity, translation, scale, rotation and (for programs, transitions and drags) borderRadius. They never trigger a layout pass.

Declare a transition and change the property from state. The new value animates natively:

src/Components/FavoriteButton.pam.php
<?php
declare(strict_types=1);
namespace App\Components;
use Pam\Native\Attributes\State;
use Pam\Native\Component;
final class FavoriteButton extends Component
{
#[State]
public bool $active = false;
public function toggle(): void
{
$this->active = !$this->active;
}
}
?>
<template>
<Pressable
class="favorite"
:class="['favorite-active' => $active]"
accessibilityRole="togglebutton"
accessibilityLabel="Favorite"
:accessibilitySelected="$active"
@press="toggle"
>
<Text class="star">★</Text>
</Pressable>
</template>
<style scoped>
.favorite {
opacity: 0.6;
transform: scale(1);
transition: transform 280ms spring(1 260 18), opacity 120ms ease-out;
}
.favorite-active {
opacity: 1;
transform: scale(1.15);
}
.star { font-size: 28px; }
</style>

Supported transition properties are all, opacity, transform, translate, scale, rotate and border-radius. Timing functions: linear, ease, ease-in, ease-out, ease-in-out, cubic-bezier(), steps() and spring(mass stiffness damping) (defaults 1 100 10). Per-property durations and delays work like CSS, and the longhands (transition-property, transition-duration, transition-timing-function, transition-delay) override the shorthand.

From typed PHP, use the same syntax with ->transition(), or the simpler ->animate() for any property change on that element:

use Pam\Native\AnimationEasing;
$badge = View::make($count)
->transition('opacity 200ms ease-in')
->style(new Style(opacity: $this->visible ? 1.0 : 0.0));
$panel = Column::make(...$rows)
->animate(durationMs: 180, easing: AnimationEasing::EaseInOut);

Animation builds Reanimated-style programs: timing, spring, sequences, parallel tracks, delays and repeats.

use Pam\Native\Animation\Animation;
use Pam\Native\Animation\Easing;
// A like-button squash and overshoot, replayed whenever $likes changes.
$bounce = Animation::timing(['scale' => 0.82], 70, Easing::EaseOutQuad)
->then(Animation::spring(['scale' => 1], stiffness: 420, damping: 9, mass: 0.6))
->key($this->likes);
<View :animation="$bounce">
<Icon name="heart" size="28" />
</View>
Builder Effect
Animation::timing(['opacity' => 1], 200, Easing::EaseOut, delay: 40) Animate to values over a duration
Animation::spring(['scale' => 1.1], stiffness: 300, damping: 7, mass: 0.5) Physical spring (defaults 100 / 10 / 1)
Animation::set(['scale' => 0.5]) Jump instantly
Animation::wait(360) Pause between phases
Animation::sequence($a, $b, $c) Chain steps per property
$a->with($b) Run in parallel (different properties, different durations)
$a->then($b) Start $b after every track of $a settled
->delay($ms), ->repeat(-1) Delay the first phase; repeat (-1 forever)
->key($value) Replay identity

Values are dp for translations (or "50%" of the element’s own size), degrees for rotate and factors for scale and opacity. Property names are opacity, translateX, translateY, scale, scaleX, scaleY, rotate and borderRadius.

Easing covers Linear, Ease, EaseIn, EaseOut, EaseInOut, the quad and cubic variants (EaseOutQuad, EaseInOutCubic…) and EaseOutBack.

A program plays when it first mounts and replays only when its identity changes: the encoded program plus its key(). Re-rendering an unchanged animation never restarts it. To replay the same program, change the key (a counter or an id), or bind replayKey (->replayKey($n)) on the element. on:animationComplete fires once when a finite program ends.

Declare @keyframes in a Language 2 stylesheet and attach them with Animated. Keyframes may only animate compositor properties (opacity, translate, scale, rotate):

src/Components/Toast.pam.php
<?php
declare(strict_types=1);
namespace App\Components;
use Pam\Native\Attributes\Prop;
use Pam\Native\Component;
final class Toast extends Component
{
public function __construct(
#[Prop(required: true)]
public readonly string $message,
) {
}
}
?>
<template language="2">
<Animated animation="enter" durationMs="240" easing="easeOut">
<View class="toast" accessibilityLiveRegion="polite">
<Text>{{ $message }}</Text>
</View>
</Animated>
</template>
<style>
@keyframes enter {
from { opacity: 0; transform: translateY(12px); }
to { opacity: 1; transform: translateY(0px); }
}
</style>

Animated accepts durationMs, easing (linear, easeIn, easeOut, easeInOut, spring), delayMs, iterations, fillMode (none, forwards, backwards, both), playState (running, paused, stopped) and autoReverse. Animated wraps exactly one child.

The typed equivalent uses AnimationKeyframe values (2 to 64, ordered by offset):

use Pam\Native\AnimationEasing;
use Pam\Native\AnimationFillMode;
use Pam\Native\AnimationKeyframe;
use Pam\Native\UI\Animated;
$entrance = Animated::make(
$card,
[
new AnimationKeyframe(0, opacity: 0, translationY: 18, scaleX: 0.96, scaleY: 0.96),
new AnimationKeyframe(1, opacity: 1, translationY: 0, scaleX: 1, scaleY: 1),
],
durationMs: 260,
easing: AnimationEasing::EaseOut,
)
->fillMode(AnimationFillMode::Forwards)
->onComplete(fn () => $this->entered = true);

A keyframe’s easing argument (for example 'ease-out-quad') sets the curve from that keyframe to the next, so one timeline can mix curves.

Pam\Native\Animation\AnimationPreset ships common motions as programs:

Preset Use
heartBurst() Double-tap heart: spring pop, hold, float up and fade
likeBounce() Like-button squash and overshoot
backToTop(bool $visible) Floating back-to-top button entrance and exit
shimmer(int $durationMs = 1200) Skeleton highlight sweep
pulse(float $minimum = 0.35, int $durationMs = 700) Opacity pulse for a recording indicator
marquee(float $distance, float $speed = 30.0) Ticker for an overflowing track
fadeInUp(int $durationMs = 180, float $offset = 14.0) List row entrance
<View :animation="$fadeIn" class="row">…</View>
use Pam\Native\Animation\AnimationPreset;
public function render(): Element
{
$this->fadeIn = AnimationPreset::fadeInUp();
// ...
}

For simple entrances there are also element presets: ->motion(MotionPreset::FadeIn) with FadeIn, ScaleIn, SlideUp, SlideDown, Success and Shake.

A TapEffect plays an animation centered on the tap, natively, before PHP is notified. The classic example is the double-tap heart on a video:

use Pam\Native\Animation\AnimationPreset;
use Pam\Native\Animation\TapEffect;
use Pam\Native\PressEvent;
public TapEffect $heart;
public function __construct()
{
$this->heart = TapEffect::make('heart', AnimationPreset::heartBurst(), tilt: 15);
}
public function like(PressEvent $event): void
{
$this->liked = true;
}
<Pressable @press="togglePause" on:doubleTap="like" :tapEffect="$heart">
<Video :source="$clip->url" />
<View nativeRef="heart" style="position:absolute;width:96px;height:96px" importantForAccessibility="no-hide-descendants">
<Icon name="heart" size="72" color="#FFFFFF" />
</View>
</Pressable>

The nativeRef anchor is moved so its center sits on the tap and rotated by a random angle up to tilt; the animation runs on its first child. TapEffect::pop($ref) pops the anchor in place on a single tap instead.

Modal animation types are none, slide, fade and slide-fade (ModalAnimationType::SlideFade), which fades the backdrop while the content slides up, and reverses both on dismiss. A presented Modal or BottomSheet removed with p-if plays the same exit as visible = false. See Overlays and System UI.

When the user enables reduced motion (Android animator-duration scale, iOS Reduce Motion), programs, transitions and keyframes jump to their final values, navigation and sheets commit immediately, and finite animations still fire their completion event once. You do not need to check it yourself; for extra decorative CSS, use @media (prefers-reduced-motion: reduce).

Animations run natively, but they are not free: each running animation keeps the display pipeline busy and costs battery.

  • Animate only compositor properties. Animating width, height or padding would relayout the tree; PAM does not allow it in programs and keyframes.
  • Stop indefinite motion when it is not visible. AnimationPreset::shimmer() and <Shimmer> already pause when detached, hidden or off screen. For your own repeat(-1) programs, remove the animation (or set playState="paused" on Animated) when the route is covered (on:routeCovered) or the app goes to the background:
use Pam\Native\Attributes\State;
#[State]
public bool $animating = true;
// Component lifecycle hooks: called when the app goes to the background and back.
public function paused(): void
{
$this->animating = false;
}
public function resumed(): void
{
$this->animating = true;
}
<!-- $pulse = AnimationPreset::pulse(); the dot only animates while the app is in the foreground -->
<View p-if="$animating" :animation="$pulse" class="recording-dot" importantForAccessibility="no" />
<View p-else class="recording-dot" importantForAccessibility="no" />
  • Prefer one animated container over many animated children in long lists, and never animate inside every row of a 1,000-item list at once.
  • For progress that must reflect real time (countdowns, recording bars), use the native time primitives (clockStartedAt, progressStartedAt) instead of a PHP timer that re-renders every second.