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

PullRequestSheetContent.tsx

60 lines2.2 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";
8​
9export function PullRequestSheetContent(props: {
10 readonly title: string;
11 readonly subtitle: string;
12 readonly busy?: boolean;
13 readonly children: ReactNode;
14 readonly footer?: ReactNode;
15}) {
16 const navigation = useNavigation();
17 const insets = useSafeAreaInsets();
18 const { height: windowHeight } = useWindowDimensions();
19 const android = Platform.OS === "android";
20 const footer = props.footer ? (
21 <View
22 className={android ? "bg-sheet-solid pt-3" : "bg-sheet px-4 pt-3"}
23 style={{ paddingBottom: Math.max(insets.bottom, 16) }}
24 >
25 {android ? <View style={{ minHeight: 48 }}>{props.footer}</View> : props.footer}
26 </View>
27 ) : null;
28 return (
29 <KeyboardAvoidingView
30 automaticOffset
31 behavior="padding"
32 collapsable={false}
33 className="bg-sheet ios:flex-1"
34 style={android ? { maxHeight: windowHeight * 0.92 } : undefined}
35 >
36 <SheetHeader
37 title={props.title}
38 subtitle={props.subtitle}
39 onCancel={() => navigation.goBack()}
40 dismissDisabled={props.busy}
41 />
42 <ScreenContent fitToContents={android}>
43 <ScrollView
44 nestedScrollEnabled
45 className="android:shrink android:grow-0 ios:flex-1"
46 contentInsetAdjustmentBehavior="automatic"
47 keyboardShouldPersistTaps="handled"
48 contentContainerStyle={{ paddingHorizontal: 16, paddingTop: 16, paddingBottom: 20 }}
49 >
50 <View className="gap-4" pointerEvents={props.busy ? "none" : "auto"}>
51 {props.children}
52 {/* Android partial-height sheets keep submit actions within the scrollable form. */}
53 {android ? footer : null}
54 </View>
55 </ScrollView>
56 {android ? null : footer}
57 </ScreenContent>
58 </KeyboardAvoidingView>
59 );