@momo-kits/foundation 0.92.27 → 0.92.28
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/Application/BottomSheet.tsx +25 -21
- package/Application/types.ts +1 -0
- package/package.json +1 -1
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import React, {
|
|
1
|
+
import React, {useRef, useEffect, useCallback, useContext} from 'react';
|
|
2
2
|
import {
|
|
3
3
|
Animated,
|
|
4
4
|
Dimensions,
|
|
5
5
|
KeyboardAvoidingView,
|
|
6
|
-
Modal,
|
|
7
6
|
PanResponder,
|
|
8
7
|
Platform,
|
|
9
8
|
StyleSheet,
|
|
10
9
|
TouchableOpacity,
|
|
11
10
|
View,
|
|
11
|
+
Modal,
|
|
12
12
|
} from 'react-native';
|
|
13
|
+
import {useSafeAreaInsets} from 'react-native-safe-area-context';
|
|
13
14
|
import {ApplicationContext} from './index';
|
|
14
15
|
import {BottomSheetParams} from './types';
|
|
15
|
-
import {useSafeAreaInsets} from 'react-native-safe-area-context';
|
|
16
16
|
import {Colors, Radius, Spacing, Styles} from '../Consts';
|
|
17
17
|
import {Text} from '../Text';
|
|
18
18
|
import {Icon} from '../Icon';
|
|
@@ -24,6 +24,7 @@ const BottomSheet: React.FC<BottomSheetParams> = props => {
|
|
|
24
24
|
const {
|
|
25
25
|
screen: Screen,
|
|
26
26
|
options,
|
|
27
|
+
useNativeModal = false,
|
|
27
28
|
surface,
|
|
28
29
|
barrierDismissible = false,
|
|
29
30
|
draggable = true,
|
|
@@ -36,6 +37,7 @@ const BottomSheet: React.FC<BottomSheetParams> = props => {
|
|
|
36
37
|
x: 0,
|
|
37
38
|
})
|
|
38
39
|
).current;
|
|
40
|
+
|
|
39
41
|
const panResponder = useRef(
|
|
40
42
|
PanResponder.create({
|
|
41
43
|
onStartShouldSetPanResponder: () => draggable,
|
|
@@ -61,7 +63,10 @@ const BottomSheet: React.FC<BottomSheetParams> = props => {
|
|
|
61
63
|
},
|
|
62
64
|
})
|
|
63
65
|
).current;
|
|
64
|
-
|
|
66
|
+
let Container: any = View;
|
|
67
|
+
if (useNativeModal) {
|
|
68
|
+
Container = Modal;
|
|
69
|
+
}
|
|
65
70
|
let backgroundColor = theme.colors.background.default;
|
|
66
71
|
if (surface) {
|
|
67
72
|
backgroundColor = theme.colors.background.surface;
|
|
@@ -74,7 +79,7 @@ const BottomSheet: React.FC<BottomSheetParams> = props => {
|
|
|
74
79
|
Animated.timing(pan, {
|
|
75
80
|
toValue: {x: 0, y: 0},
|
|
76
81
|
useNativeDriver: false,
|
|
77
|
-
duration:
|
|
82
|
+
duration: 150,
|
|
78
83
|
}).start();
|
|
79
84
|
return () => {
|
|
80
85
|
props.route.params?.onDismiss?.();
|
|
@@ -88,18 +93,20 @@ const BottomSheet: React.FC<BottomSheetParams> = props => {
|
|
|
88
93
|
if (barrierDismissible && !force) {
|
|
89
94
|
return;
|
|
90
95
|
}
|
|
96
|
+
setTimeout(() => {
|
|
97
|
+
callback?.();
|
|
98
|
+
}, 300);
|
|
91
99
|
Animated.timing(pan, {
|
|
92
100
|
toValue: {x: 0, y: heightDevice},
|
|
93
101
|
useNativeDriver: false,
|
|
94
102
|
duration: 200,
|
|
95
103
|
}).start(() => {
|
|
96
104
|
navigator?.pop();
|
|
97
|
-
callback?.();
|
|
98
105
|
});
|
|
99
106
|
};
|
|
100
107
|
|
|
101
108
|
/**
|
|
102
|
-
*
|
|
109
|
+
* on request close
|
|
103
110
|
*/
|
|
104
111
|
const onRequestClose = useCallback((callback?: () => void) => {
|
|
105
112
|
onDismiss(true, callback);
|
|
@@ -146,7 +153,11 @@ const BottomSheet: React.FC<BottomSheetParams> = props => {
|
|
|
146
153
|
}, []);
|
|
147
154
|
|
|
148
155
|
return (
|
|
149
|
-
<
|
|
156
|
+
<Container
|
|
157
|
+
transparent
|
|
158
|
+
visible={true}
|
|
159
|
+
onRequestClose={() => onDismiss()}
|
|
160
|
+
style={styles.overlay}>
|
|
150
161
|
<KeyboardAvoidingView
|
|
151
162
|
behavior={Platform.OS === 'ios' ? 'padding' : 'height'}
|
|
152
163
|
keyboardVerticalOffset={keyboardVerticalOffset ?? -20}
|
|
@@ -170,23 +181,14 @@ const BottomSheet: React.FC<BottomSheetParams> = props => {
|
|
|
170
181
|
</View>
|
|
171
182
|
</Animated.View>
|
|
172
183
|
</KeyboardAvoidingView>
|
|
173
|
-
</
|
|
184
|
+
</Container>
|
|
174
185
|
);
|
|
175
186
|
};
|
|
176
187
|
|
|
177
|
-
export default BottomSheet;
|
|
178
|
-
|
|
179
188
|
const styles = StyleSheet.create({
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
overflow: 'hidden',
|
|
184
|
-
borderTopLeftRadius: Radius.M,
|
|
185
|
-
borderTopRightRadius: Radius.M,
|
|
186
|
-
},
|
|
187
|
-
draggableContainer: {
|
|
188
|
-
width: '100%',
|
|
189
|
-
alignItems: 'center',
|
|
189
|
+
overlay: {
|
|
190
|
+
...StyleSheet.absoluteFillObject,
|
|
191
|
+
justifyContent: 'flex-end',
|
|
190
192
|
},
|
|
191
193
|
indicator: {
|
|
192
194
|
width: 40,
|
|
@@ -210,3 +212,5 @@ const styles = StyleSheet.create({
|
|
|
210
212
|
marginHorizontal: Spacing.M,
|
|
211
213
|
},
|
|
212
214
|
});
|
|
215
|
+
|
|
216
|
+
export default BottomSheet;
|
package/Application/types.ts
CHANGED