Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

NativeAppBar.android.tsx

47 lines2.0 KB

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