Live physical-card preview that fills in while typing — PAN grouping, brand detection, expiry/CVC/holder/ZIP fields — above a secure save bar
import * as React from "react";
import { useState } from "react";
import { View, ScrollView, Pressable } 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 { BLOCK_STAGGER, CardBrandMark, LumioMark, Mount, Press, StickyBottomBar } from "../shared";
export interface NewPaymentMethod {
/** Full PAN — the face only ever renders the last four. */
number: string;
/** "MM/YY" */
expiry: string;
cvc: string;
holder: string;
/** Billing postal code. */
zip: string;
/** Detected network wordmark — "VISA" | "MASTERCARD" | "AMEX" | "". */
brand: string;
}
export interface AddPaymentScreenProps {
onSave?: (card: NewPaymentMethod) => void;
/** Wallet/camera scan affordance on the number field's right edge. */
onScanCard?: () => void;
onBack?: () => void;
}
/** PAN grouping — 4-4-4-4 as the user types, capped at 19 digits. */
function formatCardNumber(raw: string) {
const digits = raw.replace(/\D/g, "").slice(0, 19);
return digits.replace(/(.{4})/g, "$1 ").trim();
}
function detectBrand(digits: string) {
if (digits.startsWith("4")) return "VISA";
if (/^5[1-5]/.test(digits)) return "MASTERCARD";
if (/^3[47]/.test(digits)) return "AMEX";
return "";
}
/** "0812" → "08/12" — inserts the slash once the month pair is full. */
function formatExpiry(raw: string) {
const digits = raw.replace(/\D/g, "").slice(0, 4);
return digits.length > 2 ? `${digits.slice(0, 2)}/${digits.slice(2)}` : digits;
}
/** Add payment method — a live card face that fills in as the user types,
* above grouped number/expiry/CVC/name/ZIP fields and a save bar. */
export function AddPaymentScreen({
onSave,
onScanCard,
onBack,
}: AddPaymentScreenProps) {
const haptics = useHaptic();
const insets = useSafeAreaInsets();
const [number, setNumber] = useState("4571 8820 4413 4821");
const [expiry, setExpiry] = useState("09/28");
const [cvc, setCvc] = useState("123");
const [holder, setHolder] = useState("Amara Chen");
const [zip, setZip] = useState("94107");
const digits = number.replace(/\D/g, "");
const brand = detectBrand(digits);
const complete =
digits.length >= 15 &&
expiry.length === 5 &&
cvc.length >= 3 &&
holder.trim().length > 0 &&
zip.trim().length > 0;
return (
<SafeAreaView className="flex-1 bg-[#F4F5F9] dark:bg-[#111114]" edges={["top"]}>
{/* Floating chrome — back disc + centered brand/title pill. */}
<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
className="flex-1"
showsVerticalScrollIndicator={false}
contentContainerClassName="gap-5 px-6"
contentContainerStyle={{ paddingTop: insets.top + 60, paddingBottom: 24 }}
keyboardShouldPersistTaps="handled"
>
{/* Card face preview — fills in live; masked digits for the untyped rest. */}
<Mount>
<View
accessible
accessibilityRole="text"
accessibilityLabel={`Card preview${brand ? `, ${brand}` : ""}${
digits.length > 0 ? ` ending in ${digits.slice(-4)}` : ""
}`}
className="aspect-[1.586] w-full overflow-hidden rounded-3xl bg-[#1B1B26] p-5"
>
<View className="flex-1 justify-between">
<View className="flex-row items-center justify-between">
<View className="h-7 w-10 rounded-md bg-white/25" accessible={false} />
{brand ? <CardBrandMark network={brand} size={26} /> : <LumioMark size={22} />}
</View>
<Text
className="font-mono text-xl font-semibold tracking-[0.18em] text-white"
accessibilityElementsHidden
>
{number || "•••• •••• •••• ••••"}
</Text>
<View className="flex-row items-end justify-between">
<View className="flex-1 pr-4">
<Text className="text-[10px] uppercase tracking-wider text-white/50">
Card holder
</Text>
<Text
numberOfLines={1}
className="text-sm font-semibold uppercase tracking-wide text-white"
>
{holder || "Your name"}
</Text>
</View>
<View className="items-end">
<Text className="text-[10px] uppercase tracking-wider text-white/50">
Expires
</Text>
<Text className="text-sm font-semibold tabular-nums text-white">
{expiry || "MM/YY"}
</Text>
</View>
</View>
</View>
</View>
</Mount>
{/* Accepted networks — the marks every card form shows up front. */}
<View className="flex-row items-center justify-center gap-4">
{(["visa", "mastercard", "amex", "applepay"] as const).map((n) => (
<CardBrandMark key={n} network={n} size={22} />
))}
</View>
<Mount delay={BLOCK_STAGGER} className="gap-4">
<Input
glass
label="Card number"
placeholder="4571 8820 4413 4821"
value={number}
onChangeText={(t) => setNumber(formatCardNumber(t))}
keyboardType="number-pad"
maxLength={23}
accessibilityLabel="Card number"
rightIcon={
onScanCard ? (
<Pressable
onPress={() => {
haptics.light();
onScanCard();
}}
accessibilityRole="button"
accessibilityLabel="Scan card with camera"
hitSlop={8}
>
<Icon name="camera" size="sm" color="mutedForeground" />
</Pressable>
) : (
<Icon name="credit-card" size="sm" color="mutedForeground" />
)
}
/>
<View className="flex-row gap-3">
<Input
glass
label="Expiry"
placeholder="MM/YY"
value={expiry}
onChangeText={(t) => setExpiry(formatExpiry(t))}
keyboardType="number-pad"
maxLength={5}
accessibilityLabel="Expiry date"
containerClassName="flex-1"
/>
<Input
glass
label="CVC"
placeholder="123"
value={cvc}
onChangeText={(t) => setCvc(t.replace(/\D/g, "").slice(0, 4))}
keyboardType="number-pad"
maxLength={4}
helper="3–4 digits"
accessibilityLabel="Security code"
containerClassName="flex-1"
/>
</View>
<Input
glass
label="Name on card"
placeholder="Amara Chen"
value={holder}
onChangeText={setHolder}
autoCapitalize="words"
accessibilityLabel="Name on card"
/>
<Input
glass
label="Billing ZIP"
placeholder="94107"
value={zip}
onChangeText={(t) => setZip(t.replace(/\D/g, "").slice(0, 10))}
keyboardType="number-pad"
maxLength={10}
accessibilityLabel="Billing ZIP code"
/>
</Mount>
</ScrollView>
<StickyBottomBar className="gap-3">
<Button
tone="inverse"
haptic="medium"
disabled={!complete}
icon={<Icon name="lock" size="sm" color="primaryForeground" />}
onPress={() => {
haptics.success();
onSave?.({ number, expiry, cvc, holder: holder.trim(), zip: zip.trim(), brand });
}}
accessibilityLabel="Save card"
>
Save card
</Button>
<View
className="flex-row items-center justify-center gap-1.5 self-center rounded-full bg-white px-4 py-1.5 dark:bg-[#1A1A20]"
accessibilityElementsHidden
importantForAccessibility="no"
>
<Icon name="shield" size="sm" color="#65A30D" />
<Text variant="muted" className="text-xs">
Card details are encrypted and never stored on this device
</Text>
</View>
</StickyBottomBar>
</SafeAreaView>
);
}
AddPaymentScreen.displayName = "AddPaymentScreen";
Recreate the "Add Payment Screen" screen in React Native using LumioUI.
Goal: Live physical-card preview that fills in while typing — PAN grouping, brand detection, expiry/CVC/holder/ZIP fields — above a secure save bar 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 ecommerce-add-payment
```
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>` ×1
### `icon` — Lucide icon set mapped to theme colors and sizes.
- `<Icon>` ×5
### `input` — Labeled field with focus ring, error shake and success check.
- `<Input>` ×5
### `text` — Themed type scale from caption to display.
- `<Text>` ×7
## 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/ecommerce/add-payment.tsx` exporting AddPaymentScreen. 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 { useState } from "react";
import { View, ScrollView, Pressable } 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 { BLOCK_STAGGER, CardBrandMark, LumioMark, Mount, Press, StickyBottomBar } from "../shared";
export interface NewPaymentMethod {
/** Full PAN — the face only ever renders the last four. */
number: string;
/** "MM/YY" */
expiry: string;
cvc: string;
holder: string;
/** Billing postal code. */
zip: string;
/** Detected network wordmark — "VISA" | "MASTERCARD" | "AMEX" | "". */
brand: string;
}
export interface AddPaymentScreenProps {
onSave?: (card: NewPaymentMethod) => void;
/** Wallet/camera scan affordance on the number field's right edge. */
onScanCard?: () => void;
onBack?: () => void;
}
/** PAN grouping — 4-4-4-4 as the user types, capped at 19 digits. */
function formatCardNumber(raw: string) {
const digits = raw.replace(/\D/g, "").slice(0, 19);
return digits.replace(/(.{4})/g, "$1 ").trim();
}
function detectBrand(digits: string) {
if (digits.startsWith("4")) return "VISA";
if (/^5[1-5]/.test(digits)) return "MASTERCARD";
if (/^3[47]/.test(digits)) return "AMEX";
return "";
}
/** "0812" → "08/12" — inserts the slash once the month pair is full. */
function formatExpiry(raw: string) {
const digits = raw.replace(/\D/g, "").slice(0, 4);
return digits.length > 2 ? `${digits.slice(0, 2)}/${digits.slice(2)}` : digits;
}
/** Add payment method — a live card face that fills in as the user types,
* above grouped number/expiry/CVC/name/ZIP fields and a save bar. */
export function AddPaymentScreen({
onSave,
onScanCard,
onBack,
}: AddPaymentScreenProps) {
const haptics = useHaptic();
const insets = useSafeAreaInsets();
const [number, setNumber] = useState("4571 8820 4413 4821");
const [expiry, setExpiry] = useState("09/28");
const [cvc, setCvc] = useState("123");
const [holder, setHolder] = useState("Amara Chen");
const [zip, setZip] = useState("94107");
const digits = number.replace(/\D/g, "");
const brand = detectBrand(digits);
const complete =
digits.length >= 15 &&
expiry.length === 5 &&
cvc.length >= 3 &&
holder.trim().length > 0 &&
zip.trim().length > 0;
return (
<SafeAreaView className="flex-1 bg-[#F4F5F9] dark:bg-[#111114]" edges={["top"]}>
{/* Floating chrome — back disc + centered brand/title pill. */}
<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
className="flex-1"
showsVerticalScrollIndicator={false}
contentContainerClassName="gap-5 px-6"
contentContainerStyle={{ paddingTop: insets.top + 60, paddingBottom: 24 }}
keyboardShouldPersistTaps="handled"
>
{/* Card face preview — fills in live; masked digits for the untyped rest. */}
<Mount>
<View
accessible
accessibilityRole="text"
accessibilityLabel={`Card preview${brand ? `, ${brand}` : ""}${
digits.length > 0 ? ` ending in ${digits.slice(-4)}` : ""
}`}
className="aspect-[1.586] w-full overflow-hidden rounded-3xl bg-[#1B1B26] p-5"
>
<View className="flex-1 justify-between">
<View className="flex-row items-center justify-between">
<View className="h-7 w-10 rounded-md bg-white/25" accessible={false} />
{brand ? <CardBrandMark network={brand} size={26} /> : <LumioMark size={22} />}
</View>
<Text
className="font-mono text-xl font-semibold tracking-[0.18em] text-white"
accessibilityElementsHidden
>
{number || "•••• •••• •••• ••••"}
</Text>
<View className="flex-row items-end justify-between">
<View className="flex-1 pr-4">
<Text className="text-[10px] uppercase tracking-wider text-white/50">
Card holder
</Text>
<Text
numberOfLines={1}
className="text-sm font-semibold uppercase tracking-wide text-white"
>
{holder || "Your name"}
</Text>
</View>
<View className="items-end">
<Text className="text-[10px] uppercase tracking-wider text-white/50">
Expires
</Text>
<Text className="text-sm font-semibold tabular-nums text-white">
{expiry || "MM/YY"}
</Text>
</View>
</View>
</View>
</View>
</Mount>
{/* Accepted networks — the marks every card form shows up front. */}
<View className="flex-row items-center justify-center gap-4">
{(["visa", "mastercard", "amex", "applepay"] as const).map((n) => (
<CardBrandMark key={n} network={n} size={22} />
))}
</View>
<Mount delay={BLOCK_STAGGER} className="gap-4">
<Input
glass
label="Card number"
placeholder="4571 8820 4413 4821"
value={number}
onChangeText={(t) => setNumber(formatCardNumber(t))}
keyboardType="number-pad"
maxLength={23}
accessibilityLabel="Card number"
rightIcon={
onScanCard ? (
<Pressable
onPress={() => {
haptics.light();
onScanCard();
}}
accessibilityRole="button"
accessibilityLabel="Scan card with camera"
hitSlop={8}
>
<Icon name="camera" size="sm" color="mutedForeground" />
</Pressable>
) : (
<Icon name="credit-card" size="sm" color="mutedForeground" />
)
}
/>
<View className="flex-row gap-3">
<Input
glass
label="Expiry"
placeholder="MM/YY"
value={expiry}
onChangeText={(t) => setExpiry(formatExpiry(t))}
keyboardType="number-pad"
maxLength={5}
accessibilityLabel="Expiry date"
containerClassName="flex-1"
/>
<Input
glass
label="CVC"
placeholder="123"
value={cvc}
onChangeText={(t) => setCvc(t.replace(/\D/g, "").slice(0, 4))}
keyboardType="number-pad"
maxLength={4}
helper="3–4 digits"
accessibilityLabel="Security code"
containerClassName="flex-1"
/>
</View>
<Input
glass
label="Name on card"
placeholder="Amara Chen"
value={holder}
onChangeText={setHolder}
autoCapitalize="words"
accessibilityLabel="Name on card"
/>
<Input
glass
label="Billing ZIP"
placeholder="94107"
value={zip}
onChangeText={(t) => setZip(t.replace(/\D/g, "").slice(0, 10))}
keyboardType="number-pad"
maxLength={10}
accessibilityLabel="Billing ZIP code"
/>
</Mount>
</ScrollView>
<StickyBottomBar className="gap-3">
<Button
tone="inverse"
haptic="medium"
disabled={!complete}
icon={<Icon name="lock" size="sm" color="primaryForeground" />}
onPress={() => {
haptics.success();
onSave?.({ number, expiry, cvc, holder: holder.trim(), zip: zip.trim(), brand });
}}
accessibilityLabel="Save card"
>
Save card
</Button>
<View
className="flex-row items-center justify-center gap-1.5 self-center rounded-full bg-white px-4 py-1.5 dark:bg-[#1A1A20]"
accessibilityElementsHidden
importantForAccessibility="no"
>
<Icon name="shield" size="sm" color="#65A30D" />
<Text variant="muted" className="text-xs">
Card details are encrypted and never stored on this device
</Text>
</View>
</StickyBottomBar>
</SafeAreaView>
);
}
AddPaymentScreen.displayName = "AddPaymentScreen";
```
Screen: https://lumioui.dev/screens/ecommerce-add-payment