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

PullRequestSheetContent.tsx

68 lines2.5 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}) {
17 const navigation = useNavigation();
18 const insets = useSafeAreaInsets();
19 const { height: windowHeight } = useWindowDimensions();
20 const android = Platform.OS === "android";
21 const footer = props.footer ? (
22 <View
23 className={android ? "bg-sheet-solid pt-3" : "bg-sheet px-4 pt-3"}
24 style={{ paddingBottom: Math.max(insets.bottom, 16) }}
25 >
26 {android ? <View style={{ minHeight: 48 }}>{props.footer}</View> : props.footer}
27 </View>
28 ) : null;
29 return (
30 <KeyboardAvoidingView
31 automaticOffset
32 behavior="padding"
33 collapsable={false}
34 className="bg-sheet ios:flex-1"
35 style={android ? { maxHeight: windowHeight * 0.92 } : undefined}
36 >
37 <NativeStackScreenOptions
38 options={{
39 gestureEnabled: !props.busy,
40 ...(android ? { sheetCornerRadius: 28, sheetAllowedDetents: "fitToContents" } : {}),
41 }}
42 />
43 <SheetHeader
44 presentation={android ? "inline" : "native"}
45 title={props.title}
46 subtitle={props.subtitle}
47 onCancel={() => navigation.goBack()}
48 dismissDisabled={props.busy}
49 />
50 <ScreenContent fitToContents={android}>
51 <ScrollView
52 nestedScrollEnabled
53 className="android:shrink android:grow-0 ios:flex-1"
54 contentInsetAdjustmentBehavior="automatic"
55 keyboardShouldPersistTaps="handled"
56 contentContainerStyle={{ paddingHorizontal: 16, paddingTop: 16, paddingBottom: 20 }}
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 {android ? null : footer}
65 </ScreenContent>
66 </KeyboardAvoidingView>
67 );