@momo-kits/foundation 0.81.1-optimize.16 → 0.81.1-optimize.18

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,4 +1,4 @@
1
- import React, {useContext, useEffect, useRef, useState} from 'react';
1
+ import React, {useCallback, useContext, useEffect, useRef} from 'react';
2
2
  import {
3
3
  Animated,
4
4
  Dimensions,
@@ -26,19 +26,20 @@ const BottomSheet: React.FC<BottomSheetParams> = props => {
26
26
  options,
27
27
  surface,
28
28
  barrierDismissible = false,
29
- snapPoint = 'content',
30
29
  draggable = true,
31
- dragOnContent = false,
32
30
  useBottomInset = true,
33
31
  }: BottomSheetParams = props.route.params;
34
- const [modalVisible, setModalVisible] = useState(false);
35
- const animatedHeight = useRef(new Animated.Value(0)).current;
36
- const pan = useRef(new Animated.ValueXY()).current;
32
+ const pan = useRef(
33
+ new Animated.ValueXY({
34
+ y: heightDevice,
35
+ x: 0,
36
+ }),
37
+ ).current;
37
38
  const panResponder = useRef(
38
39
  PanResponder.create({
39
40
  onStartShouldSetPanResponder: () => draggable,
40
41
  onMoveShouldSetPanResponder: (_, gestureState) => {
41
- return draggable && dragOnContent && gestureState.dy > 0;
42
+ return draggable && gestureState.dy > 0;
42
43
  },
43
44
  onPanResponderMove: (e, gestureState) => {
44
45
  gestureState.dy > 0 &&
@@ -59,44 +60,26 @@ const BottomSheet: React.FC<BottomSheetParams> = props => {
59
60
  },
60
61
  }),
61
62
  ).current;
62
- const [estimate, setEstimate] = useState(0.9);
63
- const timeoutMount = useRef<any>();
64
63
 
65
64
  let backgroundColor = theme.colors.background.default;
66
65
  if (surface) {
67
66
  backgroundColor = theme.colors.background.surface;
68
67
  }
69
68
 
70
- /**
71
- * handle open & emit dismiss event
72
- */
73
- useEffect(() => {
74
- clearTimeout(timeoutMount.current);
75
- timeoutMount.current = setTimeout(() => {
76
- const mapSnapPoint: any = {
77
- '30%': 0.3,
78
- '50%': 0.5,
79
- '70%': 0.7,
80
- '90%': 0.9,
81
- };
82
- const point = mapSnapPoint[snapPoint] ?? estimate;
83
- setModalVisible(true);
84
- Animated.timing(animatedHeight, {
85
- useNativeDriver: false,
86
- toValue: heightDevice * point,
87
- duration: 150,
88
- }).start();
89
- }, 50);
90
- }, [estimate]);
91
-
92
69
  /**
93
70
  * emit dismiss event
94
71
  */
95
72
  useEffect(() => {
73
+ Animated.timing(pan, {
74
+ toValue: {x: 0, y: 0},
75
+ useNativeDriver: false,
76
+ duration: 150,
77
+ }).start();
96
78
  return () => {
97
79
  props.route.params?.onDismiss?.();
98
80
  };
99
81
  }, []);
82
+
100
83
  /**
101
84
  * handler dismiss
102
85
  */
@@ -104,94 +87,74 @@ const BottomSheet: React.FC<BottomSheetParams> = props => {
104
87
  if (barrierDismissible && !force) {
105
88
  return;
106
89
  }
107
- Animated.timing(animatedHeight, {
90
+ Animated.timing(pan, {
91
+ toValue: {x: 0, y: heightDevice},
108
92
  useNativeDriver: false,
109
- toValue: 0,
110
- duration: 200,
93
+ duration: 100,
111
94
  }).start(() => {
112
- pan.setValue({x: 0, y: 0});
113
95
  navigator?.pop();
114
96
  });
115
97
  };
116
98
 
117
- return (
118
- <>
119
- <Modal
120
- transparent
121
- visible={modalVisible}
122
- onRequestClose={() => onDismiss()}>
123
- <KeyboardAvoidingView
124
- behavior={Platform.OS === 'ios' ? 'padding' : 'height'}
125
- keyboardVerticalOffset={-20}
126
- style={Styles.flex}>
99
+ const renderHeader = useCallback(() => {
100
+ return (
101
+ <View
102
+ style={{
103
+ backgroundColor,
104
+ borderTopLeftRadius: Radius.M,
105
+ borderTopRightRadius: Radius.M,
106
+ }}
107
+ {...panResponder.panHandlers}>
108
+ <View style={{height: 16}}>
109
+ <View style={styles.indicator} />
110
+ </View>
111
+ <View
112
+ style={[
113
+ styles.header,
114
+ surface && {
115
+ borderBottomColor: theme.colors.border.default,
116
+ borderBottomWidth: 1,
117
+ },
118
+ ]}>
119
+ <View style={styles.iconButton} />
120
+ <Text
121
+ style={[Styles.flex, {textAlign: 'center'}]}
122
+ numberOfLines={1}
123
+ typography="header_default_bold">
124
+ {options.title ?? ''}
125
+ </Text>
127
126
  <TouchableOpacity
128
- style={Styles.flex}
129
- activeOpacity={1}
130
- onPress={() => onDismiss()}
131
- />
132
- <Animated.View
133
- {...(dragOnContent && panResponder.panHandlers)}
134
- style={[
135
- styles.container,
136
- {transform: pan.getTranslateTransform()},
137
- {
138
- height: animatedHeight,
139
- backgroundColor,
140
- },
141
- ]}>
142
- {draggable && (
143
- <View
144
- {...(!dragOnContent && panResponder.panHandlers)}
145
- style={styles.draggableContainer}>
146
- <View style={{height: 16}}>
147
- <View style={styles.indicator} />
148
- </View>
149
- <View
150
- style={[
151
- styles.header,
152
- surface && {
153
- borderBottomColor: theme.colors.border.default,
154
- borderBottomWidth: 1,
155
- },
156
- ]}>
157
- <View style={styles.iconButton} />
158
- <Text
159
- style={[Styles.flex, {textAlign: 'center'}]}
160
- numberOfLines={1}
161
- typography="header_default_bold">
162
- {options.title ?? ''}
163
- </Text>
164
- <TouchableOpacity
165
- style={styles.iconButton}
166
- onPress={() => onDismiss(true)}>
167
- <Icon source="navigation_close" />
168
- </TouchableOpacity>
169
- </View>
170
- </View>
171
- )}
127
+ style={styles.iconButton}
128
+ onPress={() => onDismiss(true)}>
129
+ <Icon source="navigation_close" />
130
+ </TouchableOpacity>
131
+ </View>
132
+ </View>
133
+ );
134
+ }, []);
135
+
136
+ return (
137
+ <Modal transparent visible={true} onRequestClose={() => onDismiss()}>
138
+ <KeyboardAvoidingView
139
+ behavior={Platform.OS === 'ios' ? 'padding' : 'height'}
140
+ keyboardVerticalOffset={-20}
141
+ style={[Styles.flex, {justifyContent: 'flex-end'}]}>
142
+ <TouchableOpacity
143
+ style={Styles.flex}
144
+ activeOpacity={1}
145
+ onPress={() => onDismiss()}
146
+ />
147
+ <Animated.View style={{transform: pan.getTranslateTransform()}}>
148
+ {renderHeader()}
149
+ <View style={{backgroundColor: backgroundColor}}>
172
150
  <Screen {...props} {...props.route.params} />
173
151
  {useBottomInset && (
174
152
  <View style={{height: Math.min(insets.bottom, 21)}} />
175
153
  )}
176
- </Animated.View>
177
- </KeyboardAvoidingView>
178
- </Modal>
179
- {snapPoint == 'content' && (
180
- <View
181
- style={styles.estimate}
182
- onLayout={e => {
183
- const current = (e.nativeEvent.layout.height + 72) / heightDevice;
184
- if (current != estimate) {
185
- setEstimate(current);
186
- }
187
- }}>
188
- <Screen {...props} {...props.route.params} />
189
- {useBottomInset && (
190
- <View style={{height: Math.min(insets.bottom, 21)}} />
191
- )}
192
- </View>
193
- )}
194
- </>
154
+ </View>
155
+ </Animated.View>
156
+ </KeyboardAvoidingView>
157
+ </Modal>
195
158
  );
196
159
  };
197
160
  export default BottomSheet;
@@ -114,12 +114,10 @@ export type BottomSheetParams = {
114
114
  title: string;
115
115
  surface?: boolean;
116
116
  };
117
- snapPoint?: '30%' | '50%' | '70%' | '90%' | 'content';
118
117
  surface?: boolean;
119
118
  onDismiss?: (type?: string) => void;
120
119
  barrierDismissible?: boolean;
121
120
  draggable?: boolean;
122
- dragOnContent?: boolean;
123
121
  useBottomInset?: boolean;
124
122
  };
125
123
 
package/Layout/Screen.tsx CHANGED
@@ -235,7 +235,7 @@ const Screen = forwardRef(
235
235
  if (scrollable) {
236
236
  Component = Animated.ScrollView;
237
237
  handleScroll = scrollViewProps?.onScroll;
238
- if (animatedHeader || floatingButtonProps) {
238
+ if (animatedHeader || floatingButtonProps?.icon) {
239
239
  handleScroll = Animated.event(
240
240
  [
241
241
  {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@momo-kits/foundation",
3
- "version": "0.81.1-optimize.16",
3
+ "version": "0.81.1-optimize.18",
4
4
  "description": "React Native Component Kits",
5
5
  "main": "index.ts",
6
6
  "scripts": {},