dynamic island.
The iOS Dynamic Island, morphing between seven live activities on a single spring that survives being interrupted.
live component, try it
what to expect.
how it works.
The obvious build gives width and height a spring each, and it looks perfect, which is the trap. A spring is linear, so two axes released together from rest hold the same normalised progress however far apart their targets are. It comes apart on interruption, and for this component interruption is not an edge case: a call arrives while the timer is still expanding. Each axis carries its own velocity into the new leg, those velocities are not in the ratio of the new distances, and the island travels through shapes that belong to no state. One scalar spring fixes it by construction, and an interruption moves the line rather than starting a second race. The content is a handover rather than a crossfade, because two labels at half opacity stacked on each other is not a transition, it is mush. The layout follows the hardware too: a compact state keeps the camera's width empty in the middle and puts its content either side, the clock and battery slide outward as the island widens so it never sits on them, and the camera fades out while the island is busy and comes back only once it has settled.
take it with you.
Three steps, and the stage above runs in your own project.
Install
Nothing to add. It runs on React alone, 18 or newer.
Copy the files
11 files, kept together in one folder,
dynamic-island/. The styles travel with them."use client"; import { useEffect, useRef, useState, type ReactNode } from "react"; import { ISLAND } from "./geometry"; import { useReducedMotion } from "./motion"; import { beginMorph, boxAt, contentPhase, morphDone, stepMorph, type Box, type MorphState } from "./morph"; import "./dynamic-island.css"; export type IslandState = | "idle" | "ring" | "record" | "battery" | "screen" | "call" | "timer" | "music"; const IDLE: Box = { w: ISLAND.w, h: ISLAND.h, r: ISLAND.h / 2 }; const EXPANDED_W = 344; const compact = (ear: number): Box => ({ ...IDLE, w: IDLE.w + 2 * ear }); export const STATES: Record<IslandState, Box> = { idle: IDLE, ring: compact(58), record: compact(50), battery: compact(76), screen: { w: EXPANDED_W, h: 84, r: 40 }, call: { w: EXPANDED_W, h: 84, r: 40 }, timer: { w: EXPANDED_W, h: 84, r: 40 }, music: { w: EXPANDED_W, h: 168, r: 46 }, }; export type BarMode = "full" | "compact" | "none"; export const BAR: Record<IslandState, BarMode> = { idle: "full", ring: "compact", record: "compact", battery: "compact", screen: "none", call: "none", timer: "none", music: "none", }; const LEG_CEILING_MS = 1500; export default function DynamicIsland({ state, content, onTap, stiffness = 300, damping = 27, handover = 0.55, }: { state: IslandState; // what the island shows in each state content: Record<IslandState, ReactNode>; onTap: () => void; // spring that carries the shape: stiffer is quicker, more damping settles with less wobble stiffness?: number; damping?: number; // 0 to 1: how far into the morph the old content hands over to the new handover?: number; }) { const reduced = useReducedMotion(); const shell = useRef<HTMLButtonElement>(null); const leaving = useRef<HTMLDivElement>(null); const arriving = useRef<HTMLDivElement>(null); const cfg = useRef({ stiffness, damping, handover }); cfg.current = { stiffness, damping, handover }; const [pair, setPair] = useState<{ from: IslandState; to: IslandState }>({ from: state, to: state, }); if (pair.to !== state) setPair({ from: pair.to, to: state }); const morph = useRef<MorphState>(beginMorph(STATES[state], STATES[state])); const frame = useRef(0); const last = useRef(0); useEffect(() => { const el = shell.current; const host = el?.parentElement; if (!el || !host) return; const write = (box: Box, t: number) => { host.style.setProperty("--iw", String(box.w)); host.style.setProperty("--ih", String(box.h)); host.style.setProperty("--ir", String(box.r)); const p = contentPhase(t, cfg.current.handover); for (const [node, fade] of [ [leaving.current, p.leaving], [arriving.current, p.arriving], ] as const) { if (!node) continue; node.style.opacity = String(fade.opacity); node.style.transform = `scale(${fade.scale})`; node.style.filter = fade.blur > 0.01 ? `blur(${fade.blur}px)` : "none"; node.style.visibility = fade.opacity === 0 ? "hidden" : "visible"; } }; const target = STATES[state]; if (reduced) { morph.current = beginMorph(target, target); write(target, 1); return; } let alive = true; const at = boxAt(morph.current); morph.current = beginMorph(at, target, morph.current.t.v, morph.current.to); const finish = () => { morph.current = beginMorph(target, target); write(target, 1); }; write(at, 0); const guard = window.setTimeout(() => { if (!alive) return; alive = false; cancelAnimationFrame(frame.current); finish(); }, LEG_CEILING_MS); last.current = performance.now(); const tick = (now: number) => { if (!alive) return; const dt = now - last.current; last.current = now; const { stiffness: k, damping: c } = cfg.current; morph.current = stepMorph(morph.current, dt, { stiffness: k, damping: c }); write(boxAt(morph.current), morph.current.t.x); if (morphDone(morph.current)) { window.clearTimeout(guard); return finish(); } frame.current = requestAnimationFrame(tick); }; frame.current = requestAnimationFrame(tick); return () => { alive = false; window.clearTimeout(guard); cancelAnimationFrame(frame.current); }; }, [state, reduced]); return ( <button type="button" ref={shell} className="island" onClick={onTap} aria-label={state === "idle" ? "expand the island" : `${state}, collapse the island`} > <div className="island-layer" ref={leaving} aria-hidden="true"> {content[pair.from]} </div> <div className="island-layer" ref={arriving}> {content[pair.to]} </div> </button> ); }Use it
The stage above, exactly as it runs here. The comments mark what to change.
"use client"; import { useState } from "react"; import Bands from "./dynamic-island/Bands"; import PhoneFrame from "./dynamic-island/PhoneFrame"; import { islandContent, type Caller } from "./dynamic-island/content"; import DynamicIsland, { BAR, type IslandState } from "./dynamic-island/DynamicIsland"; const CHIPS: { id: IslandState; label: string }[] = [ { id: "record", label: "memo" }, { id: "ring", label: "ringer" }, { id: "battery", label: "battery" }, { id: "call", label: "call" }, { id: "screen", label: "screen" }, { id: "timer", label: "timer" }, { id: "music", label: "music" }, ]; const CALLER: Caller = { name: "Ashwin", avatar: "https://picsum.photos/seed/caller/144/144" }; export default function DynamicIslandExample({ caller = CALLER }: { caller?: Caller }) { const [state, setState] = useState<IslandState>("idle"); const content = islandContent(caller); return ( <div className="island-lab-frame" data-bar={BAR[state]} data-state={state}> <PhoneFrame width={300} wallpaper={<Bands />} island={ <DynamicIsland state={state} content={content} stiffness={300} damping={27} handover={0.55} onTap={() => setState((s) => (s === "idle" ? CHIPS[0]!.id : "idle"))} /> } > <div className="island-lab"> <div className="island-lab-panel"> <p className="island-lab-hint">tap the island, or send it something</p> <div className="island-lab-chips"> {CHIPS.map((c) => ( <button key={c.id} type="button" data-on={state === c.id} onClick={() => setState((s) => (s === c.id ? "idle" : c.id))} > {c.label} </button> ))} </div> </div> </div> </PhoneFrame> </div> ); }