@momo-kits/foundation 0.92.26 → 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.
@@ -1,30 +1,30 @@
1
- import React, {useCallback, useContext, useEffect, useRef} from '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';
19
19
 
20
20
  const BottomSheet: React.FC<BottomSheetParams> = props => {
21
21
  const {theme, navigator} = useContext(ApplicationContext);
22
- const closed = useRef(false);
23
22
  const heightDevice = Dimensions.get('screen').height;
24
23
  const insets = useSafeAreaInsets();
25
24
  const {
26
25
  screen: Screen,
27
26
  options,
27
+ useNativeModal = false,
28
28
  surface,
29
29
  barrierDismissible = false,
30
30
  draggable = true,
@@ -37,6 +37,7 @@ const BottomSheet: React.FC<BottomSheetParams> = props => {
37
37
  x: 0,
38
38
  })
39
39
  ).current;
40
+
40
41
  const panResponder = useRef(
41
42
  PanResponder.create({
42
43
  onStartShouldSetPanResponder: () => draggable,
@@ -62,7 +63,10 @@ const BottomSheet: React.FC<BottomSheetParams> = props => {
62
63
  },
63
64
  })
64
65
  ).current;
65
-
66
+ let Container: any = View;
67
+ if (useNativeModal) {
68
+ Container = Modal;
69
+ }
66
70
  let backgroundColor = theme.colors.background.default;
67
71
  if (surface) {
68
72
  backgroundColor = theme.colors.background.surface;
@@ -78,9 +82,6 @@ const BottomSheet: React.FC<BottomSheetParams> = props => {
78
82
  duration: 150,
79
83
  }).start();
80
84
  return () => {
81
- if (!closed.current) {
82
- navigator?.pop();
83
- }
84
85
  props.route.params?.onDismiss?.();
85
86
  };
86
87
  }, []);
@@ -93,21 +94,21 @@ const BottomSheet: React.FC<BottomSheetParams> = props => {
93
94
  return;
94
95
  }
95
96
  setTimeout(() => {
96
- closed.current = true;
97
- navigator?.pop();
98
97
  callback?.();
99
- }, 350);
98
+ }, 300);
100
99
  Animated.timing(pan, {
101
100
  toValue: {x: 0, y: heightDevice},
102
101
  useNativeDriver: false,
103
102
  duration: 200,
104
- }).start();
103
+ }).start(() => {
104
+ navigator?.pop();
105
+ });
105
106
  };
106
107
 
107
108
  /**
108
- * manual close
109
+ * on request close
109
110
  */
110
- const requestClose = useCallback((callback?: () => void) => {
111
+ const onRequestClose = useCallback((callback?: () => void) => {
111
112
  onDismiss(true, callback);
112
113
  }, []);
113
114
 
@@ -152,7 +153,11 @@ const BottomSheet: React.FC<BottomSheetParams> = props => {
152
153
  }, []);
153
154
 
154
155
  return (
155
- <Modal transparent visible={true} onRequestClose={() => onDismiss()}>
156
+ <Container
157
+ transparent
158
+ visible={true}
159
+ onRequestClose={() => onDismiss()}
160
+ style={styles.overlay}>
156
161
  <KeyboardAvoidingView
157
162
  behavior={Platform.OS === 'ios' ? 'padding' : 'height'}
158
163
  keyboardVerticalOffset={keyboardVerticalOffset ?? -20}
@@ -168,7 +173,7 @@ const BottomSheet: React.FC<BottomSheetParams> = props => {
168
173
  <Screen
169
174
  {...props}
170
175
  {...props.route.params}
171
- requestClose={requestClose}
176
+ onRequestClose={onRequestClose}
172
177
  />
173
178
  {useBottomInset && (
174
179
  <View style={{height: Math.min(insets.bottom, 21)}} />
@@ -176,23 +181,14 @@ const BottomSheet: React.FC<BottomSheetParams> = props => {
176
181
  </View>
177
182
  </Animated.View>
178
183
  </KeyboardAvoidingView>
179
- </Modal>
184
+ </Container>
180
185
  );
181
186
  };
182
187
 
183
- export default BottomSheet;
184
-
185
188
  const styles = StyleSheet.create({
186
- container: {
187
- width: '100%',
188
- height: 0,
189
- overflow: 'hidden',
190
- borderTopLeftRadius: Radius.M,
191
- borderTopRightRadius: Radius.M,
192
- },
193
- draggableContainer: {
194
- width: '100%',
195
- alignItems: 'center',
189
+ overlay: {
190
+ ...StyleSheet.absoluteFillObject,
191
+ justifyContent: 'flex-end',
196
192
  },
197
193
  indicator: {
198
194
  width: 40,
@@ -216,3 +212,5 @@ const styles = StyleSheet.create({
216
212
  marginHorizontal: Spacing.M,
217
213
  },
218
214
  });
215
+
216
+ export default BottomSheet;
@@ -115,6 +115,7 @@ export type BottomSheetParams = {
115
115
  title: string;
116
116
  surface?: boolean;
117
117
  };
118
+ useNativeModal?: boolean;
118
119
  surface?: boolean;
119
120
  onDismiss?: (type?: string) => void;
120
121
  barrierDismissible?: boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@momo-kits/foundation",
3
- "version": "0.92.26",
3
+ "version": "0.92.28",
4
4
  "description": "React Native Component Kits",
5
5
  "main": "index.ts",
6
6
  "scripts": {},