@vvedantb/native-ui 0.23.0 → 0.24.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,157 +0,0 @@
1
- import { ModalBottomSheet } from "@swmansion/react-native-bottom-sheet";
2
- import type { ModalDetent } from "@swmansion/react-native-bottom-sheet";
3
- import { IconX } from "@tabler/icons-react-native";
4
- import React, { useCallback, useEffect, useMemo, useState } from "react";
5
- import { StyleSheet, Text, TouchableOpacity, View } from "react-native";
6
- import { Colors } from "./colors";
7
- import { textStyle, typeStyle } from "./controlStyles";
8
- import { floatingSolidFill } from "./floating";
9
- import { withAlpha } from "./palette";
10
- import { useLargerText } from "./theme";
11
- import { tokens } from "./tokens";
12
- import { useScheme } from "./useScheme";
13
-
14
- const SHEET_RADIUS = 20;
15
-
16
- // A single open detent at 40%, so the default matches the gorhom container's one
17
- // snap point. A caller can pass several detents to try the library's multi-detent
18
- // sizing. The closed detent (0) is added by the component.
19
- const DEFAULT_DETENTS: readonly ModalDetent[] = ["40%"];
20
-
21
- // A dimming scrim like the gorhom backdrop's `opacity={0.5}`. The library scales
22
- // this alpha to 0 at the closed detent and to full at an open one.
23
- const SCRIM_COLOR = "rgba(0, 0, 0, 0.5)";
24
-
25
- /**
26
- * EXPERIMENTAL. A trial of Software Mansion's native `@swmansion/react-native-bottom-sheet`,
27
- * next to the gorhom-based {@link BottomSheetContainer}. It mirrors that container's role
28
- * and props: a controlled sheet over the screen, driven by `visible`/`onClose`, with a
29
- * title and a close button in the same chrome.
30
- *
31
- * It is built on `ModalBottomSheet` in `windowOverlay` mode, so it needs no root
32
- * `BottomSheetProvider` and nothing else in the app changes. The library is New
33
- * Architecture only and ships native code, so it needs a native build (no Expo Go).
34
- *
35
- * Extra over the gorhom container: `detents`, the library's multi-detent sizing. Pass
36
- * the open detents, shortest first; the default is a single 40% detent.
37
- */
38
- export function NativeBottomSheetContainer({
39
- visible,
40
- onClose,
41
- title,
42
- children,
43
- closeTestID,
44
- detents = DEFAULT_DETENTS,
45
- }: {
46
- visible: boolean;
47
- onClose: () => void;
48
- title: string;
49
- children: React.ReactNode;
50
- closeTestID?: string;
51
- /** Open detents, shortest first. The closed detent is added automatically. */
52
- detents?: readonly ModalDetent[];
53
- }) {
54
- const largerText = useLargerText();
55
- const scheme = useScheme();
56
- const isDark = scheme === "dark";
57
-
58
- // The library sheet is controlled by a detent index. The first detent is the
59
- // closed state (0); the open detents follow.
60
- const detentList = useMemo<ModalDetent[]>(() => [0, ...detents], [detents]);
61
- const [index, setIndex] = useState(0);
62
-
63
- // Keep the index in step with `visible`: open to the first detent, close to 0.
64
- useEffect(() => {
65
- setIndex((current) => (visible ? (current === 0 ? 1 : current) : 0));
66
- }, [visible]);
67
-
68
- // A user-driven drag to the closed detent reports here; tell the parent.
69
- const handleIndexChange = useCallback(
70
- (next: number) => {
71
- setIndex(next);
72
- if (next === 0) onClose();
73
- },
74
- [onClose],
75
- );
76
-
77
- // A scrim tap or system Back asks the sheet to close; close it and tell the parent.
78
- const handleCloseRequest = useCallback(() => {
79
- setIndex(0);
80
- onClose();
81
- }, [onClose]);
82
-
83
- const surface = (
84
- <View
85
- style={[StyleSheet.absoluteFill, { backgroundColor: floatingSolidFill[scheme] }]}
86
- />
87
- );
88
-
89
- return (
90
- <ModalBottomSheet
91
- index={index}
92
- detents={detentList}
93
- // Unmount the content once the sheet settles closed, as the gorhom container does.
94
- lazy
95
- windowOverlay
96
- scrimColor={SCRIM_COLOR}
97
- scrimAccessibilityLabel="Close"
98
- surface={surface}
99
- surfaceStyle={{
100
- borderTopLeftRadius: SHEET_RADIUS,
101
- borderTopRightRadius: SHEET_RADIUS,
102
- }}
103
- onIndexChange={handleIndexChange}
104
- onCloseRequest={handleCloseRequest}
105
- >
106
- <View style={{ flex: 1, paddingTop: 12 }}>
107
- <View
108
- accessibilityElementsHidden
109
- importantForAccessibility="no-hide-descendants"
110
- style={{
111
- alignSelf: "center",
112
- height: 6,
113
- width: 40,
114
- borderRadius: 999,
115
- backgroundColor: withAlpha(tokens.color.muted[scheme], 0.4),
116
- }}
117
- />
118
- <View
119
- style={{
120
- flexDirection: "row",
121
- alignItems: "center",
122
- justifyContent: "space-between",
123
- gap: 12,
124
- paddingHorizontal: 20,
125
- marginTop: 16,
126
- marginBottom: 16,
127
- }}
128
- >
129
- <Text
130
- accessibilityRole="header"
131
- style={[
132
- { flex: 1, fontSize: largerText ? 24 : 20 },
133
- textStyle("foreground", scheme),
134
- typeStyle("semibold"),
135
- ]}
136
- >
137
- {title}
138
- </Text>
139
- <TouchableOpacity
140
- testID={closeTestID}
141
- accessibilityRole="button"
142
- accessibilityLabel="Close"
143
- onPress={handleCloseRequest}
144
- style={{ marginRight: -8, height: 48, width: 48, alignItems: "center", justifyContent: "center" }}
145
- hitSlop={8}
146
- activeOpacity={0.7}
147
- >
148
- <IconX size={largerText ? 32 : 28} color={isDark ? Colors.white : Colors.black} />
149
- </TouchableOpacity>
150
- </View>
151
- <View style={{ flex: 1, paddingHorizontal: 20, paddingBottom: 48 }}>
152
- {children}
153
- </View>
154
- </View>
155
- </ModalBottomSheet>
156
- );
157
- }
@@ -1,4 +0,0 @@
1
- // `@vvedantb/native-ui/native-bottom-sheet`. Experimental: imports Software Mansion's
2
- // native `@swmansion/react-native-bottom-sheet` (an optional peer). Kept separate from
3
- // the gorhom `./bottom-sheet` entry so neither affects the other.
4
- export { NativeBottomSheetContainer } from "../NativeBottomSheetContainer";