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 /** Compose nodes laid out by the bar itself, so they never wait on a React Native measure. */
14 readonly nativeActions?: ReactElement;
15 /** Shorter bar for a one-row title. */
16 readonly singleLine?: boolean;
17}) {
18 const { colors } = useControlTheme();
19 const layout = useToolbarLayout(false, props.singleLine);
20 return (
21 // The bar's height is fixed, so React Native lays out the screen below it from the first frame
22 // instead of at zero height until Compose has measured and reported the bar.
23 <NativeThemeHost style={{ width: "100%", height: layout.height }}>
24 <TopAppBar
25 applyWindowInsets={false}
26 // Every header shares the list toolbar's height, so titles line up across panes.
27 modifiers={[fillMaxWidth(), height(layout.height)]}
28 colors={{
29 containerColor: colors["--color-header"],
30 titleContentColor: colors["--color-header-foreground"],
31 navigationIconContentColor: colors["--color-header-foreground"],
32 actionIconContentColor: colors["--color-header-foreground"],
33 }}
34 >
35 <TopAppBar.Title>{props.title}</TopAppBar.Title>
36 {props.navigationIcon ? (
37 <TopAppBar.NavigationIcon>
38 <RNHostView matchContents>{props.navigationIcon}</RNHostView>
39 </TopAppBar.NavigationIcon>
40 ) : null}
41 {props.actions || props.nativeActions ? (
42 <TopAppBar.Actions>
43 {props.nativeActions}
44 {props.actions ? <RNHostView matchContents>{props.actions}</RNHostView> : null}
45 </TopAppBar.Actions>
46 ) : null}
47 </TopAppBar>
48 </NativeThemeHost>
49 );
50}