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

ScreenContent.tsx

55 lines1.4 KB

1import type { ReactNode } from "react";
2import { Platform, View, type LayoutChangeEvent } from "react-native";
3​
4const SURFACE_CLASS_NAMES = {
5 sheet: "bg-sheet-solid",
6 screen: "bg-screen",
7 canvas: "bg-thread-canvas",
8 drawer: "bg-drawer",
9} as const;
10​
11/**
12 * The body below a screen's AppBar. On Android it is the rounded card every pane and sheet
13 * draws under its bar; a screen picks only the card's surface.
14 */
15export function ScreenContent({
16 children,
17 surface = "sheet",
18 insetHorizontal = false,
19 fitToContents = false,
20 onLayout,
21}: {
22 readonly children: ReactNode;
23 readonly surface?: keyof typeof SURFACE_CLASS_NAMES;
24 readonly insetHorizontal?: boolean;
25 readonly fitToContents?: boolean;
26 readonly onLayout?: (event: LayoutChangeEvent) => void;
27}) {
28 if (Platform.OS !== "android") {
29 return onLayout ? (
30 <View className="flex-1" onLayout={onLayout}>
31 {children}
32 </View>
33 ) : (
34 children
35 );
36 }
37​
38 return (
39 <View className={fitToContents ? "shrink bg-header" : "flex-1 bg-header"}>
40 <View
41 className={`overflow-hidden rounded-t-[28px] ${SURFACE_CLASS_NAMES[surface]}`}
42 collapsable={false}
43 onLayout={onLayout}
44 style={{
45 flexShrink: 1,
46 flexGrow: fitToContents ? 0 : 1,
47 flexBasis: fitToContents ? "auto" : 0,
48 marginHorizontal: insetHorizontal ? 4 : 0,
49 }}
50 >
51 {children}
52 </View>
53 </View>
54 );