Forms on mobile
Keep fields visible, move through the keyboard, preserve drafts and explain validation beside each input.
A mobile form needs more than a row of inputs. Keep the focused field visible, offer a route to the next field, and preserve what someone typed when validation fails. SwipeUI's inputs share labels and messages through Field.
Set up one keyboard host
Put FormProvider near the app root, inside your gesture and safe-area roots. Keep the provider outside the navigator so it survives screen changes. If the application already has Keyboard Controller's KeyboardProvider, keep that one.
import { GestureHandlerRootView } from 'react-native-gesture-handler';
import { SafeAreaProvider } from 'react-native-safe-area-context';
import { FormProvider } from '@/components/swipeui/ui/form';
import { SheetProvider } from '@/components/swipeui/sheet/sheet';
import { ToastHost, ToastProvider } from '@/components/swipeui/ui/toast';
export default function RootLayout() {
return (
<GestureHandlerRootView style={{ flex: 1 }}>
<SafeAreaProvider>
<FormProvider>
<SheetProvider>
<ToastProvider>
<Stack />
<ToastHost />
</ToastProvider>
</SheetProvider>
</FormProvider>
</SafeAreaProvider>
</GestureHandlerRootView>
);
}AppNavigation can be Expo Router or React Navigation. Sheets need the shared SheetProvider; toasts use exactly one ToastHost or ToastStack per ToastProvider. Notifications preserve task focus. Important actionable messages stay until dismissed by default.
Keep the focused input visible
Use FormScrollView for the form body and place FormToolbar beside it for previous, next and done actions. The toolbar helps with numeric keyboards that have no Return key. Avoid nesting the form inside another vertical scroll view.
import { useRef } from 'react';
import { FormScrollView, FormToolbar } from '@/components/swipeui/ui/form';
import { TextField } from '@/components/swipeui/ui/text-field';
import type { TextFieldRef } from '@/components/swipeui/ui/text-field';
export default function Contact() {
const emailRef = useRef<TextFieldRef>(null);
return (
<>
<FormScrollView contentContainerClassName="gap-4 p-4">
<TextField label="Full name" autoComplete="name" returnKeyType="next" nextRef={emailRef} />
<TextField ref={emailRef} label="Email" autoComplete="email" keyboardType="email-address" />
</FormScrollView>
<FormToolbar />
</>
);
}Refs use TextFieldRef, which follows the installed React Native TextInput instance type across SDK 57 and 58. Return moves to nextRef; the application decides when to submit. Test bottom safe areas and any fixed navigation clearance on a device.
Label the field, then explain the error
A field can create its own Field using label, helper, error and required. For a custom composition, put the messages on an enclosing Field. Keep a visible label; placeholders are examples rather than names.
<TextField
label="Email"
value={email}
onValueChange={setEmail}
error={attempted && !isValidEmail(email) ? 'Enter a valid email address.' : undefined}
/>Validation and persistence belong to the application. Keep invalid drafts visible, explain how to fix them beside the field, and focus the first invalid input after submission. Field connects descriptions and announces newly displayed errors. Do not announce every keystroke.
Preserve exact amounts and incomplete drafts
MoneyInput accepts safe integer minor units, or null for empty. USD 1250 is $12.50; JPY 1250 is ¥1,250; KWD 1250 is 1.250 dinar. The currency determines precision. Do not convert entered decimal text with floating-point multiplication.
<MoneyInput label="Budget" currency="USD" value={amount} onValueChange={setAmount} onValidityChange={setValid} />
<Button disabled={!valid} onPress={save}>Save budget</Button>An incomplete or invalid draft can differ from the last valid value. Use onValidityChange so submission cannot silently save that earlier value. SlotText supplies exact decorative display text; the native input retains editing and accessibility ownership.
Use platform entry features
- PasswordField sets current/new-password hints. PasswordStrength provides local requirements feedback, not an entropy estimate or a replacement for application policy.
- PhoneInput formats with minimal phone metadata and reports possible-length E.164 values. Formatting does not verify ownership or deliverability.
- OtpInput uses one real input for paste and autofill. It chooses iOS one-time-code or Android SMS-OTP hints without SMS permissions or interception.
- Date and time pickers share native/custom APIs. Use the custom engine when you need arbitrary disabled dates, preset styling or minute intervals. Consult each support table; native presentation and motion belong to the OS.
Review the form on a phone
Keep Dynamic Type enabled and let labels, messages and action rows wrap. Check right-to-left entry, mid-string editing, paste, autofill, screen readers, keyboard occlusion and Return/toolbar navigation on both platforms. Reduce Motion removes decorative travel, not validation or intentional hold thresholds.
The source, typechecks and JavaScript exports are verified for SDK 57, SDK 58 and the bare compatibility app. Native runtime, keyboard behavior, device accessibility, recordings and bare Uniwind runtime compatibility remain pending until the deferred native session. Browser previews are interactive approximations.