related-ui-components 2.4.8 → 2.5.0
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.
- package/lib/module/app.js +39 -21
- package/lib/module/app.js.map +1 -1
- package/lib/module/components/Input/PhoneInput.js +178 -0
- package/lib/module/components/Input/PhoneInput.js.map +1 -0
- package/lib/module/components/Input/index.js +2 -0
- package/lib/module/components/Input/index.js.map +1 -1
- package/lib/module/contexts/BottomSheetStackContext.js +12 -0
- package/lib/module/contexts/BottomSheetStackContext.js.map +1 -0
- package/lib/module/contexts/BottomSheetStackProvider.js +111 -0
- package/lib/module/contexts/BottomSheetStackProvider.js.map +1 -0
- package/lib/module/contexts/index.js +2 -2
- package/lib/module/contexts/index.js.map +1 -1
- package/lib/module/utils/flags.js +6 -0
- package/lib/module/utils/flags.js.map +1 -0
- package/lib/typescript/src/components/Input/PhoneInput.d.ts +22 -0
- package/lib/typescript/src/components/Input/PhoneInput.d.ts.map +1 -0
- package/lib/typescript/src/components/Input/index.d.ts +2 -0
- package/lib/typescript/src/components/Input/index.d.ts.map +1 -1
- package/lib/typescript/src/contexts/BottomSheetStackContext.d.ts +16 -0
- package/lib/typescript/src/contexts/BottomSheetStackContext.d.ts.map +1 -0
- package/lib/typescript/src/contexts/BottomSheetStackProvider.d.ts +5 -0
- package/lib/typescript/src/contexts/BottomSheetStackProvider.d.ts.map +1 -0
- package/lib/typescript/src/contexts/index.d.ts +2 -2
- package/lib/typescript/src/contexts/index.d.ts.map +1 -1
- package/lib/typescript/src/utils/flags.d.ts +2 -0
- package/lib/typescript/src/utils/flags.d.ts.map +1 -0
- package/package.json +4 -1
- package/src/app.tsx +39 -21
- package/src/components/Input/PhoneInput.tsx +214 -0
- package/src/components/Input/index.ts +4 -1
- package/src/contexts/BottomSheetStackContext.tsx +30 -0
- package/src/contexts/BottomSheetStackProvider.tsx +138 -0
- package/src/contexts/index.ts +2 -2
- package/src/utils/flags.ts +7 -0
- package/lib/module/contexts/BottomSheetContext.js +0 -13
- package/lib/module/contexts/BottomSheetContext.js.map +0 -1
- package/lib/module/contexts/BottomSheetProvider.js +0 -104
- package/lib/module/contexts/BottomSheetProvider.js.map +0 -1
- package/lib/typescript/src/contexts/BottomSheetContext.d.ts +0 -10
- package/lib/typescript/src/contexts/BottomSheetContext.d.ts.map +0 -1
- package/lib/typescript/src/contexts/BottomSheetProvider.d.ts +0 -7
- package/lib/typescript/src/contexts/BottomSheetProvider.d.ts.map +0 -1
- package/src/contexts/BottomSheetContext.tsx +0 -28
- package/src/contexts/BottomSheetProvider.tsx +0 -136
package/src/app.tsx
CHANGED
|
@@ -2,9 +2,20 @@
|
|
|
2
2
|
// import { SafeAreaView, StyleSheet, StatusBar } from "react-native";
|
|
3
3
|
// import CarouselCardStack from "./components/CarouselCardStack/CarouselCardStack"; // Adjust path as needed
|
|
4
4
|
// import { GestureHandlerRootView } from "react-native-gesture-handler";
|
|
5
|
-
// import {
|
|
5
|
+
// import {
|
|
6
|
+
// CarRentalForm,
|
|
7
|
+
// DateRangePicker,
|
|
8
|
+
// FlightForm,
|
|
9
|
+
// FlightSummary,
|
|
10
|
+
// HotelForm,
|
|
11
|
+
// HotelSummary,
|
|
12
|
+
// Filters,
|
|
13
|
+
// } from "./components";
|
|
6
14
|
// import { lightTheme, RelatedProvider, useTheme } from "./theme";
|
|
7
15
|
// import CircularProgressBar from "./components/ProgressBar/CircularProgressBar";
|
|
16
|
+
// import PhoneInput from "./components/Input/PhoneInput";
|
|
17
|
+
// import { BottomSheetStackProvider } from "./contexts";
|
|
18
|
+
// import { SafeAreaProvider } from "react-native-safe-area-context";
|
|
8
19
|
|
|
9
20
|
// // Sample data - replace with your actual image URLs
|
|
10
21
|
// const DUMMY_DATA = [
|
|
@@ -43,27 +54,31 @@
|
|
|
43
54
|
// const App = () => {
|
|
44
55
|
// const { theme } = useTheme();
|
|
45
56
|
|
|
46
|
-
// const [departureDate, setDepartureDate] = useState<string | undefined>(
|
|
57
|
+
// const [departureDate, setDepartureDate] = useState<string | undefined>(
|
|
58
|
+
// undefined
|
|
59
|
+
// );
|
|
47
60
|
// const [returnDate, setReturnDate] = useState<string | undefined>(undefined);
|
|
48
61
|
|
|
49
62
|
// const [progress, setProgress] = useState(25);
|
|
50
|
-
//
|
|
63
|
+
// const handleAnimate = () => {
|
|
51
64
|
// // Set progress to a new random value between 0 and 100
|
|
52
65
|
// const newProgress = Math.floor(Math.random() * 101);
|
|
53
66
|
// setProgress(newProgress);
|
|
54
67
|
// };
|
|
55
68
|
// return (
|
|
56
69
|
// <>
|
|
57
|
-
//
|
|
58
|
-
//
|
|
59
|
-
//
|
|
60
|
-
// <
|
|
61
|
-
// <
|
|
70
|
+
// <SafeAreaProvider>
|
|
71
|
+
// <GestureHandlerRootView style={{ flex: 1 }}>
|
|
72
|
+
// <RelatedProvider theme={lightTheme}>
|
|
73
|
+
// <BottomSheetStackProvider>
|
|
74
|
+
// <StatusBar barStyle="light-content" />
|
|
75
|
+
// <SafeAreaView style={styles.appContainer}>
|
|
76
|
+
// {/* <CircularProgressBar
|
|
62
77
|
// progress={5}
|
|
63
78
|
// lineCap="round"
|
|
64
79
|
// textFont={""}
|
|
65
|
-
// />
|
|
66
|
-
//
|
|
80
|
+
// /> */}
|
|
81
|
+
// {/* <DateRangePicker
|
|
67
82
|
// onDatesChange={(t) => {
|
|
68
83
|
// setDepartureDate(t.departure);
|
|
69
84
|
// setReturnDate(t.return);
|
|
@@ -73,7 +88,7 @@
|
|
|
73
88
|
// returnDate={returnDate}
|
|
74
89
|
// // returnDisplayValue={returnDate}
|
|
75
90
|
// ></DateRangePicker> */}
|
|
76
|
-
//
|
|
91
|
+
// {/* <Filters
|
|
77
92
|
// bottomSheetBackgroundStyle={{
|
|
78
93
|
// borderTopRightRadius: 30,
|
|
79
94
|
// borderTopLeftRadius: 30,
|
|
@@ -97,16 +112,19 @@
|
|
|
97
112
|
// applyButtonTextStyle={{ color: theme.secondary }}
|
|
98
113
|
// headerStyle={{ borderBottomWidth: 0 }}
|
|
99
114
|
// ></Filters> */}
|
|
100
|
-
//
|
|
101
|
-
//
|
|
102
|
-
//
|
|
103
|
-
//
|
|
104
|
-
//
|
|
105
|
-
//
|
|
106
|
-
//
|
|
107
|
-
//
|
|
108
|
-
//
|
|
109
|
-
//
|
|
115
|
+
// {/* <FlightSummary></FlightSummary> */}
|
|
116
|
+
// {/* <FlightForm></FlightForm> */}
|
|
117
|
+
// {/* <HotelSummary></HotelSummary> */}
|
|
118
|
+
// {/* <HotelForm></HotelForm> */}
|
|
119
|
+
// {/* <DateRangePicker onDatesChange={()=>{}} labelContainerStyle={{backgroundColor:"red"}}></DateRangePicker> */}
|
|
120
|
+
// {/* <CarRentalForm onSelectionChange={console.log}></CarRentalForm> */}
|
|
121
|
+
// {/* <CarouselCardStack data={DUMMY_DATA} /> */}
|
|
122
|
+
// <PhoneInput value="" onChangeText={() => {}} inputContainerStyle={{height: 55}}></PhoneInput>
|
|
123
|
+
// </SafeAreaView>
|
|
124
|
+
// </BottomSheetStackProvider>
|
|
125
|
+
// </RelatedProvider>
|
|
126
|
+
// </GestureHandlerRootView>
|
|
127
|
+
// </SafeAreaProvider>
|
|
110
128
|
// </>
|
|
111
129
|
// );
|
|
112
130
|
// };
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
import React, { forwardRef, useState, useMemo, useCallback } from "react";
|
|
2
|
+
import {
|
|
3
|
+
TextInput,
|
|
4
|
+
Text,
|
|
5
|
+
View,
|
|
6
|
+
TouchableOpacity,
|
|
7
|
+
StyleSheet,
|
|
8
|
+
FlatList,
|
|
9
|
+
TextInputProps,
|
|
10
|
+
StyleProp,
|
|
11
|
+
TextStyle,
|
|
12
|
+
} from "react-native";
|
|
13
|
+
import CustomInput, { CustomInputProps } from "./Input";
|
|
14
|
+
import { useTheme } from "../../theme";
|
|
15
|
+
import { Popup } from "../Popup";
|
|
16
|
+
import { Ionicons } from "@expo/vector-icons";
|
|
17
|
+
import { useBottomSheetStack } from "../../contexts";
|
|
18
|
+
import { BottomSheetFlatList } from "@gorhom/bottom-sheet";
|
|
19
|
+
import { allCountries } from 'country-telephone-data';
|
|
20
|
+
import { iso2ToFlagEmoji } from "../../utils/flags";
|
|
21
|
+
|
|
22
|
+
export type Country = {
|
|
23
|
+
code: string;
|
|
24
|
+
iso2: string;
|
|
25
|
+
name: string;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export interface PhoneInputProps
|
|
29
|
+
extends Omit<
|
|
30
|
+
CustomInputProps,
|
|
31
|
+
| "leftIcon"
|
|
32
|
+
| "rightIcon"
|
|
33
|
+
| "onRightIconPress"
|
|
34
|
+
| "keyboardType"
|
|
35
|
+
| "style"
|
|
36
|
+
| "placeholderTextColor"
|
|
37
|
+
> {
|
|
38
|
+
value: string;
|
|
39
|
+
onChangeText: (text: string) => void;
|
|
40
|
+
selectedCountry?: Country;
|
|
41
|
+
onSelectCountry?: (c: Country) => void;
|
|
42
|
+
countries?: Country[];
|
|
43
|
+
|
|
44
|
+
//styles
|
|
45
|
+
countryNameStyle?: StyleProp<TextStyle>;
|
|
46
|
+
countryCodeStyle?: StyleProp<TextStyle>;
|
|
47
|
+
listTitleStyle?: StyleProp<TextStyle>;
|
|
48
|
+
|
|
49
|
+
listTitle?: string
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const DEFAULT_COUNTRIES: Country[] = allCountries.map(c => ({
|
|
53
|
+
code: `+${c.dialCode}`,
|
|
54
|
+
iso2: c.iso2,
|
|
55
|
+
name: c.name,
|
|
56
|
+
}));
|
|
57
|
+
|
|
58
|
+
const PhoneInput = forwardRef<TextInput, PhoneInputProps>(
|
|
59
|
+
(
|
|
60
|
+
{
|
|
61
|
+
value,
|
|
62
|
+
onChangeText,
|
|
63
|
+
selectedCountry,
|
|
64
|
+
onSelectCountry,
|
|
65
|
+
countries = DEFAULT_COUNTRIES,
|
|
66
|
+
containerStyle,
|
|
67
|
+
inputContainerStyle,
|
|
68
|
+
inputStyle,
|
|
69
|
+
label,
|
|
70
|
+
labelStyle,
|
|
71
|
+
error,
|
|
72
|
+
errorStyle,
|
|
73
|
+
helper,
|
|
74
|
+
helperStyle,
|
|
75
|
+
listTitle = "Select Country",
|
|
76
|
+
listTitleStyle,
|
|
77
|
+
countryCodeStyle,
|
|
78
|
+
countryNameStyle,
|
|
79
|
+
...rest
|
|
80
|
+
},
|
|
81
|
+
ref
|
|
82
|
+
) => {
|
|
83
|
+
const { theme } = useTheme();
|
|
84
|
+
const { push } = useBottomSheetStack();
|
|
85
|
+
|
|
86
|
+
const sel = useMemo(
|
|
87
|
+
() =>
|
|
88
|
+
selectedCountry ||
|
|
89
|
+
countries.find((c) => c.code === "+1") ||
|
|
90
|
+
countries[0],
|
|
91
|
+
[selectedCountry, countries]
|
|
92
|
+
);
|
|
93
|
+
|
|
94
|
+
const handleCountryPress = useCallback(
|
|
95
|
+
(c: Country) => {
|
|
96
|
+
onSelectCountry && onSelectCountry(c);
|
|
97
|
+
},
|
|
98
|
+
[onSelectCountry]
|
|
99
|
+
);
|
|
100
|
+
|
|
101
|
+
const renderCountry = ({ item }: { item: Country }) => (
|
|
102
|
+
<TouchableOpacity
|
|
103
|
+
style={styles.countryRow}
|
|
104
|
+
onPress={() => handleCountryPress(item)}
|
|
105
|
+
>
|
|
106
|
+
<Text style={styles.flag}> {iso2ToFlagEmoji(item.iso2)}</Text>
|
|
107
|
+
<View style={styles.countryText}>
|
|
108
|
+
<Text style={[styles.countryName, countryNameStyle]}>{item.name}</Text>
|
|
109
|
+
<Text style={[styles.countryCode, countryCodeStyle]}>{item.code}</Text>
|
|
110
|
+
</View>
|
|
111
|
+
</TouchableOpacity>
|
|
112
|
+
);
|
|
113
|
+
|
|
114
|
+
const leftIcon = (
|
|
115
|
+
<TouchableOpacity
|
|
116
|
+
style={[styles.selector, { backgroundColor: theme.inputBackground }]}
|
|
117
|
+
hitSlop={{left: 30, top: 30, right: 30, bottom: 30}}
|
|
118
|
+
onPress={() =>
|
|
119
|
+
push({
|
|
120
|
+
component: (
|
|
121
|
+
<View style={styles.popup}>
|
|
122
|
+
<Text style={[styles.popupTitle, listTitleStyle, { color: theme.text }]}>
|
|
123
|
+
{listTitle}
|
|
124
|
+
</Text>
|
|
125
|
+
<BottomSheetFlatList
|
|
126
|
+
data={countries}
|
|
127
|
+
keyExtractor={(c, i) => i.toString()}
|
|
128
|
+
renderItem={renderCountry}
|
|
129
|
+
contentContainerStyle={{ paddingBottom: 16 }}
|
|
130
|
+
/>
|
|
131
|
+
</View>
|
|
132
|
+
),
|
|
133
|
+
snapPoints: ["100%"]
|
|
134
|
+
})
|
|
135
|
+
}
|
|
136
|
+
activeOpacity={0.8}
|
|
137
|
+
>
|
|
138
|
+
<Text style={[styles.flag, { color: theme.inputText }]}>
|
|
139
|
+
{iso2ToFlagEmoji(sel.iso2)}
|
|
140
|
+
</Text>
|
|
141
|
+
<Text style={[styles.code, { color: theme.inputText }]}>
|
|
142
|
+
{sel.code}
|
|
143
|
+
</Text>
|
|
144
|
+
<Ionicons name="chevron-down" size={16} style={{marginHorizontal: 4}}></Ionicons>
|
|
145
|
+
</TouchableOpacity>
|
|
146
|
+
);
|
|
147
|
+
|
|
148
|
+
return (
|
|
149
|
+
<>
|
|
150
|
+
<CustomInput
|
|
151
|
+
ref={ref}
|
|
152
|
+
label={label}
|
|
153
|
+
value={value}
|
|
154
|
+
onChangeText={onChangeText}
|
|
155
|
+
keyboardType="phone-pad"
|
|
156
|
+
placeholder="123 456 7890"
|
|
157
|
+
leftIcon={leftIcon}
|
|
158
|
+
containerStyle={containerStyle}
|
|
159
|
+
inputContainerStyle={inputContainerStyle}
|
|
160
|
+
inputStyle={inputStyle}
|
|
161
|
+
labelStyle={labelStyle}
|
|
162
|
+
error={error}
|
|
163
|
+
errorStyle={errorStyle}
|
|
164
|
+
helper={helper}
|
|
165
|
+
helperStyle={helperStyle}
|
|
166
|
+
{...rest}
|
|
167
|
+
/>
|
|
168
|
+
</>
|
|
169
|
+
);
|
|
170
|
+
}
|
|
171
|
+
);
|
|
172
|
+
|
|
173
|
+
const styles = StyleSheet.create({
|
|
174
|
+
selector: {
|
|
175
|
+
flexDirection: "row",
|
|
176
|
+
alignItems: "center",
|
|
177
|
+
borderRightWidth: 1,
|
|
178
|
+
borderRightColor: "grey"
|
|
179
|
+
},
|
|
180
|
+
flag: {
|
|
181
|
+
fontSize: 18,
|
|
182
|
+
},
|
|
183
|
+
code: {
|
|
184
|
+
fontSize: 14,
|
|
185
|
+
marginLeft: 4,
|
|
186
|
+
},
|
|
187
|
+
popup: {
|
|
188
|
+
// maxHeight: 400,
|
|
189
|
+
width: "100%",
|
|
190
|
+
padding: 16,
|
|
191
|
+
},
|
|
192
|
+
popupTitle: {
|
|
193
|
+
fontSize: 18,
|
|
194
|
+
fontWeight: "600",
|
|
195
|
+
marginBottom: 12,
|
|
196
|
+
},
|
|
197
|
+
countryRow: {
|
|
198
|
+
flexDirection: "row",
|
|
199
|
+
alignItems: "center",
|
|
200
|
+
paddingVertical: 10,
|
|
201
|
+
},
|
|
202
|
+
countryText: {
|
|
203
|
+
marginLeft: 12,
|
|
204
|
+
},
|
|
205
|
+
countryName: {
|
|
206
|
+
fontSize: 16,
|
|
207
|
+
},
|
|
208
|
+
countryCode: {
|
|
209
|
+
fontSize: 14,
|
|
210
|
+
color: "#666",
|
|
211
|
+
},
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
export default PhoneInput;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import React, { ReactNode, useContext } from "react";
|
|
2
|
+
|
|
3
|
+
export interface BottomSheetStackItem {
|
|
4
|
+
component: ReactNode;
|
|
5
|
+
snapPoints?: string[] | number[];
|
|
6
|
+
initialSnapIndex?: number;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface BottomSheetStackContextType {
|
|
10
|
+
push: (item: BottomSheetStackItem) => void;
|
|
11
|
+
pop: () => void;
|
|
12
|
+
replace: (item: BottomSheetStackItem) => void;
|
|
13
|
+
clear: () => void;
|
|
14
|
+
canGoBack: boolean;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export const BottomSheetStackContext =
|
|
18
|
+
React.createContext<BottomSheetStackContextType | null>(null);
|
|
19
|
+
|
|
20
|
+
export const useBottomSheetStack = () => {
|
|
21
|
+
const context = useContext(BottomSheetStackContext);
|
|
22
|
+
|
|
23
|
+
if (!context) {
|
|
24
|
+
throw new Error(
|
|
25
|
+
"useBottomSheetStack must be used within a BottomSheetStackProvider"
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return context;
|
|
30
|
+
};
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import BottomSheet, {
|
|
2
|
+
BottomSheetBackdrop,
|
|
3
|
+
BottomSheetBackdropProps,
|
|
4
|
+
} from "@gorhom/bottom-sheet";
|
|
5
|
+
import React, {
|
|
6
|
+
ReactNode,
|
|
7
|
+
useCallback,
|
|
8
|
+
useEffect,
|
|
9
|
+
useMemo,
|
|
10
|
+
useRef,
|
|
11
|
+
useState,
|
|
12
|
+
} from "react";
|
|
13
|
+
import { BackHandler, StyleSheet } from "react-native";
|
|
14
|
+
import Animated, { FadeIn, FadeOut } from "react-native-reanimated";
|
|
15
|
+
import { useSafeAreaInsets } from "react-native-safe-area-context";
|
|
16
|
+
import {
|
|
17
|
+
BottomSheetStackContext,
|
|
18
|
+
BottomSheetStackItem,
|
|
19
|
+
} from "./BottomSheetStackContext";
|
|
20
|
+
|
|
21
|
+
export const BottomSheetStackProvider: React.FC<{ children: ReactNode }> = ({
|
|
22
|
+
children,
|
|
23
|
+
}) => {
|
|
24
|
+
const [stack, setStack] = useState<BottomSheetStackItem[]>([]);
|
|
25
|
+
const sheetRef = useRef<BottomSheet>(null);
|
|
26
|
+
const { top } = useSafeAreaInsets();
|
|
27
|
+
|
|
28
|
+
const push = useCallback((item: BottomSheetStackItem) => {
|
|
29
|
+
setStack((prev) => [...prev, item]);
|
|
30
|
+
}, []);
|
|
31
|
+
|
|
32
|
+
const clear = useCallback(() => {
|
|
33
|
+
sheetRef.current?.close();
|
|
34
|
+
setStack([]);
|
|
35
|
+
}, []);
|
|
36
|
+
|
|
37
|
+
const pop = useCallback(() => {
|
|
38
|
+
if (stack.length <= 1) {
|
|
39
|
+
clear();
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
setStack((prev) => prev.slice(0, -1));
|
|
43
|
+
}, [stack.length, clear]);
|
|
44
|
+
|
|
45
|
+
const replace = useCallback((item: BottomSheetStackItem) => {
|
|
46
|
+
setStack((prev) => [...prev.slice(0, -1), item]);
|
|
47
|
+
}, []);
|
|
48
|
+
|
|
49
|
+
const currentItem = useMemo(() => stack[stack.length - 1], [stack]);
|
|
50
|
+
const canGoBack = stack.length > 1;
|
|
51
|
+
const isOpen = stack.length > 0;
|
|
52
|
+
|
|
53
|
+
useEffect(() => {
|
|
54
|
+
if (isOpen && currentItem) {
|
|
55
|
+
sheetRef.current?.snapToIndex(0);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const backHandlerSubscription = BackHandler.addEventListener(
|
|
59
|
+
"hardwareBackPress",
|
|
60
|
+
() => {
|
|
61
|
+
if (canGoBack) {
|
|
62
|
+
pop();
|
|
63
|
+
return true;
|
|
64
|
+
}
|
|
65
|
+
if (!canGoBack && stack.length === 1) {
|
|
66
|
+
sheetRef.current?.close();
|
|
67
|
+
return true;
|
|
68
|
+
}
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
return () => backHandlerSubscription.remove();
|
|
74
|
+
}, [isOpen, canGoBack, currentItem, pop, stack]);
|
|
75
|
+
|
|
76
|
+
const AnimatedView = Animated.View;
|
|
77
|
+
const enteringAnimation = FadeIn.duration(200);
|
|
78
|
+
const exitingAnimation = FadeOut.duration(200);
|
|
79
|
+
|
|
80
|
+
const renderBackdrop = useCallback(
|
|
81
|
+
(props: BottomSheetBackdropProps) => (
|
|
82
|
+
<BottomSheetBackdrop
|
|
83
|
+
{...props}
|
|
84
|
+
disappearsOnIndex={-1}
|
|
85
|
+
style={[props.style, { backgroundColor: "rgba(0,0,0,0,1)" }]}
|
|
86
|
+
appearsOnIndex={0}
|
|
87
|
+
pressBehavior={"close"}
|
|
88
|
+
/>
|
|
89
|
+
),
|
|
90
|
+
[]
|
|
91
|
+
);
|
|
92
|
+
|
|
93
|
+
return (
|
|
94
|
+
<BottomSheetStackContext.Provider
|
|
95
|
+
value={{ push, pop, replace, clear, canGoBack }}
|
|
96
|
+
>
|
|
97
|
+
{children}
|
|
98
|
+
<BottomSheet
|
|
99
|
+
ref={sheetRef}
|
|
100
|
+
index={0}
|
|
101
|
+
snapPoints={currentItem?.snapPoints || ["100%"]}
|
|
102
|
+
enableDynamicSizing={currentItem?.snapPoints === undefined}
|
|
103
|
+
enablePanDownToClose
|
|
104
|
+
android_keyboardInputMode="adjustResize"
|
|
105
|
+
enableBlurKeyboardOnGesture
|
|
106
|
+
keyboardBlurBehavior="restore"
|
|
107
|
+
keyboardBehavior="fillParent"
|
|
108
|
+
onClose={clear}
|
|
109
|
+
backdropComponent={renderBackdrop}
|
|
110
|
+
topInset={top}
|
|
111
|
+
handleIndicatorStyle={{ backgroundColor: "#CCCCCC" }}
|
|
112
|
+
style={styles.sheetContainer}
|
|
113
|
+
>
|
|
114
|
+
{currentItem && (
|
|
115
|
+
<AnimatedView
|
|
116
|
+
key={stack.length}
|
|
117
|
+
entering={enteringAnimation}
|
|
118
|
+
exiting={exitingAnimation}
|
|
119
|
+
style={styles.animatedView}
|
|
120
|
+
>
|
|
121
|
+
{currentItem.component}
|
|
122
|
+
</AnimatedView>
|
|
123
|
+
)}
|
|
124
|
+
</BottomSheet>
|
|
125
|
+
</BottomSheetStackContext.Provider>
|
|
126
|
+
);
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
const styles = StyleSheet.create({
|
|
130
|
+
sheetContainer: {
|
|
131
|
+
// backgroundColor: "#FFFFFF",
|
|
132
|
+
// borderTopLeftRadius: 20,
|
|
133
|
+
// borderTopRightRadius: 20,
|
|
134
|
+
},
|
|
135
|
+
animatedView: {
|
|
136
|
+
flex: 1,
|
|
137
|
+
},
|
|
138
|
+
});
|
package/src/contexts/index.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from "./
|
|
2
|
-
export * from "./
|
|
1
|
+
export * from "./BottomSheetStackContext"
|
|
2
|
+
export * from "./BottomSheetStackProvider"
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
import { createContext, useContext } from "react";
|
|
4
|
-
const BottomSheetContext = /*#__PURE__*/createContext(undefined);
|
|
5
|
-
export const useBottomSheet = () => {
|
|
6
|
-
const context = useContext(BottomSheetContext);
|
|
7
|
-
if (!context) {
|
|
8
|
-
throw new Error("useBottomSheet must be used within a BottomSheetProvider");
|
|
9
|
-
}
|
|
10
|
-
return context;
|
|
11
|
-
};
|
|
12
|
-
export default BottomSheetContext;
|
|
13
|
-
//# sourceMappingURL=BottomSheetContext.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["createContext","useContext","BottomSheetContext","undefined","useBottomSheet","context","Error"],"sourceRoot":"..\\..\\..\\src","sources":["contexts/BottomSheetContext.tsx"],"mappings":";;AAAA,SAASA,aAAa,EAAEC,UAAU,QAAmB,OAAO;AAa5D,MAAMC,kBAAkB,gBAAGF,aAAa,CACtCG,SACF,CAAC;AAED,OAAO,MAAMC,cAAc,GAAGA,CAAA,KAAM;EAClC,MAAMC,OAAO,GAAGJ,UAAU,CAACC,kBAAkB,CAAC;EAC9C,IAAI,CAACG,OAAO,EAAE;IACZ,MAAM,IAAIC,KAAK,CACb,0DACF,CAAC;EACH;EACA,OAAOD,OAAO;AAChB,CAAC;AAED,eAAeH,kBAAkB","ignoreList":[]}
|
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
import React, { useState, useRef, useCallback, useMemo, useEffect } from "react";
|
|
4
|
-
import BottomSheet, { BottomSheetBackdrop } from "@gorhom/bottom-sheet";
|
|
5
|
-
import BottomSheetContext from "./BottomSheetContext.js";
|
|
6
|
-
import { Keyboard, StyleSheet } from "react-native";
|
|
7
|
-
import { useTheme } from "../theme/index.js";
|
|
8
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
9
|
-
export const BottomSheetProvider = ({
|
|
10
|
-
children
|
|
11
|
-
}) => {
|
|
12
|
-
const {
|
|
13
|
-
theme
|
|
14
|
-
} = useTheme(); // Get theme for styling the provider's sheet if needed
|
|
15
|
-
const styles = useMemo(() => providerStyles(theme), [theme]);
|
|
16
|
-
const sheetRef = useRef(null);
|
|
17
|
-
const [isOpen, setIsOpen] = useState(false);
|
|
18
|
-
const [content, setContent] = useState(null);
|
|
19
|
-
const [size, setSize] = useState("small");
|
|
20
|
-
const [sp, setSnapPoints] = useState(["30%", "50%", "85%"]);
|
|
21
|
-
const [onCloseCallback, setOnCloseCallback] = useState(null);
|
|
22
|
-
const openBottomSheet = useCallback((newContent, size, onClose, snapPoints) => {
|
|
23
|
-
setContent(newContent);
|
|
24
|
-
setSize(size);
|
|
25
|
-
setOnCloseCallback(() => onClose);
|
|
26
|
-
setIsOpen(true);
|
|
27
|
-
if (snapPoints) {
|
|
28
|
-
setSnapPoints(snapPoints);
|
|
29
|
-
}
|
|
30
|
-
}, []);
|
|
31
|
-
const closeBottomSheet = useCallback(() => {
|
|
32
|
-
sheetRef.current?.close();
|
|
33
|
-
setIsOpen(false);
|
|
34
|
-
}, []);
|
|
35
|
-
const renderBackdrop = useCallback(props => /*#__PURE__*/_jsx(BottomSheetBackdrop, {
|
|
36
|
-
...props,
|
|
37
|
-
disappearsOnIndex: -1,
|
|
38
|
-
appearsOnIndex: 0,
|
|
39
|
-
opacity: 0.5,
|
|
40
|
-
pressBehavior: "close",
|
|
41
|
-
style: [props.style, {
|
|
42
|
-
backgroundColor: "rgba(0,0,0,0.5)"
|
|
43
|
-
}]
|
|
44
|
-
}), []);
|
|
45
|
-
useEffect(() => {
|
|
46
|
-
if (isOpen && content) {
|
|
47
|
-
sheetRef.current?.snapToIndex(size === "small" ? 0 : 1);
|
|
48
|
-
} else {
|
|
49
|
-
sheetRef.current?.close();
|
|
50
|
-
}
|
|
51
|
-
}, [isOpen, content, size]);
|
|
52
|
-
return /*#__PURE__*/_jsxs(BottomSheetContext.Provider, {
|
|
53
|
-
value: {
|
|
54
|
-
openBottomSheet,
|
|
55
|
-
closeBottomSheet,
|
|
56
|
-
isOpen
|
|
57
|
-
},
|
|
58
|
-
children: [children, /*#__PURE__*/_jsx(BottomSheet, {
|
|
59
|
-
ref: sheetRef,
|
|
60
|
-
index: -1,
|
|
61
|
-
snapPoints: sp,
|
|
62
|
-
enablePanDownToClose: true,
|
|
63
|
-
backdropComponent: renderBackdrop,
|
|
64
|
-
android_keyboardInputMode: "adjustResize",
|
|
65
|
-
keyboardBlurBehavior: "restore",
|
|
66
|
-
keyboardBehavior: "extend",
|
|
67
|
-
enableDynamicSizing: false,
|
|
68
|
-
style: styles.bottomSheetContainer,
|
|
69
|
-
onClose: () => {
|
|
70
|
-
setIsOpen(false);
|
|
71
|
-
Keyboard.dismiss();
|
|
72
|
-
},
|
|
73
|
-
handleIndicatorStyle: {
|
|
74
|
-
backgroundColor: theme.onSurface
|
|
75
|
-
},
|
|
76
|
-
children: content
|
|
77
|
-
})]
|
|
78
|
-
});
|
|
79
|
-
};
|
|
80
|
-
const providerStyles = theme => StyleSheet.create({
|
|
81
|
-
bottomSheetContainer: {
|
|
82
|
-
backgroundColor: theme.surface,
|
|
83
|
-
// Ensure sheet background matches theme
|
|
84
|
-
borderTopLeftRadius: 20,
|
|
85
|
-
borderTopRightRadius: 20,
|
|
86
|
-
overflow: "hidden" // Important for rounded corners with content
|
|
87
|
-
},
|
|
88
|
-
headerContainer: {
|
|
89
|
-
padding: 16,
|
|
90
|
-
borderBottomWidth: 1,
|
|
91
|
-
borderBottomColor: theme.divider,
|
|
92
|
-
// Use theme color for divider
|
|
93
|
-
alignItems: "center"
|
|
94
|
-
},
|
|
95
|
-
headerTitle: {
|
|
96
|
-
fontSize: 18,
|
|
97
|
-
fontWeight: "bold",
|
|
98
|
-
color: theme.onSurface
|
|
99
|
-
},
|
|
100
|
-
contentContainer: {
|
|
101
|
-
flex: 1 // Ensure content can take up available space
|
|
102
|
-
}
|
|
103
|
-
});
|
|
104
|
-
//# sourceMappingURL=BottomSheetProvider.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["React","useState","useRef","useCallback","useMemo","useEffect","BottomSheet","BottomSheetBackdrop","BottomSheetContext","Keyboard","StyleSheet","useTheme","jsx","_jsx","jsxs","_jsxs","BottomSheetProvider","children","theme","styles","providerStyles","sheetRef","isOpen","setIsOpen","content","setContent","size","setSize","sp","setSnapPoints","onCloseCallback","setOnCloseCallback","openBottomSheet","newContent","onClose","snapPoints","closeBottomSheet","current","close","renderBackdrop","props","disappearsOnIndex","appearsOnIndex","opacity","pressBehavior","style","backgroundColor","snapToIndex","Provider","value","ref","index","enablePanDownToClose","backdropComponent","android_keyboardInputMode","keyboardBlurBehavior","keyboardBehavior","enableDynamicSizing","bottomSheetContainer","dismiss","handleIndicatorStyle","onSurface","create","surface","borderTopLeftRadius","borderTopRightRadius","overflow","headerContainer","padding","borderBottomWidth","borderBottomColor","divider","alignItems","headerTitle","fontSize","fontWeight","color","contentContainer","flex"],"sourceRoot":"..\\..\\..\\src","sources":["contexts/BottomSheetProvider.tsx"],"mappings":";;AAAA,OAAOA,KAAK,IACVC,QAAQ,EACRC,MAAM,EACNC,WAAW,EAEXC,OAAO,EACPC,SAAS,QACJ,OAAO;AACd,OAAOC,WAAW,IAChBC,mBAAmB,QAEd,sBAAsB;AAC7B,OAAOC,kBAAkB,MAAM,yBAAsB;AACrD,SAASC,QAAQ,EAAEC,UAAU,QAAQ,cAAc;AACnD,SAAoBC,QAAQ,QAA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OAAO,CAAC,CAAC;MACpB,CAAE;MACFC,oBAAoB,EAAE;QAAEd,eAAe,EAAE5B,KAAK,CAAC2C;MAAU,CAAE;MAAA5C,QAAA,EAE1DO;IAAO,CACG,CAAC;EAAA,CACa,CAAC;AAElC,CAAC;AAED,MAAMJ,cAAc,GAAIF,KAAgB,IACtCR,UAAU,CAACoD,MAAM,CAAC;EAChBJ,oBAAoB,EAAE;IACpBZ,eAAe,EAAE5B,KAAK,CAAC6C,OAAO;IAAE;IAChCC,mBAAmB,EAAE,EAAE;IACvBC,oBAAoB,EAAE,EAAE;IACxBC,QAAQ,EAAE,QAAQ,CAAE;EACtB,CAAC;EACDC,eAAe,EAAE;IACfC,OAAO,EAAE,EAAE;IACXC,iBAAiB,EAAE,CAAC;IACpBC,iBAAiB,EAAEpD,KAAK,CAACqD,OAAO;IAAE;IAClCC,UAAU,EAAE;EACd,CAAC;EACDC,WAAW,EAAE;IACXC,QAAQ,EAAE,EAAE;IACZC,UAAU,EAAE,MAAM;IAClBC,KAAK,EAAE1D,KAAK,CAAC2C;EACf,CAAC;EACDgB,gBAAgB,EAAE;IAChBC,IAAI,EAAE,CAAC,CAAE;EACX;AACF,CAAC,CAAC","ignoreList":[]}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { ReactNode } from "react";
|
|
2
|
-
interface BottomSheetContextProps {
|
|
3
|
-
openBottomSheet: (content: ReactNode | (() => ReactNode), size: "small" | "large", onClose?: () => void, snapPoints?: string[]) => void;
|
|
4
|
-
closeBottomSheet: () => void;
|
|
5
|
-
isOpen: boolean;
|
|
6
|
-
}
|
|
7
|
-
declare const BottomSheetContext: import("react").Context<BottomSheetContextProps | undefined>;
|
|
8
|
-
export declare const useBottomSheet: () => BottomSheetContextProps;
|
|
9
|
-
export default BottomSheetContext;
|
|
10
|
-
//# sourceMappingURL=BottomSheetContext.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"BottomSheetContext.d.ts","sourceRoot":"","sources":["../../../../src/contexts/BottomSheetContext.tsx"],"names":[],"mappings":"AAAA,OAAO,EAA6B,SAAS,EAAE,MAAM,OAAO,CAAC;AAE7D,UAAU,uBAAuB;IAC/B,eAAe,EAAE,CACf,OAAO,EAAE,SAAS,GAAG,CAAC,MAAM,SAAS,CAAC,EACtC,IAAI,EAAE,OAAO,GAAG,OAAO,EACvB,OAAO,CAAC,EAAE,MAAM,IAAI,EACpB,UAAU,CAAC,EAAE,MAAM,EAAE,KAClB,IAAI,CAAC;IACV,gBAAgB,EAAE,MAAM,IAAI,CAAC;IAC7B,MAAM,EAAE,OAAO,CAAC;CACjB;AAED,QAAA,MAAM,kBAAkB,8DAEvB,CAAC;AAEF,eAAO,MAAM,cAAc,+BAQ1B,CAAC;AAEF,eAAe,kBAAkB,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"BottomSheetProvider.d.ts","sourceRoot":"","sources":["../../../../src/contexts/BottomSheetProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAIZ,SAAS,EAGV,MAAM,OAAO,CAAC;AASf,UAAU,wBAAwB;IAChC,QAAQ,EAAE,SAAS,CAAC;CACrB;AAED,eAAO,MAAM,mBAAmB,EAAE,KAAK,CAAC,EAAE,CAAC,wBAAwB,CA2FlE,CAAC"}
|