@momo-kits/foundation 0.115.2-beta.13 → 0.115.3-beta.10

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,23 +1,32 @@
1
- import React, {useCallback, useContext, useEffect, useRef} from 'react';
1
+ import React, {
2
+ useCallback,
3
+ useContext,
4
+ useEffect,
5
+ useRef,
6
+ useState,
7
+ } from 'react';
2
8
  import {
3
9
  Dimensions,
10
+ Keyboard,
4
11
  KeyboardAvoidingView,
12
+ LayoutAnimation,
5
13
  Modal,
6
14
  PanResponder,
7
15
  Platform,
8
16
  Pressable,
17
+ ScrollView,
9
18
  StyleSheet,
10
19
  TouchableOpacity,
11
20
  View,
12
21
  } from 'react-native';
13
22
  import {useSafeAreaInsets} from 'react-native-safe-area-context';
23
+ import Animated, {Easing, Extrapolate} from 'react-native-reanimated';
24
+ import {useHeaderHeight} from '@react-navigation/stack';
14
25
  import {ApplicationContext} from './index';
15
26
  import {BottomSheetParams} from './types';
16
27
  import {Colors, Radius, Spacing, Styles} from '../Consts';
17
28
  import {Text} from '../Text';
18
29
  import {Icon} from '../Icon';
19
- import {useHeaderHeight} from '@react-navigation/stack';
20
- import Animated, {Easing, Extrapolate} from 'react-native-reanimated';
21
30
 
22
31
  const BottomSheet: React.FC<BottomSheetParams> = props => {
23
32
  const {theme, navigator} = useContext(ApplicationContext);
@@ -25,6 +34,8 @@ const BottomSheet: React.FC<BottomSheetParams> = props => {
25
34
  const action = useRef<undefined | string>();
26
35
  const insets = useSafeAreaInsets();
27
36
  const heightHeader = useHeaderHeight();
37
+ const [keyboardHeight, setKeyboardHeight] = useState(0);
38
+ const [contentHeight, setContentHeight] = useState(0);
28
39
  const keyboardOffset = heightHeader - Math.min(insets.bottom, 21);
29
40
 
30
41
  const {
@@ -36,6 +47,7 @@ const BottomSheet: React.FC<BottomSheetParams> = props => {
36
47
  draggable = true,
37
48
  useBottomInset = true,
38
49
  useKeyboardAvoidingView = true,
50
+ useScrollOverflow = false,
39
51
  keyboardVerticalOffset,
40
52
  }: BottomSheetParams = props.route.params;
41
53
 
@@ -86,14 +98,39 @@ const BottomSheet: React.FC<BottomSheetParams> = props => {
86
98
  ).current;
87
99
 
88
100
  let Container: any = View;
101
+ let Content: any = View;
89
102
  if (useNativeModal) {
90
103
  Container = Modal;
91
104
  }
105
+ if (useScrollOverflow) {
106
+ Content = ScrollView;
107
+ }
92
108
  let backgroundColor = theme.colors.background.default;
93
109
  if (surface) {
94
110
  backgroundColor = theme.colors.background.surface;
95
111
  }
96
112
 
113
+ const maxContentSize = heightDevice - 52 - keyboardHeight;
114
+
115
+ useEffect(() => {
116
+ const onKeyboardShow = (e: any) => {
117
+ LayoutAnimation.configureNext(LayoutAnimation.Presets.easeInEaseOut);
118
+ setKeyboardHeight(e.endCoordinates.height);
119
+ };
120
+ const onKeyboardHide = () => {
121
+ LayoutAnimation.configureNext(LayoutAnimation.Presets.easeInEaseOut);
122
+ setKeyboardHeight(0);
123
+ };
124
+
125
+ const showSub = Keyboard.addListener('keyboardWillShow', onKeyboardShow);
126
+ const hideSub = Keyboard.addListener('keyboardWillHide', onKeyboardHide);
127
+
128
+ return () => {
129
+ showSub.remove();
130
+ hideSub.remove();
131
+ };
132
+ }, []);
133
+
97
134
  /**
98
135
  * emit dismiss event
99
136
  */
@@ -105,6 +142,17 @@ const BottomSheet: React.FC<BottomSheetParams> = props => {
105
142
  };
106
143
  }, []);
107
144
 
145
+ /**
146
+ * handle content bottom sheet change
147
+ * @param width
148
+ * @param height
149
+ */
150
+ const handleContentSizeChange = (width: number, height: number) => {
151
+ if (contentHeight !== height) {
152
+ setContentHeight(height);
153
+ }
154
+ };
155
+
108
156
  /**
109
157
  * handler dismiss
110
158
  */
@@ -216,9 +264,13 @@ const BottomSheet: React.FC<BottomSheetParams> = props => {
216
264
  <Animated.View
217
265
  style={{
218
266
  transform: [{translateY}],
267
+ maxHeight: maxContentSize,
219
268
  }}>
220
269
  {renderHeader()}
221
- <View style={{backgroundColor: backgroundColor}}>
270
+ <Content
271
+ scrollEnabled={contentHeight + 20 > maxContentSize}
272
+ style={{backgroundColor: backgroundColor}}
273
+ onContentSizeChange={handleContentSizeChange}>
222
274
  <Screen
223
275
  {...props}
224
276
  {...props.route.params}
@@ -227,7 +279,7 @@ const BottomSheet: React.FC<BottomSheetParams> = props => {
227
279
  {useBottomInset && (
228
280
  <View style={{height: Math.min(insets.bottom, 21)}} />
229
281
  )}
230
- </View>
282
+ </Content>
231
283
  </Animated.View>
232
284
  </KeyboardAvoidingView>
233
285
  </Container>
@@ -50,6 +50,7 @@ const HeaderRight: React.FC<any> = props => {
50
50
  const HeaderToolkitAction: React.FC<any> = ({
51
51
  tintColor,
52
52
  preventClose,
53
+ useSystemTools = true,
53
54
  useShortcut = false,
54
55
  useMore = false,
55
56
  tools = [],
@@ -198,6 +199,7 @@ const HeaderToolkitAction: React.FC<any> = ({
198
199
  navigator?.maxApi?.dispatchFunction?.(
199
200
  'showTools',
200
201
  {
202
+ useSystemTools,
201
203
  tools,
202
204
  context,
203
205
  },
@@ -98,6 +98,7 @@ export type Tool = {
98
98
  name: {vi: string; en: string};
99
99
  key: string;
100
100
  showBadge?: boolean;
101
+ showRightIcon?: boolean;
101
102
  onPress: () => void;
102
103
  };
103
104
 
@@ -150,6 +151,7 @@ export type BottomSheetParams = {
150
151
  useBottomInset?: boolean;
151
152
  useKeyboardAvoidingView?: boolean;
152
153
  keyboardVerticalOffset?: number;
154
+ useScrollOverflow?: boolean;
153
155
  };
154
156
 
155
157
  export interface NavigationButtonProps extends TouchableOpacityProps {
@@ -97,10 +97,10 @@ const InputMoney = forwardRef(
97
97
  };
98
98
 
99
99
  const onClearText = () => {
100
+ inputRef?.current?.clear();
100
101
  setDisplayValue('');
101
102
  setNumericValue('');
102
103
  onChangeText?.('');
103
- inputRef?.current?.focus();
104
104
  };
105
105
 
106
106
  const _onChangeText = (text: string) => {
@@ -113,7 +113,8 @@ const InputMoney = forwardRef(
113
113
 
114
114
  if (text.length < lastDisplayValue.length) {
115
115
  const lastChar = lastDisplayValue.charAt(lastDisplayValue.length - 1);
116
- const isRemovingCurrency = lastDisplayValue.endsWith(currency) || lastChar === ' ';
116
+ const isRemovingCurrency =
117
+ lastDisplayValue.endsWith(currency) || lastChar === ' ';
117
118
  const isRemovingDot = lastChar === '.';
118
119
 
119
120
  if (isRemovingCurrency || isRemovingDot) {
@@ -237,7 +237,7 @@ const InputSearch: ForwardRefRenderFunction<InputRef, InputSearchProps> = (
237
237
  const renderTrailing = () => {
238
238
  return (
239
239
  <View style={Styles.row}>
240
- {focused && haveValue && (
240
+ {haveValue && (
241
241
  <TouchableOpacity
242
242
  style={styles.iconWrapper}
243
243
  onPress={onClearText}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@momo-kits/foundation",
3
- "version": "0.115.2-beta.13",
3
+ "version": "0.115.3-beta.10",
4
4
  "description": "React Native Component Kits",
5
5
  "main": "index.ts",
6
6
  "scripts": {},