@momo-kits/foundation 0.78.1 → 0.78.3

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,6 +1,12 @@
1
- import React, {useContext, useEffect, useRef} from 'react';
1
+ import React, {
2
+ useCallback,
3
+ useContext,
4
+ useEffect,
5
+ useMemo,
6
+ useRef,
7
+ useState,
8
+ } from 'react';
2
9
  import {
3
- Dimensions,
4
10
  KeyboardAvoidingView,
5
11
  Platform,
6
12
  Pressable,
@@ -85,11 +91,10 @@ const Modal: React.FC<ModalParams> = props => {
85
91
 
86
92
  const BottomSheet: React.FC<BottomSheetParams> = props => {
87
93
  const {theme, navigator} = useContext(ApplicationContext);
88
- const {height} = Dimensions.get('window');
89
94
  const {
90
95
  screen,
91
96
  options,
92
- snapPoints = [height * 0.5, height * 0.9],
97
+ useSnap = true,
93
98
  }: BottomSheetParams = props.route.params;
94
99
  const Component = useRef(screen).current;
95
100
  const navigation = new Navigation(props.navigation, theme);
@@ -100,9 +105,31 @@ const BottomSheet: React.FC<BottomSheetParams> = props => {
100
105
 
101
106
  delete params.screen;
102
107
 
108
+ const [contentHeight, setContentHeight] = useState(undefined);
109
+ const snapPoints = useMemo(() => {
110
+ if (useSnap) {
111
+ return ['50%', '90%'];
112
+ }
113
+ return [contentHeight ?? '50%'];
114
+ }, [contentHeight]);
115
+
103
116
  const bottomSheetRef = useRef<any>(null);
104
117
  const mountedRef = useRef(true);
105
118
 
119
+ let handleOnLayout;
120
+ if (!useSnap) {
121
+ handleOnLayout = useCallback(
122
+ ({
123
+ nativeEvent: {
124
+ layout: {height},
125
+ },
126
+ }) => {
127
+ setContentHeight(height);
128
+ },
129
+ [],
130
+ );
131
+ }
132
+
106
133
  let backgroundColor = theme.colors.background.default;
107
134
  if (options?.surface) {
108
135
  backgroundColor = theme.colors.background.surface;
@@ -127,7 +154,7 @@ const BottomSheet: React.FC<BottomSheetParams> = props => {
127
154
  <SafeAreaView style={Styles.flex}>
128
155
  <BottomSheetModal
129
156
  ref={bottomSheetRef}
130
- snapPoints={snapPoints?.map(item => item + 68)}
157
+ snapPoints={snapPoints}
131
158
  onDismiss={() => {
132
159
  if (mountedRef.current) {
133
160
  navigator?.pop();
@@ -135,7 +162,7 @@ const BottomSheet: React.FC<BottomSheetParams> = props => {
135
162
  }}
136
163
  handleComponent={null}
137
164
  backdropComponent={backdropComponent}>
138
- <View accessibilityLabel={'BottomSheet'}>
165
+ <View onLayout={handleOnLayout} accessibilityLabel={'BottomSheet'}>
139
166
  <View style={[styles.sheetContainer, {backgroundColor}]}>
140
167
  <View style={styles.indicatorContainer}>
141
168
  <View
@@ -1,4 +1,4 @@
1
- import {StackActions} from '@react-navigation/native';
1
+ import {CommonActions, StackActions} from '@react-navigation/native';
2
2
  import {
3
3
  BottomSheetParams,
4
4
  HeaderToolkitProps,
@@ -48,6 +48,21 @@ class Navigator {
48
48
  this.ref.current.dispatch(StackActions.popToTop());
49
49
  };
50
50
 
51
+ reset = (params: ScreenParams) => {
52
+ this.ref.current.dispatch(
53
+ CommonActions.reset({
54
+ index: 0,
55
+ routes: [
56
+ {
57
+ name: 'Stack',
58
+ key: `Stack_${new Date().getTime()}`,
59
+ params,
60
+ },
61
+ ],
62
+ }),
63
+ );
64
+ };
65
+
51
66
  requestApi = (func: any, args: any = [], callback: any) => {
52
67
  if (this.maxApi) {
53
68
  this.maxApi[func]?.(...args, callback);
@@ -56,6 +71,7 @@ class Navigator {
56
71
  instance?.miniAppApi?.dispatch?.(func, ...args, callback);
57
72
  }
58
73
  };
74
+
59
75
  getToolkit = async (): Promise<HeaderToolkitProps | undefined> => {
60
76
  return new Promise(resolve => {
61
77
  if (this.toolkitConfig) {
@@ -83,7 +83,7 @@ export type NavigationContainerProps = {
83
83
  options?: NavigationOptions;
84
84
  theme: Theme;
85
85
  maxApi?: any;
86
- localization: LocalizationObject;
86
+ localization?: LocalizationObject;
87
87
  };
88
88
 
89
89
  export type NavigationScreenProps = {
@@ -107,7 +107,7 @@ export interface ModalParams extends ScreenParams {
107
107
  export interface BottomSheetParams extends ScreenParams {
108
108
  [key: string]: any;
109
109
  onDismiss?: () => void;
110
- snapPoints?: ReadonlyArray<number>;
110
+ useSnap?: boolean;
111
111
  }
112
112
 
113
113
  export type NavigationButtonProps = {
package/Input/Input.tsx CHANGED
@@ -1,4 +1,4 @@
1
- import React, {FC, forwardRef, useContext, useRef, useState} from 'react';
1
+ import React, {forwardRef, useContext, useRef, useState} from 'react';
2
2
  import {
3
3
  NativeSyntheticEvent,
4
4
  TextInput,
@@ -14,7 +14,7 @@ import {Icon} from '../Icon';
14
14
  import {checkTyping} from './utils';
15
15
  import {Loader} from '../Loader';
16
16
 
17
- const Input: FC<InputProps> = forwardRef(
17
+ const Input = forwardRef(
18
18
  (
19
19
  {
20
20
  value,
@@ -34,7 +34,7 @@ const Input: FC<InputProps> = forwardRef(
34
34
  errorSpacing,
35
35
  loading,
36
36
  ...props
37
- },
37
+ }: InputProps,
38
38
  ref,
39
39
  ) => {
40
40
  const {theme} = useContext(ApplicationContext);
@@ -1,4 +1,4 @@
1
- import React, {FC, forwardRef, useContext, useRef, useState} from 'react';
1
+ import React, {forwardRef, useContext, useRef, useState} from 'react';
2
2
  import {
3
3
  NativeSyntheticEvent,
4
4
  TextInput,
@@ -13,7 +13,7 @@ import {InputMoneyProps} from './index';
13
13
  import {Icon} from '../Icon';
14
14
  import {formatMoneyToNumber, formatNumberToMoney} from './utils';
15
15
 
16
- const InputMoney: FC<InputMoneyProps> = forwardRef(
16
+ const InputMoney = forwardRef(
17
17
  (
18
18
  {
19
19
  onChangeText,
@@ -30,7 +30,7 @@ const InputMoney: FC<InputMoneyProps> = forwardRef(
30
30
  required,
31
31
  errorSpacing,
32
32
  ...props
33
- },
33
+ }: InputMoneyProps,
34
34
  ref,
35
35
  ) => {
36
36
  const {theme} = useContext(ApplicationContext);
@@ -1,4 +1,4 @@
1
- import React, {FC, forwardRef, useContext, useRef, useState} from 'react';
1
+ import React, {forwardRef, useContext, useRef, useState} from 'react';
2
2
  import {
3
3
  NativeSyntheticEvent,
4
4
  TextInput,
@@ -13,7 +13,7 @@ import {Icon} from '../Icon';
13
13
  import {Text} from '../Text';
14
14
  import {checkTyping} from './utils';
15
15
 
16
- const InputSearch: FC<InputSearchProps> = forwardRef(
16
+ const InputSearch = forwardRef(
17
17
  (
18
18
  {
19
19
  placeholder,
@@ -30,7 +30,7 @@ const InputSearch: FC<InputSearchProps> = forwardRef(
30
30
  defaultValue,
31
31
  onPressButtonText,
32
32
  ...props
33
- },
33
+ }: InputSearchProps,
34
34
  ref,
35
35
  ) => {
36
36
  const {theme} = useContext(ApplicationContext);
@@ -1,4 +1,4 @@
1
- import React, {FC, forwardRef, useContext, useRef, useState} from 'react';
1
+ import React, {forwardRef, useContext, useRef, useState} from 'react';
2
2
  import {
3
3
  NativeSyntheticEvent,
4
4
  TextInput,
@@ -19,7 +19,7 @@ import {InputTextAreaProps} from './index';
19
19
  import {Icon} from '../Icon';
20
20
  import {ApplicationContext} from '../Application';
21
21
 
22
- const InputTextArea: FC<InputTextAreaProps> = forwardRef(
22
+ const InputTextArea = forwardRef(
23
23
  (
24
24
  {
25
25
  errorMessage,
@@ -38,7 +38,7 @@ const InputTextArea: FC<InputTextAreaProps> = forwardRef(
38
38
  required,
39
39
  errorSpacing,
40
40
  ...props
41
- },
41
+ }: InputTextAreaProps,
42
42
  ref,
43
43
  ) => {
44
44
  const {theme} = useContext(ApplicationContext);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@momo-kits/foundation",
3
- "version": "0.78.1",
3
+ "version": "0.78.3",
4
4
  "description": "React Native Component Kits",
5
5
  "main": "index.ts",
6
6
  "scripts": {