Open History to see the last commit
1import { RNHostView, TopAppBar } from "@expo/ui/jetpack-compose";
2import { fillMaxWidth, height } from "@expo/ui/jetpack-compose/modifiers";
3import type { ReactElement } from "react";
4import { NativeThemeHost } from "./NativeThemeHost.android";
5import { useControlTheme } from "./useControlTheme";
6import { useToolbarLayout } from "./useToolbarLayout";
7
8/** Internal renderer. The surrounding screen owns status-bar and sheet insets. */
9export function NativeAppBar(props: {
10 readonly title: ReactElement;
11 readonly navigationIcon?: ReactElement;
12 readonly actions?: ReactElement;
13}) {
14 const { colors } = useControlTheme();
15 const layout = useToolbarLayout();
16 return (
17 // The bar's height is fixed, so React Native lays out the screen below it from the first frame
18 // instead of at zero height until Compose has measured and reported the bar.
19 <NativeThemeHost style={{ width: "100%", height: layout.height }}>
20 <TopAppBar
21 applyWindowInsets={false}
22 // Every header shares the list toolbar's height, so titles line up across panes.
23 modifiers={[fillMaxWidth(), height(layout.height)]}
24 colors={{
25 containerColor: colors["--color-header"],
26 titleContentColor: colors["--color-header-foreground"],
27 navigationIconContentColor: colors["--color-header-foreground"],
28 actionIconContentColor: colors["--color-header-foreground"],
29 }}
30 >
31 <TopAppBar.Title>{props.title}</TopAppBar.Title>
32 {props.navigationIcon ? (
33 <TopAppBar.NavigationIcon>
34 <RNHostView matchContents>{props.navigationIcon}</RNHostView>
35 </TopAppBar.NavigationIcon>
36 ) : null}
37 {props.actions ? (
38 <TopAppBar.Actions>
39 <RNHostView matchContents>{props.actions}</RNHostView>
40 </TopAppBar.Actions>
41 ) : null}
42 </TopAppBar>
43 </NativeThemeHost>
44 );
45}