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

Sheet.tsx

69 lines2.4 KB

1import { useId, useState } from "react";
2import { Platform, View } from "react-native";
3import { FormSheet, ScreenStack } from "react-native-screens";
4import { useResolveClassNames } from "uniwind";
5​
6import { nativeHeaderScrollEdgeEffects } from "../../native/StackHeader";
7import { formSheetDetents } from "../../native/sheet-surface";
8import { NativeHeader, NativeScreen } from "../../native/ThemedScreenStack";
9​
10const HEADER_SCROLL_EDGE_EFFECTS = nativeHeaderScrollEdgeEffects(Platform.OS, Platform.Version);
11​
12export type { SheetProps } from "./Sheet.types";
13import type { SheetProps } from "./Sheet.types";
14​
15/** Native presentation. Scrollable children use automatic insets beneath the iOS header. */
16export function Sheet(props: SheetProps) {
17 const containerStyle = useResolveClassNames("bg-sheet");
18 const screenId = useId();
19 const [isOpen, setIsOpen] = useState(true);
20 const close = () => setIsOpen(false);
21​
22 return (
23 <FormSheet
24 isOpen={isOpen}
25 detents={formSheetDetents(0.5, 0.9)}
26 prefersGrabberVisible
27 // The header holds the close button, so the Duo needs no rail inside this sheet.
28 prefersHorizontalBars
29 nativeContainerStyle={containerStyle}
30 onDismiss={props.onClose}
31 onNativeDismiss={props.onClose}
32 >
33 <View collapsable={false} className="flex-1 bg-sheet">
34 <ScreenStack style={{ flex: 1 }}>
35 <NativeScreen
36 activityState={2}
37 enabled
38 isNativeStack
39 screenId={`app-sheet-${screenId}`}
40 scrollEdgeEffects={HEADER_SCROLL_EDGE_EFFECTS}
41 className="flex-1 bg-sheet"
42 >
43 {props.children}
44 <NativeHeader
45 backgroundColor="rgba(0,0,0,0)"
46 tintColorClassName="accent-foreground"
47 hideBackButton
48 hideShadow={false}
49 title={props.title}
50 titleColorClassName="accent-foreground"
51 titleFontSize={18}
52 titleFontWeight="800"
53 translucent
54 headerRightBarButtonItems={[
55 {
56 type: "button",
57 icon: { name: "xmark", type: "sfSymbol" },
58 accessibilityLabel: `Close ${props.title}`,
59 identifier: `app-sheet-close-${screenId}`,
60 onPress: close,
61 },
62 ]}
63 />
64 </NativeScreen>
65 </ScreenStack>
66 </View>
67 </FormSheet>
68 );