Text morph
Per-character label replacement with intrinsic width transitions and shaped-run fades.
npx @swipeui/cli add text-morphWhen to use it
- Button or status labels that change, like Follow → Following or Send → Sent.
- Small headings that swap words, where a smooth change feels polished.
- Labels whose width changes and shouldn't jump.
When not to use it
- Numbers. Use Slot text or Animated counter.
- Long paragraphs.
- Text that changes constantly; the motion becomes noise.
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 text-morph- Adds
components/swipeui/ui/text-morph.tsxand 4 shared helpers. - Installs react-native-reanimated, react-native-worklets, clsx, tailwind-merge, class-variance-authority. In Expo apps it uses
npx expo installso versions match your SDK.
Usage
import { TextMorph } from '@/components/swipeui/ui/text-morph';
<TextMorph text={saved ? 'Saved' : 'Save'} />;Examples
button morphs Save changes → Saving → Saved inside its primary action (wrap={false}). Tap Saved to reset. status shows a sync row with an outside Sync now control. The app and website use the same boards and content.
API reference
TextMorphProps
| Prop | Type | Default | Description |
|---|---|---|---|
text | | — | Next complete label; unchanged character slots retain identity. |
motion? | | — | Shared morph feel. |
wrap? | | | Lets characters wrap onto more lines when space runs out. Turn it off inside controls that size to their label, such as buttons, so the label keeps one line. |
className? | | — | Root classes. |
textClassName? | | | Text role classes. |
style? | | — | Native layout escape hatch. |
testID? | | — | Root ID. |
Native view/input props not listed here pass through where the exported TypeScript type allows them.
Composition and behavior
- text is the current label.
- textClassName sets the style (body by default).
Behavior and gestures
- Static; when text changes, characters that stay keep their place and new ones fade in.
- The label's width eases to fit the new text.
Accessibility
- Screen readers hear the complete new label.
- Emoji and joined scripts stay intact.
- Reduce Motion swaps text instantly.
Motion
- Uses the
morphmotion role, so it follows your app's feel. Passmotionto tune this one instance. - Uses the morph role for characters and width.
- Reduce Motion turns it off.
Performance
- Only changed characters mount or unmount.
Notes for AI
- Pass the next label as text; keep labels short.
Compatibility
| Runs on | Supported |
|---|---|
| Expo SDK 57 | Yes |
| Expo SDK 58 | Yes |
| React Native CLI (with Expo modules) | Yes |
| Expo Go | Yes |
| iOS | Yes |
| Android | Yes |
This table describes API support and static bundle checks. Native runtime, device accessibility and bare Uniwind compatibility remain pending.