@momo-kits/foundation 0.92.26-beta.4 → 0.92.26-beta.6
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 +31 -15
- package/package.json +1 -1
|
@@ -1,17 +1,18 @@
|
|
|
1
|
-
import React, {
|
|
1
|
+
import React, {useCallback, useContext, useEffect, useRef} from 'react';
|
|
2
2
|
import {
|
|
3
3
|
Animated,
|
|
4
4
|
Dimensions,
|
|
5
5
|
KeyboardAvoidingView,
|
|
6
|
+
Modal,
|
|
6
7
|
PanResponder,
|
|
7
8
|
Platform,
|
|
8
9
|
StyleSheet,
|
|
9
10
|
TouchableOpacity,
|
|
10
11
|
View,
|
|
11
12
|
} from 'react-native';
|
|
12
|
-
import {useSafeAreaInsets} from 'react-native-safe-area-context';
|
|
13
13
|
import {ApplicationContext} from './index';
|
|
14
14
|
import {BottomSheetParams} from './types';
|
|
15
|
+
import {useSafeAreaInsets} from 'react-native-safe-area-context';
|
|
15
16
|
import {Colors, Radius, Spacing, Styles} from '../Consts';
|
|
16
17
|
import {Text} from '../Text';
|
|
17
18
|
import {Icon} from '../Icon';
|
|
@@ -66,17 +67,23 @@ const BottomSheet: React.FC<BottomSheetParams> = props => {
|
|
|
66
67
|
backgroundColor = theme.colors.background.surface;
|
|
67
68
|
}
|
|
68
69
|
|
|
70
|
+
/**
|
|
71
|
+
* emit dismiss event
|
|
72
|
+
*/
|
|
69
73
|
useEffect(() => {
|
|
70
74
|
Animated.timing(pan, {
|
|
71
75
|
toValue: {x: 0, y: 0},
|
|
72
76
|
useNativeDriver: false,
|
|
73
|
-
duration:
|
|
77
|
+
duration: 200,
|
|
74
78
|
}).start();
|
|
75
79
|
return () => {
|
|
76
80
|
props.route.params?.onDismiss?.();
|
|
77
81
|
};
|
|
78
82
|
}, []);
|
|
79
83
|
|
|
84
|
+
/**
|
|
85
|
+
* handler dismiss
|
|
86
|
+
*/
|
|
80
87
|
const onDismiss = (force = false, callback?: () => void) => {
|
|
81
88
|
if (barrierDismissible && !force) {
|
|
82
89
|
return;
|
|
@@ -93,10 +100,16 @@ const BottomSheet: React.FC<BottomSheetParams> = props => {
|
|
|
93
100
|
});
|
|
94
101
|
};
|
|
95
102
|
|
|
103
|
+
/**
|
|
104
|
+
* manual close
|
|
105
|
+
*/
|
|
96
106
|
const requestClose = useCallback((callback?: () => void) => {
|
|
97
107
|
onDismiss(true, callback);
|
|
98
108
|
}, []);
|
|
99
109
|
|
|
110
|
+
/**
|
|
111
|
+
* render header
|
|
112
|
+
*/
|
|
100
113
|
const renderHeader = useCallback(() => {
|
|
101
114
|
return (
|
|
102
115
|
<View
|
|
@@ -135,7 +148,7 @@ const BottomSheet: React.FC<BottomSheetParams> = props => {
|
|
|
135
148
|
}, []);
|
|
136
149
|
|
|
137
150
|
return (
|
|
138
|
-
<
|
|
151
|
+
<Modal transparent visible={true} onRequestClose={() => onDismiss()}>
|
|
139
152
|
<KeyboardAvoidingView
|
|
140
153
|
behavior={Platform.OS === 'ios' ? 'padding' : 'height'}
|
|
141
154
|
keyboardVerticalOffset={keyboardVerticalOffset ?? -20}
|
|
@@ -148,25 +161,30 @@ const BottomSheet: React.FC<BottomSheetParams> = props => {
|
|
|
148
161
|
<Animated.View style={{transform: pan.getTranslateTransform()}}>
|
|
149
162
|
{renderHeader()}
|
|
150
163
|
<View style={{backgroundColor: backgroundColor}}>
|
|
151
|
-
<Screen
|
|
152
|
-
{...props}
|
|
153
|
-
{...props.route.params}
|
|
154
|
-
// requestClose={requestClose}
|
|
155
|
-
/>
|
|
164
|
+
<Screen {...props} {...props.route.params} />
|
|
156
165
|
{useBottomInset && (
|
|
157
166
|
<View style={{height: Math.min(insets.bottom, 21)}} />
|
|
158
167
|
)}
|
|
159
168
|
</View>
|
|
160
169
|
</Animated.View>
|
|
161
170
|
</KeyboardAvoidingView>
|
|
162
|
-
</
|
|
171
|
+
</Modal>
|
|
163
172
|
);
|
|
164
173
|
};
|
|
165
174
|
|
|
175
|
+
export default BottomSheet;
|
|
176
|
+
|
|
166
177
|
const styles = StyleSheet.create({
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
178
|
+
container: {
|
|
179
|
+
width: '100%',
|
|
180
|
+
height: 0,
|
|
181
|
+
overflow: 'hidden',
|
|
182
|
+
borderTopLeftRadius: Radius.M,
|
|
183
|
+
borderTopRightRadius: Radius.M,
|
|
184
|
+
},
|
|
185
|
+
draggableContainer: {
|
|
186
|
+
width: '100%',
|
|
187
|
+
alignItems: 'center',
|
|
170
188
|
},
|
|
171
189
|
indicator: {
|
|
172
190
|
width: 40,
|
|
@@ -190,5 +208,3 @@ const styles = StyleSheet.create({
|
|
|
190
208
|
marginHorizontal: Spacing.M,
|
|
191
209
|
},
|
|
192
210
|
});
|
|
193
|
-
|
|
194
|
-
export default BottomSheet;
|