Skip to main content

AppBar

Top app bars display navigation, title, and actions at the top of the screen. Follows the Material Design 3 Top App Bar specification.

Usage

import { AppBar } from '@onlynative/components'
import { ThemeProvider } from '@onlynative/core'
import { SafeAreaProvider } from 'react-native-safe-area-context'
import { View } from 'react-native'

export default function App() {
return (
<SafeAreaProvider>
<ThemeProvider>
<View style={{ flex: 1 }}>
<AppBar title="Home" />
</View>
</ThemeProvider>
</SafeAreaProvider>
)
}

Variants

VariantDescription
smallCompact single-row bar (default)
center-alignedTitle centered in the bar
mediumExpanded two-row bar
largeExpanded with larger title typography

With Back Button

import { AppBar } from '@onlynative/components'
import { ThemeProvider } from '@onlynative/core'
import { SafeAreaProvider } from 'react-native-safe-area-context'
import { Alert, View } from 'react-native'

export default function App() {
return (
<SafeAreaProvider>
<ThemeProvider>
<View style={{ flex: 1 }}>
<AppBar
title="Details"
canGoBack
onBackPress={() => Alert.alert('Back pressed')}
/>
</View>
</ThemeProvider>
</SafeAreaProvider>
)
}

With Actions

import { AppBar } from '@onlynative/components'
import { ThemeProvider } from '@onlynative/core'
import { SafeAreaProvider } from 'react-native-safe-area-context'
import { Alert, View } from 'react-native'

export default function App() {
return (
<SafeAreaProvider>
<ThemeProvider>
<View style={{ flex: 1 }}>
<AppBar
title="Inbox"
actions={[
{ icon: 'magnify', accessibilityLabel: 'Search', onPress: () => Alert.alert('Search') },
{ icon: 'dots-vertical', accessibilityLabel: 'More', onPress: () => Alert.alert('More') },
]}
/>
</View>
</ThemeProvider>
</SafeAreaProvider>
)
}

Props

PropTypeDefaultRequiredDescription
titlestring-YesTitle text displayed in the bar.
variantenumsmallNoLayout variant.
colorSchemeenumsurfaceNoColor scheme that determines the default container and content colors. `containerColor` and `contentColor` props override these defaults.
canGoBackbooleanNoWhen `true`, renders a back button in the leading slot.
onBackPress() => void-NoCalled when the auto-rendered back button is pressed.
insetTopbooleanNoWhen `true`, wraps the bar in a SafeAreaView that handles the top inset.
elevatedbooleanNoWhen `true`, adds shadow/elevation to indicate the bar is scrolled.
leadingReactNode-NoCustom leading content. When provided, overrides `canGoBack`.
trailingReactNode-NoCustom trailing content. When provided, overrides `actions`.
actionsAppBarAction[]-NoArray of actions rendered in the trailing slot. Each entry is either an icon action (`{ icon }`) or a text action (`{ label }`, e.g. "Save").
containerColorstring-NoOverride the container (background) color. Applied to both normal and elevated states.
contentColorstring-NoOverride the content (title and icon) color.
titleStyleStyleProp<TextStyle>-NoAdditional style applied to the title text.
styleStyleProp<ViewStyle>-NoCustom style applied to the root container.