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

PullRequestSheetContent.tsx

88 lines3.1 KB

1import { SheetHeader } from "../../components/ui/SheetHeader";
2import { useNavigation } from "@react-navigation/native";
3import type { ReactNode } from "react";
4import { Platform, ScrollView, useWindowDimensions, View } from "react-native";
5import { KeyboardAvoidingView } from "react-native-keyboard-controller";
6import { useSafeAreaInsets } from "react-native-safe-area-context";
7import { ScreenContent } from "../../components/ui/ScreenContent";
8import { NativeStackScreenOptions } from "../../native/StackHeader";
9​
10export function PullRequestSheetContent(props: {
11 readonly title: string;
12 readonly subtitle: string;
13 readonly busy?: boolean;
14 readonly children: ReactNode;
15 readonly footer?: ReactNode;
16 readonly scrollable?: boolean;
17}) {
18 const navigation = useNavigation();
19 const insets = useSafeAreaInsets();
20 const { height: windowHeight } = useWindowDimensions();
21 const android = Platform.OS === "android";
22 const fitToContents = android && props.scrollable !== false;
23 const footer = props.footer ? (
24 <View
25 className={
26 android && props.scrollable !== false ? "bg-sheet-solid pt-3" : "bg-sheet px-4 pt-3"
27 }
28 style={{ paddingBottom: Math.max(insets.bottom, 16) }}
29 >
30 {android ? <View style={{ minHeight: 48 }}>{props.footer}</View> : props.footer}
31 </View>
32 ) : null;
33 const content = (
34 <>
35 <SheetHeader
36 presentation="inline"
37 title={props.title}
38 subtitle={props.subtitle}
39 onCancel={() => navigation.goBack()}
40 dismissDisabled={props.busy}
41 />
42 <ScreenContent fitToContents={fitToContents}>
43 {props.scrollable === false ? (
44 <View className="flex-1" pointerEvents={props.busy ? "none" : "auto"}>
45 {props.children}
46 </View>
47 ) : (
48 <ScrollView
49 nestedScrollEnabled
50 className="android:shrink android:grow-0 ios:flex-1"
51 keyboardShouldPersistTaps="handled"
52 contentContainerStyle={{
53 paddingHorizontal: 16,
54 paddingTop: android ? 16 : 0,
55 paddingBottom: 20,
56 }}
57 >
58 <View className="gap-4" pointerEvents={props.busy ? "none" : "auto"}>
59 {props.children}
60 {/* Android partial-height sheets keep submit actions within the scrollable form. */}
61 {android ? footer : null}
62 </View>
63 </ScrollView>
64 )}
65​
66 {!android || props.scrollable === false ? footer : null}
67 </ScreenContent>
68 </>
69 );
70 return (
71 <KeyboardAvoidingView
72 automaticOffset
73 behavior="padding"
74 collapsable={false}
75 className={props.scrollable === false ? "flex-1 bg-sheet" : "bg-sheet ios:flex-1"}
76 style={fitToContents ? { maxHeight: windowHeight * 0.92 } : undefined}
77 >
78 <NativeStackScreenOptions
79 options={{
80 gestureEnabled: !props.busy,
81 ...(android ? { sheetCornerRadius: 28 } : {}),
82 ...(fitToContents ? { sheetAllowedDetents: "fitToContents" } : {}),
83 }}
84 />
85 {content}
86 </KeyboardAvoidingView>
87 );