Floating action button
A floating action whose extended label can fold separately from scroll hiding.
npx @swipeui/cli add fabWhen to use it
- Keep one frequent creation action within thumb reach.
- Collapse a label on scroll while preserving an icon action, or hide the entire control independently.
When not to use it
- Place several competing primary actions above content.
- Assume automatic safe placement when placement is none.
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 fab- Adds
components/swipeui/ui/fab.tsx,components/swipeui/ui/use-fab.tsand 14 shared helpers. - Installs react-native-reanimated, uniwind, react-native-safe-area-context, react-native-worklets, clsx, tailwind-merge, expo-haptics, class-variance-authority, react-native-svg. In Expo apps it uses
npx expo installso versions match your SDK.
Usage
import { Fab } from '@/components/swipeui/ui/fab';
<Fab
icon={createIcon}
label="Create"
accessibilityLabel="Create note"
scrollProgress={progress}
onPress={createNote}
placement="bottom-end"
/>;Examples
extended, icon, hide. The app and public preview use the same content and variant names. Demo settings sit outside the component and outcome feedback stays on the action.
Settings
| Setting | Default | Behavior |
|---|---|---|
icon | absent | Decorative action node or themed render function. |
label | undefined | Extended action text; omit for icon only. |
accessibilityLabel | absent | Required accessible action name. |
scrollProgress | undefined | Scroll collapse/hide progress from useFabScroll, normalized 0–1. |
hideProgress | undefined | Legacy hide progress. Providing it retains automatic hiding. |
collapseOnScroll | true | Fold the label on scroll independently of hiding. |
hideOnScroll | true with legacy hideProgress, otherwise false | Hide the complete control on scroll. |
collapsed | false | Explicitly collapse the label independently of scroll. |
placement | 'none' | Optional safe placement; none leaves layout to caller. |
safeArea | true | Add device insets when placed. |
edgeOffset | 16 | Distance from safe screen edges in points. |
bottomOffset | 0 | Extra bottom clearance in points for a keyboard or navigation bar. |
variant | 'solid' | How much the button stands out: solid, tinted (a soft wash of the tone), outline, ghost (no fill until pressed) or plain (text only). The 1.x names default, secondary and destructive still work as solid primary, neutral and destructive. |
tone | 'primary' for solid, tinted and plain; 'neutral' for outline and ghost | The colour family: primary, neutral, destructive or success. |
size | lg | Shared Button sizes. |
shape | pill | Pill or preset corners. |
block | false | Stretches the button to the full width of its container. |
loading | false | Shows a spinner, reports busy and ignores taps. |
loadingLabel | absent | Label shown while loading; defaults to the children. |
loadingPlacement | 'start' | Where the spinner goes: start replaces the leading icon; center hides the label and holds the width. |
labelMorph | 'fade' | How a changed text label arrives: fade (the new label rises in as the old one fades), characters (only the changed letters roll in) or none. The width springs to fit either way. |
highlight | true | A faint rim of light along the top edge of solid buttons. |
glow | false | A soft shadow in the tone's colour under solid buttons. |
pressEffect | 'both' | Feedback while pressed: both scales and washes the surface, scale, wash or none. Text-only buttons dim their label instead of washing. |
disabledStyle | 'muted' | How a disabled button looks: muted mutes its fill and label; dim halves its opacity. |
palette | BUTTON_PALETTE | Colours that belong to the button's material rather than the theme (the top highlight). |
haptics | true | Plays a light impact on press. |
motion | the app's feel (smooth without a provider) | The app's motion feel, or a local override for the press, label and width springs. |
className | absent | Classes merged over the style. |
textClassName | absent | Classes for the label text. |
style | absent | Style escape hatch for the container. |
disabled | false | Prevent activation and expose unavailable state. |
testID | undefined | Root identifier; parts append suffixes. |
useFabScroll threshold | 24pt | Positive directional travel before changing progress; the full-screen native demo opts into 96pt. Web and library defaults remain 24pt. |
Composition and behavior
Attach useFabScroll().onScroll to an animated scroll view and pass its progress as scrollProgress. Pass the same motion override to the hook and the FAB. placement=none leaves positioning to your existing parent. The label is measured in a plain inner view without an animated layout transition.
useFabScroll tracks direction with a default 24pt threshold and returns normalized progress for collapse or hide. It ignores elastic offsets outside the content/viewport range, including content insets. Pass the complete native scroll event so those bounds are available. The elevation layer fades and translates with the control. Returning to the top restores expansion even with fractional elastic offsets. Natural label width stays pinned through collapse, with fresh measurement for changed labels, text classes, font scale or theme.
collapseOnScroll affects only the label. hideOnScroll affects visibility, pointer events and accessibility; legacy hideProgress retains its previous automatic hiding.
placement optionally anchors to a logical bottom edge. safeArea, edgeOffset and bottomOffset independently control device and keyboard/navigation clearance.
API reference
| Prop | Type | Default | Description |
|---|---|---|---|
layout? | | — | Optional layout transition for composed controls; derive its values from useMotion. |
motion? | | | The app's press character, or a local override. The app's motion feel, or a local override for the press, label and width springs. |
haptics? | | | Impact feedback on activation. Disable when a parent already provides feedback. Plays a light impact on press. |
variant? | | | How much the button stands out: |
tone? | | | The colour family: |
size? | | | The height: |
shape? | | |
|
block? | | | Stretches the button to the full width of its container. |
trailingIconNudge? | | | Slides the trailing icon a little forward while pressed, mirrored in right-to-left layouts. |
loading? | | | Shows a spinner, reports busy and ignores taps. |
loadingLabel? | | — | Label shown while loading; defaults to the children. |
loadingPlacement? | | | Where the spinner goes: |
singleLine? | | | Keep string labels and loading words on one clipped line. |
labelMorph? | | | How a changed text label arrives: |
highlight? | | | A faint rim of light along the top edge of solid buttons. |
glow? | | | A soft shadow in the tone's colour under solid buttons. |
pressEffect? | | | Feedback while pressed: |
disabledStyle? | | | How a disabled button looks: |
glassStatus? | | — | Keeps a completed or failed action’s Glass status visible when the control is locked. |
palette? | | | Colours that belong to the button's material rather than the theme (the top highlight). |
className? | | — | Classes merged over the style. |
textClassName? | | — | Classes for the label text. |
style? | | — | Style escape hatch for the container. |
icon | | — | Decorative action node or themed render function. |
label? | | | Extended action text; omit for icon only. |
scrollProgress? | | | Scroll collapse/hide progress from useFabScroll, normalized 0–1. |
hideProgress? | | | Legacy hide progress. Providing it retains automatic hiding. |
collapseOnScroll? | | | Fold the label on scroll independently of hiding. |
hideOnScroll? | | | Hide the complete control on scroll. |
collapsed? | | | Explicitly collapse the label independently of scroll. |
placement? | | | Optional safe placement; none leaves layout to caller. |
safeArea? | | | Add device insets when placed. |
edgeOffset? | | | Distance from safe screen edges in points. |
bottomOffset? | | | Extra bottom clearance in points for a keyboard or navigation bar. |
Review gates
Founder app and existing pnpm-dev visual acceptance remains open. Native runtime, VoiceOver/TalkBack, haptics, motion, Dynamic Type, RTL and recordings remain pending founder-scheduled 7.9. Source, bundle and unit checks do not establish visual or native acceptance.
The app gallery uses Open full-screen demo so the list gets its own scroll surface and the FAB anchors within it. Choose Extended, Icon or Hide in the demo header. Scroll down and up to collapse/reveal or hide/reveal, and activate Create. This full-screen touch demo waits for 96pt of directional movement (a few rows), while the existing web board keeps its 24pt setting. The web board is centered within the preview. This is fixture integration, not a native runtime acceptance claim.
Behavior and gestures
- useFabScroll tracks real in-bounds direction with a default 24pt threshold; edge bounce is ignored using content, viewport and inset geometry.
- collapseOnScroll affects only the label. hideOnScroll affects visibility, pointer events and accessibility; legacy hideProgress retains its previous automatic hiding.
- placement optionally anchors to a logical bottom edge. safeArea, edgeOffset and bottomOffset independently control device and keyboard/navigation clearance.
- The showcase opens a dedicated full-screen list, avoiding nested scroll capture. Extended collapses its label; icon/hide variants hide on down-scroll and return on up-scroll. The native full-screen demo waits for 96pt of directional travel; the web demo keeps 24pt. Elevation fades and moves with the entire control. Natural label width survives collapse and is remeasured when label or typography changes. Returning to the top restores expansion even with fractional elastic offsets. The web board is centered vertically.
Accessibility
- Named controls expose unavailable, busy and selected/progress state where applicable. Decorative layers are excluded from interaction.
- Meaningful outcome/availability announcements are distinct from clocks and decorative effects. Native VoiceOver/TalkBack, Dynamic Type, RTL and touch evidence remain pending for 7.9.
Motion
- Uses the
press,morphandnumbermotion roles, so it follows your app's feel. Passmotionto tune this one instance. - Every decorative duration/spring comes from the shared role helpers. Content clocks remain independent of motion feel.
- Reduce Motion retains readable outcome/progress feedback. Native motion/performance review remains pending.
Performance
- No new package, network service, telemetry or proprietary source.
- Async results and content timers clean up or invalidate after unmount; UI animation values stay on the UI thread.
Notes for AI
- Attach useFabScroll().onScroll to an animated scroll view and pass its progress as scrollProgress. Pass the same motion override to the hook and the FAB. placement=none leaves positioning to your existing parent. The label is measured in a plain inner view without an animated layout transition.
- Founder app/web acceptance and all native runtime, accessibility, haptics, motion and recordings remain pending for 7.9.
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.