Skip to main content

FAB

A floating action button (FAB) represents the primary action of the screen. It appears in front of all other content, usually pinned to a corner. It follows the Material Design 3 Floating Action Button specification.

The icon prop accepts three forms: a string name (resolved through the iconResolver of the theme, for example mdiResolver for MaterialDesignIcons), a pre-rendered React element from any icon library, or a render function that receives the resolved { size, color }. See the Icons guide for details.

Usage​

import { FAB } from '@rootnative/components'
import { mdiResolver } from '@rootnative/components/mdi'
import { ThemeProvider } from '@rootnative/core'
import { SafeAreaProvider } from 'react-native-safe-area-context'
import { View } from 'react-native'

export default function App() {
return (
<SafeAreaProvider>
<ThemeProvider iconResolver={mdiResolver}>
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
<FAB
icon="plus"
accessibilityLabel="Add"
onPress={() => {}}
/>
</View>
</ThemeProvider>
</SafeAreaProvider>
)
}

Variants​

VariantContainerContent
primaryprimaryContaineronPrimaryContainer
secondarysecondaryContaineronSecondaryContainer
tertiarytertiaryContaineronTertiaryContainer
surfacesurfaceContainerHighprimary

Sizes​

import { FAB } from '@rootnative/components'
import { mdiResolver } from '@rootnative/components/mdi'
import { ThemeProvider } from '@rootnative/core'
import { SafeAreaProvider } from 'react-native-safe-area-context'
import { View } from 'react-native'

export default function App() {
return (
<SafeAreaProvider>
<ThemeProvider iconResolver={mdiResolver}>
<View style={{ flex: 1, flexDirection: 'row', alignItems: 'center', justifyContent: 'center', gap: 16 }}>
<FAB icon="plus" size="small" accessibilityLabel="Add (small)" onPress={() => {}} />
<FAB icon="plus" size="medium" accessibilityLabel="Add (medium)" onPress={() => {}} />
<FAB icon="plus" size="large" accessibilityLabel="Add (large)" onPress={() => {}} />
</View>
</ThemeProvider>
</SafeAreaProvider>
)
}
SizeContainerIconShape
small40 × 4024dpcornerMedium (12)
medium (default)56 × 5624dpcornerLarge (16)
large96 × 9636dpcornerExtraLarge (28)

Extended​

Pass a label to render an extended FAB. An extended FAB is always 56dp tall, so the size prop is not available.

import { FAB } from '@rootnative/components'
import { mdiResolver } from '@rootnative/components/mdi'
import { ThemeProvider } from '@rootnative/core'
import { SafeAreaProvider } from 'react-native-safe-area-context'
import { View } from 'react-native'

export default function App() {
return (
<SafeAreaProvider>
<ThemeProvider iconResolver={mdiResolver}>
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center', gap: 12 }}>
<FAB icon="plus" label="Compose" onPress={() => {}} />
<FAB icon="pencil-outline" label="Edit" variant="surface" onPress={() => {}} />
</View>
</ThemeProvider>
</SafeAreaProvider>
)
}

The label is also the accessible name, so accessibilityLabel is optional in extended mode. Override it when a screen reader needs a more descriptive name.

Bring your own icon library​

import { FAB } from '@rootnative/components'
import { Plus } from 'lucide-react-native'

<FAB
icon={({ size, color }) => <Plus size={size} color={color} />}
accessibilityLabel="Add"
/>

Custom Colors​

Override containerColor and contentColor to replace the variant defaults. The component derives the state-layer colors (hover, press, focus) for you.

import { FAB } from '@rootnative/components'
import { mdiResolver } from '@rootnative/components/mdi'
import { ThemeProvider } from '@rootnative/core'
import { SafeAreaProvider } from 'react-native-safe-area-context'
import { View } from 'react-native'

export default function App() {
return (
<SafeAreaProvider>
<ThemeProvider iconResolver={mdiResolver}>
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
<FAB
icon="heart"
containerColor="#B00020"
contentColor="#FFFFFF"
accessibilityLabel="Favorite"
onPress={() => {}}
/>
</View>
</ThemeProvider>
</SafeAreaProvider>
)
}

Flat​

Pass elevated={false} to remove the shadow and the lift on hover. The container color and the state layers stay the same. MD3 uses a flat FAB in a bottom app bar.

<FAB icon="plus" variant="secondary" elevated={false} accessibilityLabel="Add" />

Props​

PropTypeDefaultRequiredDescription
iconIconSource-YesIcon to display. Accepts a string name (resolved via the theme's `iconResolver`, for example `mdiResolver`), a pre-rendered element, or a render function that receives `{ size, color }`.
labelstring-NoOptional text label. When provided, renders an extended FAB (56dp tall) and `size` is ignored. The label is also used as the accessible name unless `accessibilityLabel` is also set.
variantenumprimaryNoColor variant. Controls container and content colors.
sizeenum'medium'NoPhysical size. Ignored when `label` is set.
containerColorstring-NoOverride the container (background) color. State-layer colors (hover, press) are derived automatically.
contentColorstring-NoOverride the content (icon + label) color. State-layer colors are derived automatically when no `containerColor` is set.
labelStyleStyleProp<TextStyle>-NoStyle applied to the label text. Only used when `label` is set.
styleStyleProp<ViewStyle>-NoStyle for the component. The keys that place or size it in its parent — `alignSelf`, `flex`, `flexGrow`, `flexShrink`, `flexBasis`, `width`, the margins, `position`, the insets and `zIndex` — go to the outer wrapper, so the focus ring and the shadow move with it. `minWidth` and `maxWidth` go with a `width`; alone, they style the container. The wrapper sets no `alignSelf`, so the parent's `alignItems` places the component. In a parent that stretches its children, the component keeps its own width at the start edge. Every other key styles the container. Static form only — the function form `(state) => style` is not supported because the component drives its container background through Reanimated. Use `containerColor` / `contentColor` for state-aware styling.
onPress() => void-NoCalled when the FAB is pressed.
disabledbooleanNoDisables the FAB.
elevatedbooleanNoWhen `false`, the FAB draws no shadow and does not lift on hover. MD3 places a flat FAB in a `BottomAppBar`, which sets this for you. The container color and the state layers do not change.
accessibilityLabelstring-NoAccessible name for screen readers. Required for icon-only FABs. When `label` is set, defaults to the label and may be omitted (override only if you need a more descriptive name).