Card entry with live preview
import * as React from "react";
import { ScrollView, View } from "react-native";
import { SafeAreaView, useSafeAreaInsets } from "react-native-safe-area-context";
import { Button, Glass, Icon, Input, Text } from "@lumioui/ui";
import { useHaptic } from "@lumioui/core";
import { CardBrandMark, HeroGradient, LumioMark, Mount, Press, StickyBottomBar } from "../shared";
export interface AddCardScreenProps {
onScan?: () => void;
onAdd?: (last4: string) => void;
onBack?: () => void;
}
/** Group a card number into 4-4-4-4 for display. */
function groups(raw: string): string {
const digits = raw.replace(/\D/g, "").slice(0, 16);
return digits.replace(/(.{4})/g, "$1 ").trim();
}
/** Add card — live card preview that fills as you type + field group. */
export function AddCardScreen({
onScan,
onAdd,
onBack,
}: AddCardScreenProps) {
const haptics = useHaptic();
const insets = useSafeAreaInsets();
const [number, setNumber] = React.useState("4571 8820 4413 4821");
const [name, setName] = React.useState("Amara Chen");
const [expiry, setExpiry] = React.useState("09/28");
const [cvv, setCvv] = React.useState("123");
const last4 = number.replace(/\D/g, "").slice(-4) || "0000";
const ready = number.replace(/\D/g, "").length >= 15 && cvv.length >= 3;
return (
<SafeAreaView className="flex-1 bg-[#F4F5F9] dark:bg-[#111114]" edges={["top"]}>
<View pointerEvents="box-none" className="absolute inset-x-4 z-10" style={{ top: insets.top + 8 }}>
<View className="flex-row items-center justify-between">
<Glass interactive effect="regular" className="h-11 w-11 items-center justify-center rounded-full">
<Press
haptic="light"
onPress={() => onBack?.()}
accessibilityRole="button"
accessibilityLabel="Go back"
className="h-9 w-9 items-center justify-center"
>
<Icon name="chevron-left" size="md" color="foreground" />
</Press>
</Glass>
<View className="h-11 w-11" />
</View>
<View pointerEvents="none" className="absolute inset-0 items-center justify-center">
<View className="h-11 flex-row items-center justify-center gap-2 rounded-full pl-3.5 pr-5">
<Glass effect="regular" className="absolute inset-0 rounded-full" />
<LumioMark size={18} />
<Text accessibilityRole="header" className="text-sm font-bold tracking-tight">
Add card
</Text>
</View>
</View>
</View>
<ScrollView
showsVerticalScrollIndicator={false}
keyboardShouldPersistTaps="handled"
contentContainerStyle={{ paddingTop: insets.top + 60, paddingBottom: insets.bottom + 96 }}
>
{/* Live preview — deep gradient card with a contact chip and
network marks, mirroring the fields as you type. */}
<Mount className="mx-4 mb-5 h-48 justify-between overflow-hidden rounded-2xl p-5">
<HeroGradient from="#20242E" to="#0E1016" angle="horizontal" />
<View className="flex-row items-center justify-between">
{/* EMV chip + contactless mark — what a real card face carries. */}
<View className="flex-row items-center gap-2">
<View className="h-7 w-9 rounded-md bg-amber-200/90" />
<Icon name="wifi" size="sm" color="#FFFFFF" />
</View>
<Text className="text-sm font-semibold uppercase tracking-widest text-white/70">
Lumio
</Text>
</View>
<Text className="text-lg font-medium tracking-widest text-white">
{groups(number) || "•••• •••• •••• ••••"}
</Text>
<View className="flex-row items-end justify-between">
<View>
<Text className="text-[10px] uppercase text-white/50">
Cardholder
</Text>
<Text className="text-sm font-medium text-white">
{name || "Name on card"}
</Text>
</View>
<View>
<Text className="text-[10px] uppercase text-white/50">
Expires
</Text>
<Text className="text-sm font-medium text-white">
{expiry || "MM/YY"}
</Text>
</View>
{/* Overlapping-disc network mark. */}
<View className="flex-row items-center" style={{ width: 34 }}>
<View className="h-5 w-5 rounded-full bg-red-500/90" />
<View className="-ml-2.5 h-5 w-5 rounded-full bg-amber-400/80" />
</View>
</View>
</Mount>
{/* Accepted networks — wallet screens show their rails up front. */}
<Mount delay={40} className="mb-4 flex-row items-center justify-center gap-3 px-4">
{["visa", "mastercard", "amex", "applepay"].map((n) => (
<CardBrandMark key={n} network={n} size={22} />
))}
</Mount>
{/* Fields. */}
<Mount delay={60} className="gap-4 px-4">
<View className="relative">
<Input
label="Card number"
value={number}
onChangeText={setNumber}
placeholder="4571 8820 4413 4821"
keyboardType="number-pad"
accessibilityLabel="Card number"
/>
<Button
variant="ghost"
size="icon"
haptic="light"
onPress={() => onScan?.()}
accessibilityLabel="Scan card"
className="absolute right-1 top-6 h-10 w-10"
>
<Icon name="camera" size="sm" color="mutedForeground" />
</Button>
</View>
<Input
label="Name on card"
value={name}
onChangeText={setName}
placeholder="Amara Chen"
autoCapitalize="words"
accessibilityLabel="Name on card"
/>
<View className="flex-row gap-3">
<View className="flex-1">
<Input
label="Expiry"
value={expiry}
onChangeText={setExpiry}
placeholder="MM/YY"
keyboardType="number-pad"
accessibilityLabel="Expiry date"
/>
</View>
<View className="flex-1">
<Input
label="CVV"
value={cvv}
onChangeText={setCvv}
placeholder="123"
keyboardType="number-pad"
secureTextEntry
accessibilityLabel="Security code"
/>
</View>
</View>
<View className="mt-6 flex-row items-center justify-center gap-2">
<Icon name="lock" size="sm" color="mutedForeground" />
<Text variant="muted" className="text-xs">
Encrypted and stored securely
</Text>
</View>
</Mount>
</ScrollView>
<StickyBottomBar>
<Button
tone="inverse"
haptic="light"
disabled={!ready}
onPress={() => {
haptics.medium();
onAdd?.(last4);
}}
accessibilityLabel={`Add card ending ${last4}`}
className="w-full bg-[#1B1B26]"
>
Add card
</Button>
</StickyBottomBar>
</SafeAreaView>
);
}
AddCardScreen.displayName = "AddCardScreen";
Recreate the "Add Card Screen" screen in React Native using LumioUI.
Goal: Card entry with live preview Match the reference implementation's layout, behavior, and motion exactly — this is a production screen, not a mockup.
## Setup
Fastest path — install the screen plus its component deps:
```bash
npx lumioui add finance-add-card
```
Or pull just the components: `npx lumioui add button icon input text`
Native packages:
- @lumioui/ui@latest
- @lumioui/core@latest
- react-native-safe-area-context@*
- react-native-reanimated@*
- react-native-svg@*
- nativewind@*
Stack assumptions: Expo SDK 54 / RN 0.81, Reanimated 4, NativeWind v4, TypeScript strict, Expo Go compatible.
## Components — how, where, when
### `button` — Tactile pill button with press spring, ink wash and async loading.
- `<Button>` ×2
### `icon` — Lucide icon set mapped to theme colors and sizes.
- `<Icon>` ×4
### `input` — Labeled field with focus ring, error shake and success check.
- `<Input>` ×4
### `text` — Themed type scale from caption to display.
- `<Text>` ×8
## Conventions (non-negotiable)
- Styling via NativeWind `className` with semantic tokens only: `bg-background`, `text-foreground`, `bg-card`, `text-card-foreground`, `bg-secondary`, `bg-muted`, `text-muted-foreground`, `bg-accent`, `bg-destructive`, `border-border`. Hard-coded colors only inside media overlays (`text-white`, `bg-black/N`).
- Motion via the token presets from `@lumioui/core` (`spring.press`, `spring.surface`, `spring.glide`, `timing.fast`, `timing.slow`, …) — no bespoke spring configs or durations.
- Gate transform motion behind `useReducedMotion()`; keep opacity/color feedback, drop travel and overshoot.
- Haptics via `useHaptic()`: `light` on press, `selection` on toggle/select, `warning` on invalid input. Never import expo-haptics directly.
- Press feedback via `usePressAnimation()` (~0.97 scale), not `activeOpacity` tricks.
- a11y: `accessibilityRole` + `accessibilityLabel` on every control, touch targets ≥44pt.
- Entrance choreography: staggered `Mount` wrappers (delay 0/60/120…) so regions land in sequence instead of popping in at once.
- Wrap the screen in `SafeAreaView`; keep dark mode working via the semantic tokens.
## Deliverable
One file: `screens/finance/add-card.tsx` exporting AddCardScreen. Preserve the props interface — the host app wires the callbacks (navigation, submit handlers) through them.
## Reference implementation
The LumioUI source for this screen — reproduce it faithfully:
```tsx
import * as React from "react";
import { ScrollView, View } from "react-native";
import { SafeAreaView, useSafeAreaInsets } from "react-native-safe-area-context";
import { Button, Glass, Icon, Input, Text } from "@lumioui/ui";
import { useHaptic } from "@lumioui/core";
import { CardBrandMark, HeroGradient, LumioMark, Mount, Press, StickyBottomBar } from "../shared";
export interface AddCardScreenProps {
onScan?: () => void;
onAdd?: (last4: string) => void;
onBack?: () => void;
}
/** Group a card number into 4-4-4-4 for display. */
function groups(raw: string): string {
const digits = raw.replace(/\D/g, "").slice(0, 16);
return digits.replace(/(.{4})/g, "$1 ").trim();
}
/** Add card — live card preview that fills as you type + field group. */
export function AddCardScreen({
onScan,
onAdd,
onBack,
}: AddCardScreenProps) {
const haptics = useHaptic();
const insets = useSafeAreaInsets();
const [number, setNumber] = React.useState("4571 8820 4413 4821");
const [name, setName] = React.useState("Amara Chen");
const [expiry, setExpiry] = React.useState("09/28");
const [cvv, setCvv] = React.useState("123");
const last4 = number.replace(/\D/g, "").slice(-4) || "0000";
const ready = number.replace(/\D/g, "").length >= 15 && cvv.length >= 3;
return (
<SafeAreaView className="flex-1 bg-[#F4F5F9] dark:bg-[#111114]" edges={["top"]}>
<View pointerEvents="box-none" className="absolute inset-x-4 z-10" style={{ top: insets.top + 8 }}>
<View className="flex-row items-center justify-between">
<Glass interactive effect="regular" className="h-11 w-11 items-center justify-center rounded-full">
<Press
haptic="light"
onPress={() => onBack?.()}
accessibilityRole="button"
accessibilityLabel="Go back"
className="h-9 w-9 items-center justify-center"
>
<Icon name="chevron-left" size="md" color="foreground" />
</Press>
</Glass>
<View className="h-11 w-11" />
</View>
<View pointerEvents="none" className="absolute inset-0 items-center justify-center">
<View className="h-11 flex-row items-center justify-center gap-2 rounded-full pl-3.5 pr-5">
<Glass effect="regular" className="absolute inset-0 rounded-full" />
<LumioMark size={18} />
<Text accessibilityRole="header" className="text-sm font-bold tracking-tight">
Add card
</Text>
</View>
</View>
</View>
<ScrollView
showsVerticalScrollIndicator={false}
keyboardShouldPersistTaps="handled"
contentContainerStyle={{ paddingTop: insets.top + 60, paddingBottom: insets.bottom + 96 }}
>
{/* Live preview — deep gradient card with a contact chip and
network marks, mirroring the fields as you type. */}
<Mount className="mx-4 mb-5 h-48 justify-between overflow-hidden rounded-2xl p-5">
<HeroGradient from="#20242E" to="#0E1016" angle="horizontal" />
<View className="flex-row items-center justify-between">
{/* EMV chip + contactless mark — what a real card face carries. */}
<View className="flex-row items-center gap-2">
<View className="h-7 w-9 rounded-md bg-amber-200/90" />
<Icon name="wifi" size="sm" color="#FFFFFF" />
</View>
<Text className="text-sm font-semibold uppercase tracking-widest text-white/70">
Lumio
</Text>
</View>
<Text className="text-lg font-medium tracking-widest text-white">
{groups(number) || "•••• •••• •••• ••••"}
</Text>
<View className="flex-row items-end justify-between">
<View>
<Text className="text-[10px] uppercase text-white/50">
Cardholder
</Text>
<Text className="text-sm font-medium text-white">
{name || "Name on card"}
</Text>
</View>
<View>
<Text className="text-[10px] uppercase text-white/50">
Expires
</Text>
<Text className="text-sm font-medium text-white">
{expiry || "MM/YY"}
</Text>
</View>
{/* Overlapping-disc network mark. */}
<View className="flex-row items-center" style={{ width: 34 }}>
<View className="h-5 w-5 rounded-full bg-red-500/90" />
<View className="-ml-2.5 h-5 w-5 rounded-full bg-amber-400/80" />
</View>
</View>
</Mount>
{/* Accepted networks — wallet screens show their rails up front. */}
<Mount delay={40} className="mb-4 flex-row items-center justify-center gap-3 px-4">
{["visa", "mastercard", "amex", "applepay"].map((n) => (
<CardBrandMark key={n} network={n} size={22} />
))}
</Mount>
{/* Fields. */}
<Mount delay={60} className="gap-4 px-4">
<View className="relative">
<Input
label="Card number"
value={number}
onChangeText={setNumber}
placeholder="4571 8820 4413 4821"
keyboardType="number-pad"
accessibilityLabel="Card number"
/>
<Button
variant="ghost"
size="icon"
haptic="light"
onPress={() => onScan?.()}
accessibilityLabel="Scan card"
className="absolute right-1 top-6 h-10 w-10"
>
<Icon name="camera" size="sm" color="mutedForeground" />
</Button>
</View>
<Input
label="Name on card"
value={name}
onChangeText={setName}
placeholder="Amara Chen"
autoCapitalize="words"
accessibilityLabel="Name on card"
/>
<View className="flex-row gap-3">
<View className="flex-1">
<Input
label="Expiry"
value={expiry}
onChangeText={setExpiry}
placeholder="MM/YY"
keyboardType="number-pad"
accessibilityLabel="Expiry date"
/>
</View>
<View className="flex-1">
<Input
label="CVV"
value={cvv}
onChangeText={setCvv}
placeholder="123"
keyboardType="number-pad"
secureTextEntry
accessibilityLabel="Security code"
/>
</View>
</View>
<View className="mt-6 flex-row items-center justify-center gap-2">
<Icon name="lock" size="sm" color="mutedForeground" />
<Text variant="muted" className="text-xs">
Encrypted and stored securely
</Text>
</View>
</Mount>
</ScrollView>
<StickyBottomBar>
<Button
tone="inverse"
haptic="light"
disabled={!ready}
onPress={() => {
haptics.medium();
onAdd?.(last4);
}}
accessibilityLabel={`Add card ending ${last4}`}
className="w-full bg-[#1B1B26]"
>
Add card
</Button>
</StickyBottomBar>
</SafeAreaView>
);
}
AddCardScreen.displayName = "AddCardScreen";
```
Screen: https://lumioui.dev/screens/finance-add-card