SwipeUI

Icon morph

Twenty-five original icon morphs, three level sequences and shared-value scrubbing, with an API for your own geometry.

npx @swipeui/cli add icon-morph
Variant
Preset
Material
Scheme
Feel
Real free component with a browser animation bridge. Native motion, haptics and materials need a device.

When to use it

  • Keep a toolbar icon in place as its meaning changes.
  • Show Wi-Fi, speaker or battery levels with a numeric frame index.
  • Connect an icon to a finger or scroll through a normalized shared value.
  • Author a custom shape sequence from matching lines, arcs and dots.

When not to use it

  • A static symbol needs no animation engine.
  • Use Button for touch handling, haptics and accessible button states.
  • Large illustrations or arbitrary SVG path strings need a different renderer.

Installation

Run this from your app's root. If SwipeUI isn't set up yet, run npx @swipeui/cli init first; it sets up Uniwind, the theme tokens and the cn helper.

npx @swipeui/cli add icon-morph
  • Adds components/swipeui/ui/icon-morph.tsx, components/swipeui/ui/icon-morph-geometry.ts, components/swipeui/ui/icon-morph-library.ts, components/swipeui/ui/use-icon-morph.ts and 1 shared helper.
  • Installs react-native-reanimated, react-native-svg, uniwind, react-native-worklets. In Expo apps it uses npx expo install so versions match your SDK.

Usage

components/menu-toggle.tsx
import { IconMorph } from '@/components/swipeui/ui/icon-morph';

<IconMorph name="menu-close" state={open} />;

The parent owns touch handling, haptics and the accessible state. Place an icon inside Button, label the button, and leave the icon decorative. pair and active from 1.x still work; name and state take precedence when both are supplied.

Examples

The live board has four variants shared with the showcase app: library (25 pairs), sequences (Wi-Fi, volume and battery), scrub (a thumb-driven shared value) and in-buttons (playback, like and navigation). The library uses three equal columns with wrapping captions and a clear gap between each icon and its label. Tap any library tile to reverse its morph. The scrub board also has endpoint buttons and adjustable accessibility actions.

The pairs are menu-close, menu-back, plus-close, plus-minus, plus-check, chevron-down-up, chevron-right-down, arrow-down-check, copy-check, play-pause, play-stop, volume-mute, mic-off, eye-off, lock-unlock, bell-off, heart-filled, star-filled, bookmark-filled, sun-moon, search-close, list-grid, sort-up-down, expand-collapse and panel-open-close.

Levels and scrubbing

wifi-levels has indices 0–3, volume-levels 0–2, and battery-levels 0–4. Boolean true selects the final frame; numbers select a clamped frame index, including fractional positions. A normalized progress spans the entire sequence and overrides state.

components/sheet-chevron.tsx
import { useSharedValue } from 'react-native-reanimated';
import { IconMorph } from '@/components/swipeui/ui/icon-morph';

function SheetChevron() {
  const progress = useSharedValue(0);
  // Write progress from a UI-thread gesture or scroll handler.
  return <IconMorph name="chevron-right-down" progress={progress} />;
}

Draw your own

Create definitions outside render. Each frame contains the same primitive kinds, in the same order. Lines use [x1, y1, x2, y2], arcs use [cx, cy, radius, startDegrees, endDegrees], and dots use [cx, cy, radius], each prefixed by its kind. Angles turn clockwise from the right. Coordinates use a 24-unit grid. Adjacent line and arc endpoints connect, so closed outlines can also be filled.

components/custom-morph.tsx
import { defineIconMorph, IconMorph } from '@/components/swipeui/ui/icon-morph';

const crossbar = defineIconMorph({
  frames: [[['line', 4, 12, 20, 12]], [['line', 12, 4, 12, 20]]],
  mirrorInRTL: true,
});

<IconMorph name={crossbar} state={false} />;

Development builds throw a clear error for mismatched counts, kinds, arity, non-finite coordinates or negative radii. A disappearing primitive keeps its slot with a zero-length line or zero radius; the engine omits its entire subpath once collapsed. Anchor shrinking strokes on surviving geometry so their rounded tips do not become isolated dots during the transition. fill: true fades the definition's outline into a filled final frame. mirrorInRTL: true opts a custom definition into directional mirroring; both options default to false.

Settings

PropDefaultBehaviour
namemenu-closeBuilt-in name or a definition returned by defineIconMorph.
statefalseBoolean endpoint or numeric frame index; out-of-range values clamp, non-finite values use zero.
progressunsetShared value from 0 to 1, overrides state; skips one-shots while scrubbing.
pairmenu-closeLegacy name alias, used when name is absent.
activefalseLegacy boolean alias, used when state is absent.
size24Width and height in points.
strokeWidth1.75Outline thickness on the 24-unit grid.
colorforeground tokenOutline colour; pass the parent button's icon colour.
fillColorcolorFill and burst colour for heart, star and bookmark.
effectstrueOne-shot heart/star burst, bell ring when enabling alerts, and check draw-on.
motionapp feelLocal feel or role override; none uses endpoint cross-fades.
accessibilityLabelunsetExposes a named image; otherwise decorative.
classNameunsetClasses for the icon frame.
styleunsetNative frame styles.
testIDunsetRoot identifier; parts append their name.
Definition settingDefaultBehaviour
framesrequiredAt least two frames with matching primitive topology.
fillfalseFades a fill into the final outline on the toggle role.
mirrorInRTLfalseMirrors the definition in a right-to-left layout.

API reference

IconMorphProps

PropTypeDefaultDescription
name?union'menu-close'

Built-in name, or a custom definition from defineIconMorph. Takes precedence over pair.

state?number | booleanfalse

Boolean endpoint or numeric frame index (fractional values allowed). Takes precedence over active.

progress?SharedValue<number>undefined

Normalized 0–1 shared value spanning the entire sequence; overrides state. No one-shots while scrubbing.

pair?union'menu-close'

Legacy name alias.

active?booleanfalse

Legacy state alias.

size?number24

Icon width and height in points; the parent owns its touch target.

strokeWidth?number1.75

Stroke width in the 24-unit grid.

color?stringforeground token

Stroke colour.

fillColor?stringcolor

Colour of the optional fill layer.

effects?booleantrue

Heart/star burst, bell ring and check draw-on, once per state change.

motion?MotionOverridethe app's feel (`smooth` without a provider)

Shared motion feel or a local override.

accessibilityLabel?stringundefined (decorative)

Spoken name; label the parent button instead when interactive.

className?stringundefined

Classes on the frame.

style?StyleProp<ViewStyle>undefined

Native frame style escape hatch.

testID?stringundefined

Root identifier; parts append -path, -fill, -outgoing and -burst.

Motion and accessibility

Native geometry is built in a worklet and sent to an SVG Path through useAnimatedProps; React does no per-frame state updates. Shape changes use the morph role; fill opacity uses toggle. Effects run once on a meaningful state change and never on initial mount or during scrubbing. Directional back, chevron, arrow, sort and panel definitions mirror in RTL; media and symmetric shapes do not.

Reduce Motion replaces geometry with the nearest complete frame and uses a short opacity cross-fade; bursts, rings and draw-on are skipped. The icon adds no touch area: give its parent at least 44 points. Native screen-reader behaviour, device timing, performance and recordings remain pending founder review.

Behavior and gestures

  • The icon has no touch handling; its labelled parent owns interaction.
  • name selects a built-in or custom definition; state selects a frame.
  • progress overrides state and spans every frame from 0 to 1; scrubbing skips one-shot effects.
  • pair and active remain supported as legacy aliases.

Accessibility

  • Decorative unless accessibilityLabel is provided; a labelled icon uses the image role.
  • Label the containing button and expose its selected or expanded state.
  • Reduce Motion replaces geometric travel with a short cross-fade and suppresses one-shot effects.
  • The scrub specimen offers buttons and adjustable accessibility actions. Native screen reader checks remain pending.

Motion

  • Uses the morph and toggle motion roles, so it follows your app's feel. Pass motion to tune this one instance.
  • A worklet interpolates matching primitives into SVG Path d via useAnimatedProps.
  • The morph role drives state transitions and one-shot bursts, rings and check drawing; toggle drives fill opacity.
  • Reduced motion quantizes scrubbed positions to frames and cross-fades endpoints; effects are skipped.

Performance

  • Native geometry and effects run on the UI thread; no per-frame React state or path parsing.
  • Definitions use a compact primitive list. Development topology checks catch mismatched frames before animation.

Notes for AI

  • Prefer name and state; legacy pair and active are fallback aliases. Boolean true selects the last frame, numeric state is a clamped frame index.
  • Pass defineIconMorph output as name. Preserve the primitive kinds and counts in every frame; fill fades into the final outline.

Compatibility

Runs onSupported
Expo SDK 57Yes
Expo SDK 58Yes
React Native CLI (with Expo modules)Yes
Expo GoYes
iOSYes
AndroidYes

This table describes API support and static bundle checks. Native runtime, device accessibility and bare Uniwind compatibility remain pending.

Related items