Screen core
The formatters, seeded mock helpers and artwork every SwipeUI kit shares.
Formatters, seeded mock helpers and original artwork shared by every SwipeUI kit.
Free (MIT)Version 1.0.0Released 24 Nov 2026iOS and Android
When to use it
- Formatting counts, durations, relative times, money and percentages the way every SwipeUI kit does.
- Writing a mock adapter that returns the same data on every run, with cancellable latency.
- Covers, banners and placeholders when there's no photo, in the active preset's colours.
When not to use it
- Date pickers and calendars. Use Date utils and the selection components.
- Person avatars. Use Avatar, which draws initials.
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 screen-core- Adds
components/swipeui/lib/screen-core.ts,components/swipeui/lib/screen-artwork.tsxand 1 shared helper. - Installs react-native-svg, uniwind, clsx, tailwind-merge. In Expo apps it uses
npx expo installso versions match your SDK.
Every kit installs this library through its own core, so you rarely add it yourself.
Formatters
import {
formatCompactNumber,
formatRelativeTime,
} from '@/components/swipeui/lib/screen-core';
formatCompactNumber(12_345); // "12.3K"
formatRelativeTime(message.sentAt, { locale }); // "Now", "5m", "3h", "Yesterday", "4d", "2 Nov"formatCompactNumberrounds down, so a count never reads higher than it is.formatDurationgives0:05,3:05or1:02:03.formatClockTime,formatCurrencyandformatPercent(withsignedfor gains) useIntland your locale.- Every built-in word comes from a
messagesobject, so you can translate or lengthen it:
formatRelativeTime(date, { messages: { minutes: (n) => `${n} min ago` } });Mock helpers
import { createSeededRandom, wait } from '@/components/swipeui/lib/screen-core';
const random = createSeededRandom('inbox');
export async function loadConversations(signal?: AbortSignal) {
await wait(300, signal); // rejects with an AbortError when the screen cancels
return conversations.map((conversation) => ({ ...conversation, unread: random() > 0.6 }));
}createSeededRandom(seed)repeats the same sequence for the same seed, so demos and tests stay stable.wait(ms, signal)andisAbortError(error)make latency cancellable.createIdFactory('msg')numbers the items a mock creates.
Artwork
import { ScreenArtwork } from '@/components/swipeui/lib/screen-artwork';
<ScreenArtwork seed={album.id} className="size-24 rounded-card" accessibilityLabel={album.title} />;ScreenArtwork draws original abstract art from a seed in the active preset's chart colours, so it follows every theme. It is decorative unless you give it an accessibilityLabel. Kits never ship photos: pass your own images where you have them.
Behavior and gestures
- None; the helpers are pure functions and the artwork is static.
Accessibility
- Artwork is decorative and hidden unless you give it an accessibilityLabel, which makes it an image.
- Formatters return plain text, so screen readers read the same words people see.
Motion
- Static on its own; any movement comes from the parent that animates it.
- No motion.
Performance
- Artwork geometry is memoised per seed and pattern; it draws a few SVG shapes.
Notes for AI
- Installed with every kit through its core; don't add it on its own unless you build a kit-style screen.
- Pass the buyer's locale to every formatter, and replace the messages to translate.
- Mock adapters should take an AbortSignal and use wait(ms, signal) for latency.
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.