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

SettingsScreen.tsx

43 lines1.5 KB

1import { useNavigation, useNavigationState, useRoute } from "@react-navigation/native";
2import type { ReactNode } from "react";
3import { Platform, View } from "react-native";
4​
5import type { AppBarProps } from "../../../components/ui/AppBar.types";
6import { AppBar } from "../../../components/ui/AppBar";
7import { ScreenContent as SettingsScreenContent } from "../../../components/ui/ScreenContent";
8import { useWorkspaceTabs } from "../../workspace/WorkspaceTabsContext";
9​
10export { SettingsScreenContent };
11​
12export function SettingsScreen(
13 props: Pick<AppBarProps, "title" | "actions" | "trailing"> & {
14 readonly children: ReactNode;
15 readonly formSheet?: boolean;
16 },
17) {
18 const navigation = useNavigation();
19 const route = useRoute();
20 const index = useNavigationState((state) => state.index);
21 const workspace = useWorkspaceTabs();
22 // Android opens Settings as a workspace tab; its root page has nothing to go back to.
23 const workspaceRoot =
24 Platform.OS === "android" && workspace !== null && index === 0 && route.name === "Settings";
25​
26 return (
27 <View collapsable={false} className="flex-1 bg-sheet">
28 <AppBar
29 title={props.title}
30 actions={props.actions}
31 trailing={Platform.OS === "android" ? props.trailing : undefined}
32 sidebar={false}
33 onBack={workspaceRoot ? undefined : () => navigation.goBack()}
34 hideBottomBorder={!props.formSheet}
35 />
36 {props.formSheet ? (
37 props.children
38 ) : (
39 <SettingsScreenContent>{props.children}</SettingsScreenContent>
40 )}
41 </View>
42 );