@momo-kits/foundation 0.89.5 → 0.89.6-rc.2
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 +216 -0
- package/Application/BottomTab/BottomTabBar.tsx +278 -0
- package/Application/{BottomTab.tsx → BottomTab/index.tsx} +42 -18
- package/Application/Components.tsx +350 -86
- package/Application/Localize.ts +44 -0
- package/Application/ModalScreen.tsx +14 -185
- package/Application/Navigation.ts +5 -19
- package/Application/NavigationContainer.tsx +62 -72
- package/Application/Navigator.ts +53 -35
- package/Application/StackScreen.tsx +289 -32
- package/Application/index.ts +13 -15
- package/Application/types.ts +64 -35
- package/Application/utils.tsx +76 -30
- package/Assets/icon_bank.json +1 -1
- package/Badge/Badge.tsx +1 -1
- package/Badge/BadgeDotAnimation.tsx +95 -0
- package/Badge/index.tsx +2 -1
- package/Badge/styles.ts +50 -6
- package/Button/index.tsx +44 -26
- package/CheckBox/index.tsx +37 -26
- package/CheckBox/types.ts +5 -3
- package/Consts/colors+spacing+radius.ts +14 -0
- package/Icon/index.tsx +9 -8
- package/Icon/types.ts +2 -2
- package/IconButton/index.tsx +24 -14
- package/Image/index.tsx +23 -8
- package/Image/types.ts +2 -0
- package/Input/Input.tsx +116 -26
- package/Input/InputDropDown.tsx +66 -51
- package/Input/InputMoney.tsx +106 -15
- package/Input/InputOTP.tsx +49 -26
- package/Input/InputSearch.tsx +252 -99
- package/Input/InputTextArea.tsx +26 -6
- package/Input/TextTyping.tsx +113 -0
- package/Input/common.tsx +48 -22
- package/Input/index.tsx +112 -77
- package/Input/styles.ts +48 -11
- package/Input/utils.ts +1 -1
- package/Layout/Card.tsx +4 -3
- package/Layout/FloatingButton.tsx +168 -0
- package/Layout/GridSystem.tsx +1 -1
- package/Layout/ItemList.tsx +3 -2
- package/Layout/Screen.tsx +242 -121
- package/Layout/Section.tsx +4 -3
- package/Layout/styles.ts +11 -13
- package/Layout/types.ts +1 -1
- package/Layout/utils.ts +4 -4
- package/Loader/index.tsx +2 -0
- package/Pagination/PaginationScroll.tsx +2 -2
- package/Pagination/styles.ts +1 -1
- package/Popup/PopupNotify.tsx +56 -45
- package/Popup/PopupPromotion.tsx +5 -7
- package/Popup/types.ts +1 -7
- package/Radio/index.tsx +35 -20
- package/Radio/types.ts +5 -3
- package/Switch/index.tsx +32 -18
- package/Switch/types.ts +5 -3
- package/Tag/index.tsx +9 -2
- package/Tag/styles.ts +3 -2
- package/Tag/types.ts +12 -0
- package/Text/index.tsx +24 -5
- package/Text/styles.ts +8 -8
- package/Text/types.ts +19 -1
- package/Title/index.tsx +170 -103
- package/Title/styles.ts +36 -9
- package/Title/types.ts +16 -48
- package/code-scanner.js +125 -16
- package/index.ts +7 -0
- package/migrate_typo.js +56 -0
- package/package.json +11 -10
- package/publish.sh +16 -21
- package/tsconfig.json +1 -1
- package/verify.js +37 -40
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import {NativeModules} from 'react-native';
|
|
2
|
+
import {LocalizationObject} from './types';
|
|
3
|
+
import defaultLanguage from '../Assets/language.json';
|
|
4
|
+
|
|
5
|
+
class Localize {
|
|
6
|
+
private assets: LocalizationObject;
|
|
7
|
+
private currentLanguage: 'en' | 'vi';
|
|
8
|
+
|
|
9
|
+
constructor(assets: LocalizationObject) {
|
|
10
|
+
this.assets = {
|
|
11
|
+
vi: {...assets?.vi, ...defaultLanguage.vi},
|
|
12
|
+
en: {...assets?.en, ...defaultLanguage.en},
|
|
13
|
+
};
|
|
14
|
+
this.currentLanguage = 'vi';
|
|
15
|
+
if (NativeModules?.RNResource?.language === 'en') {
|
|
16
|
+
this.currentLanguage = 'en';
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
get getCurrentLanguage() {
|
|
21
|
+
return this.currentLanguage;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
get getAssets() {
|
|
25
|
+
return this.assets;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
translate(key: string) {
|
|
29
|
+
return this.assets[this.currentLanguage]?.[key] || key;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
translateData(data: {vi: string; en: string}) {
|
|
33
|
+
return data[this.currentLanguage] || JSON.stringify(data);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
addTranslations(translations: LocalizationObject) {
|
|
37
|
+
this.assets = {
|
|
38
|
+
vi: {...translations?.vi, ...this.assets.vi},
|
|
39
|
+
en: {...translations?.en, ...this.assets.en},
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export default Localize;
|
|
@@ -1,40 +1,19 @@
|
|
|
1
|
-
import React, {useContext, useEffect,
|
|
1
|
+
import React, {useContext, useEffect, useRef} from 'react';
|
|
2
2
|
import {
|
|
3
|
-
Dimensions,
|
|
4
|
-
Keyboard,
|
|
5
3
|
KeyboardAvoidingView,
|
|
6
4
|
Platform,
|
|
7
5
|
Pressable,
|
|
8
6
|
StyleSheet,
|
|
9
7
|
View,
|
|
10
8
|
} from 'react-native';
|
|
11
|
-
|
|
12
|
-
import {
|
|
13
|
-
|
|
14
|
-
BottomSheetModal,
|
|
15
|
-
BottomSheetView,
|
|
16
|
-
} from '@gorhom/bottom-sheet';
|
|
9
|
+
|
|
10
|
+
import {ApplicationContext} from './index';
|
|
11
|
+
import {Styles} from '../Consts';
|
|
17
12
|
import Navigation from './Navigation';
|
|
18
|
-
import {
|
|
19
|
-
import
|
|
20
|
-
import {
|
|
21
|
-
ApplicationContext,
|
|
22
|
-
HeaderRightAction,
|
|
23
|
-
NavigationButton,
|
|
24
|
-
NavigationContainer,
|
|
25
|
-
} from './index';
|
|
26
|
-
import {HeaderBackground, HeaderLeft, HeaderTitle} from './Components';
|
|
13
|
+
import {ModalParams} from './types';
|
|
14
|
+
import BottomSheet from './BottomSheet';
|
|
27
15
|
|
|
28
16
|
const ModalScreen: React.FC<any> = props => {
|
|
29
|
-
/**
|
|
30
|
-
* dismiss callback when modal | bottom sheet dismissed
|
|
31
|
-
*/
|
|
32
|
-
useEffect(() => {
|
|
33
|
-
return () => {
|
|
34
|
-
props.route.params?.onDismiss?.();
|
|
35
|
-
};
|
|
36
|
-
}, []);
|
|
37
|
-
|
|
38
17
|
if (props.route?.params?.isBottomSheet) {
|
|
39
18
|
return <BottomSheet {...props} />;
|
|
40
19
|
}
|
|
@@ -42,17 +21,22 @@ const ModalScreen: React.FC<any> = props => {
|
|
|
42
21
|
};
|
|
43
22
|
|
|
44
23
|
const Modal: React.FC<ModalParams> = props => {
|
|
45
|
-
const {
|
|
24
|
+
const {navigator} = useContext(ApplicationContext);
|
|
46
25
|
const {screen, barrierDismissible} = props.route.params;
|
|
47
26
|
const Component = useRef(screen).current;
|
|
48
|
-
const navigation = new Navigation(props.navigation
|
|
27
|
+
const navigation = new Navigation(props.navigation);
|
|
49
28
|
const params = {
|
|
50
29
|
...props.route.params,
|
|
51
30
|
navigation,
|
|
52
31
|
};
|
|
53
|
-
|
|
54
32
|
delete params.screen;
|
|
55
33
|
|
|
34
|
+
useEffect(() => {
|
|
35
|
+
return () => {
|
|
36
|
+
props.route.params?.onDismiss?.();
|
|
37
|
+
};
|
|
38
|
+
}, []);
|
|
39
|
+
|
|
56
40
|
const onDismiss = () => {
|
|
57
41
|
if (barrierDismissible) {
|
|
58
42
|
return;
|
|
@@ -91,142 +75,6 @@ const Modal: React.FC<ModalParams> = props => {
|
|
|
91
75
|
);
|
|
92
76
|
};
|
|
93
77
|
|
|
94
|
-
const BottomSheet: React.FC<BottomSheetParams> = props => {
|
|
95
|
-
const insets = useSafeAreaInsets();
|
|
96
|
-
const {theme, navigator} = useContext(ApplicationContext);
|
|
97
|
-
const [keyboardSnap, setKeyboardSnap] = useState(0);
|
|
98
|
-
const {screen, options, snapPoint, indicatorColor}: BottomSheetParams =
|
|
99
|
-
props.route.params;
|
|
100
|
-
const Component = useRef(screen).current;
|
|
101
|
-
const navigation = new Navigation(props.navigation, theme);
|
|
102
|
-
const params = {
|
|
103
|
-
...props.route.params,
|
|
104
|
-
navigation,
|
|
105
|
-
};
|
|
106
|
-
|
|
107
|
-
delete params.screen;
|
|
108
|
-
|
|
109
|
-
const snapPoints = useMemo(() => {
|
|
110
|
-
if (snapPoint) {
|
|
111
|
-
const current = parseInt(snapPoint) + keyboardSnap * 100;
|
|
112
|
-
return [`${current}%`];
|
|
113
|
-
}
|
|
114
|
-
return ['50%', '70%', '90%'];
|
|
115
|
-
}, [keyboardSnap]);
|
|
116
|
-
|
|
117
|
-
const bottomSheetRef = useRef<any>(null);
|
|
118
|
-
const mountedRef = useRef(true);
|
|
119
|
-
|
|
120
|
-
let backgroundColor = theme.colors.background.default;
|
|
121
|
-
let bottomInset = keyboardSnap * Dimensions.get('window').height;
|
|
122
|
-
if (bottomInset > 16) {
|
|
123
|
-
bottomInset -= 16;
|
|
124
|
-
}
|
|
125
|
-
if (options?.surface) {
|
|
126
|
-
backgroundColor = theme.colors.background.surface;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
useEffect(() => {
|
|
130
|
-
const keyboardDidShow = Keyboard.addListener('keyboardDidShow', e => {
|
|
131
|
-
setKeyboardSnap(
|
|
132
|
-
e.endCoordinates.height / Dimensions.get('window').height,
|
|
133
|
-
);
|
|
134
|
-
bottomSheetRef.current?.expand();
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
const keyboardDidHide = Keyboard.addListener('keyboardDidHide', () => {
|
|
138
|
-
setKeyboardSnap(0);
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
bottomSheetRef.current?.present();
|
|
142
|
-
return () => {
|
|
143
|
-
mountedRef.current = false;
|
|
144
|
-
keyboardDidShow.remove();
|
|
145
|
-
keyboardDidHide.remove();
|
|
146
|
-
};
|
|
147
|
-
}, []);
|
|
148
|
-
|
|
149
|
-
const backdropComponent = (backdropProps: any) => (
|
|
150
|
-
<BottomSheetBackdrop
|
|
151
|
-
disappearsOnIndex={-1}
|
|
152
|
-
appearsOnIndex={0}
|
|
153
|
-
{...backdropProps}
|
|
154
|
-
/>
|
|
155
|
-
);
|
|
156
|
-
|
|
157
|
-
return (
|
|
158
|
-
<SafeAreaView style={Styles.flex}>
|
|
159
|
-
<BottomSheetModal
|
|
160
|
-
ref={bottomSheetRef}
|
|
161
|
-
snapPoints={snapPoints}
|
|
162
|
-
onDismiss={() => {
|
|
163
|
-
if (mountedRef.current) {
|
|
164
|
-
navigator?.pop();
|
|
165
|
-
}
|
|
166
|
-
}}
|
|
167
|
-
bottomInset={Platform.OS === 'ios' ? bottomInset : 0}
|
|
168
|
-
handleComponent={null}
|
|
169
|
-
backdropComponent={backdropComponent}>
|
|
170
|
-
<BottomSheetView>
|
|
171
|
-
<View style={[styles.sheetContainer, {backgroundColor}]}>
|
|
172
|
-
<View style={styles.indicatorContainer}>
|
|
173
|
-
<View
|
|
174
|
-
style={[
|
|
175
|
-
styles.indicator,
|
|
176
|
-
{backgroundColor: theme.colors.text.disable},
|
|
177
|
-
]}
|
|
178
|
-
/>
|
|
179
|
-
</View>
|
|
180
|
-
<NavigationContainer
|
|
181
|
-
maxApi={navigator?.maxApi}
|
|
182
|
-
theme={{
|
|
183
|
-
...theme,
|
|
184
|
-
assets: {...theme.assets, headerBackground: undefined},
|
|
185
|
-
}}
|
|
186
|
-
screen={props => <Component {...props} {...params} />}
|
|
187
|
-
options={{
|
|
188
|
-
...options,
|
|
189
|
-
...{
|
|
190
|
-
headerLeft: (props: any) => {
|
|
191
|
-
if (props.canGoBack) {
|
|
192
|
-
return <HeaderLeft {...props} useBorder={false} />;
|
|
193
|
-
}
|
|
194
|
-
},
|
|
195
|
-
headerTitle: (props: any) => {
|
|
196
|
-
return <HeaderTitle {...props} />;
|
|
197
|
-
},
|
|
198
|
-
headerTintColor: theme.colors.text.default,
|
|
199
|
-
headerBackground: () => (
|
|
200
|
-
<HeaderBackground backgroundColor={backgroundColor} />
|
|
201
|
-
),
|
|
202
|
-
headerTransparent: false,
|
|
203
|
-
},
|
|
204
|
-
headerTitleAlign: 'center',
|
|
205
|
-
headerRight: props => (
|
|
206
|
-
<HeaderRightAction>
|
|
207
|
-
<NavigationButton
|
|
208
|
-
{...props}
|
|
209
|
-
icon="24_navigation_close"
|
|
210
|
-
useBorder={false}
|
|
211
|
-
onPress={() => bottomSheetRef.current?.dismiss()}
|
|
212
|
-
/>
|
|
213
|
-
</HeaderRightAction>
|
|
214
|
-
),
|
|
215
|
-
}}
|
|
216
|
-
/>
|
|
217
|
-
<View
|
|
218
|
-
style={{
|
|
219
|
-
height: Math.min(insets.bottom, 20),
|
|
220
|
-
backgroundColor: indicatorColor ?? backgroundColor,
|
|
221
|
-
}}
|
|
222
|
-
/>
|
|
223
|
-
</View>
|
|
224
|
-
</BottomSheetView>
|
|
225
|
-
</BottomSheetModal>
|
|
226
|
-
</SafeAreaView>
|
|
227
|
-
);
|
|
228
|
-
};
|
|
229
|
-
|
|
230
78
|
const styles = StyleSheet.create({
|
|
231
79
|
container: {flex: 1, flexDirection: 'row'},
|
|
232
80
|
modalContent: {
|
|
@@ -244,25 +92,6 @@ const styles = StyleSheet.create({
|
|
|
244
92
|
flex: 1,
|
|
245
93
|
minHeight: '10%',
|
|
246
94
|
},
|
|
247
|
-
sheetContainer: {
|
|
248
|
-
height: '100%',
|
|
249
|
-
width: '100%',
|
|
250
|
-
borderTopLeftRadius: Radius.M,
|
|
251
|
-
borderTopRightRadius: Radius.M,
|
|
252
|
-
overflow: 'hidden',
|
|
253
|
-
},
|
|
254
|
-
indicatorContainer: {
|
|
255
|
-
width: '100%',
|
|
256
|
-
paddingTop: Spacing.S,
|
|
257
|
-
paddingBottom: Spacing.XS,
|
|
258
|
-
alignItems: 'center',
|
|
259
|
-
justifyContent: 'center',
|
|
260
|
-
},
|
|
261
|
-
indicator: {
|
|
262
|
-
width: 40,
|
|
263
|
-
height: 4,
|
|
264
|
-
borderRadius: Radius.S,
|
|
265
|
-
},
|
|
266
95
|
});
|
|
267
96
|
|
|
268
97
|
export default ModalScreen;
|
|
@@ -1,17 +1,13 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
1
|
import {NavigationProp} from '@react-navigation/native';
|
|
3
|
-
import {NavigationOptions
|
|
4
|
-
import {HeaderRightAction} from './index';
|
|
2
|
+
import {NavigationOptions} from './types';
|
|
5
3
|
import {getOptions} from './utils';
|
|
6
|
-
import {HeaderToolkitAction} from './Components';
|
|
7
4
|
|
|
8
5
|
class Navigation {
|
|
9
|
-
|
|
10
|
-
|
|
6
|
+
instance: NavigationProp<any>;
|
|
7
|
+
onHeaderRightChange?: (width: number) => void;
|
|
11
8
|
|
|
12
|
-
constructor(instance: any
|
|
9
|
+
constructor(instance: any) {
|
|
13
10
|
this.instance = instance;
|
|
14
|
-
this.theme = theme;
|
|
15
11
|
}
|
|
16
12
|
|
|
17
13
|
/**
|
|
@@ -19,16 +15,6 @@ class Navigation {
|
|
|
19
15
|
* @param params
|
|
20
16
|
*/
|
|
21
17
|
private filterParams = (params: NavigationOptions) => {
|
|
22
|
-
if (params.headerRight) {
|
|
23
|
-
const headerRight = params.headerRight?.({}) as React.ReactElement;
|
|
24
|
-
const type = headerRight?.type;
|
|
25
|
-
if (type !== HeaderRightAction && type !== HeaderToolkitAction) {
|
|
26
|
-
console.warn(
|
|
27
|
-
'headerRight contains element type of HeaderRightAction | HeaderToolkitAction, Please check again.',
|
|
28
|
-
);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
18
|
if (params.headerLeft) {
|
|
33
19
|
console.warn('headerLeft not allow override render by design system!');
|
|
34
20
|
delete params.headerLeft;
|
|
@@ -42,7 +28,7 @@ class Navigation {
|
|
|
42
28
|
* @param params
|
|
43
29
|
*/
|
|
44
30
|
setOptions = (params: NavigationOptions) => {
|
|
45
|
-
params = getOptions(this.filterParams(params), this
|
|
31
|
+
params = getOptions(this.filterParams(params), this);
|
|
46
32
|
this.instance.setOptions(params);
|
|
47
33
|
};
|
|
48
34
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import React, {
|
|
2
|
-
import {BottomSheetModalProvider} from '@gorhom/bottom-sheet';
|
|
1
|
+
import React, {useEffect, useRef, useState} from 'react';
|
|
3
2
|
import {SafeAreaProvider} from 'react-native-safe-area-context';
|
|
4
3
|
import {
|
|
5
4
|
NavigationContainer as ReactNavigationContainer,
|
|
@@ -11,9 +10,9 @@ import StackScreen from './StackScreen';
|
|
|
11
10
|
import ModalScreen from './ModalScreen';
|
|
12
11
|
import Navigator from './Navigator';
|
|
13
12
|
import {getDialogOptions, getModalOptions, getStackOptions} from './utils';
|
|
14
|
-
import {
|
|
15
|
-
import {ApplicationContext
|
|
16
|
-
import
|
|
13
|
+
import {NavigationContainerProps} from './types';
|
|
14
|
+
import {ApplicationContext} from './index';
|
|
15
|
+
import Localize from './Localize';
|
|
17
16
|
|
|
18
17
|
const Stack = createStackNavigator();
|
|
19
18
|
|
|
@@ -22,14 +21,18 @@ const NavigationContainer: React.FC<NavigationContainerProps> = ({
|
|
|
22
21
|
theme,
|
|
23
22
|
options,
|
|
24
23
|
maxApi,
|
|
25
|
-
|
|
24
|
+
initialParams,
|
|
25
|
+
localize = new Localize({vi: {}, en: {}}),
|
|
26
26
|
}) => {
|
|
27
|
-
const
|
|
28
|
-
const
|
|
29
|
-
const navigator = useRef(new Navigator(navigationRef));
|
|
27
|
+
const navigationRef = useRef<NavigationContainerRef>(null);
|
|
28
|
+
const isReady = useRef(false);
|
|
29
|
+
const navigator = useRef(new Navigator(navigationRef, isReady));
|
|
30
30
|
const [showGrid, setShowGrid] = useState(false);
|
|
31
31
|
const config = useRef<any>();
|
|
32
|
-
|
|
32
|
+
/**
|
|
33
|
+
* inject data for navigator
|
|
34
|
+
*/
|
|
35
|
+
navigator.current.maxApi = maxApi;
|
|
33
36
|
/**
|
|
34
37
|
* handle mini language & listen change
|
|
35
38
|
* engine only shake to enable grid view
|
|
@@ -39,7 +42,7 @@ const NavigationContainer: React.FC<NavigationContainerProps> = ({
|
|
|
39
42
|
'onChangeGrid',
|
|
40
43
|
enable => {
|
|
41
44
|
setShowGrid(!!enable);
|
|
42
|
-
}
|
|
45
|
+
}
|
|
43
46
|
);
|
|
44
47
|
|
|
45
48
|
return () => {
|
|
@@ -47,72 +50,59 @@ const NavigationContainer: React.FC<NavigationContainerProps> = ({
|
|
|
47
50
|
};
|
|
48
51
|
}, []);
|
|
49
52
|
|
|
50
|
-
/**
|
|
51
|
-
* inject data for navigator
|
|
52
|
-
*/
|
|
53
|
-
navigator.current.maxApi = maxApi;
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* translate
|
|
57
|
-
* @param key
|
|
58
|
-
*/
|
|
59
53
|
const translate = (key: string) => {
|
|
60
|
-
|
|
61
|
-
const mergedLocalization: LocalizationObject = {
|
|
62
|
-
vi: {...localization?.vi, ...kitLocalization.vi},
|
|
63
|
-
en: {...localization?.en, ...kitLocalization.en},
|
|
64
|
-
};
|
|
65
|
-
return mergedLocalization?.[language]?.[key] || key;
|
|
54
|
+
return localize?.translate(key);
|
|
66
55
|
};
|
|
67
56
|
|
|
68
57
|
return (
|
|
69
58
|
<SafeAreaProvider>
|
|
70
|
-
<
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
theme
|
|
81
|
-
|
|
82
|
-
colors
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
59
|
+
<ApplicationContext.Provider
|
|
60
|
+
value={{
|
|
61
|
+
navigator: navigator.current,
|
|
62
|
+
config: config.current,
|
|
63
|
+
theme,
|
|
64
|
+
showGrid,
|
|
65
|
+
translate,
|
|
66
|
+
}}>
|
|
67
|
+
<ReactNavigationContainer
|
|
68
|
+
theme={{
|
|
69
|
+
...theme,
|
|
70
|
+
colors: {
|
|
71
|
+
...theme.colors,
|
|
72
|
+
background: theme.colors.background.default,
|
|
73
|
+
card: theme.colors.background.surface,
|
|
74
|
+
text: theme.colors.text.default,
|
|
75
|
+
border: theme.colors.border.default,
|
|
76
|
+
notification: theme.colors.error.primary,
|
|
77
|
+
},
|
|
78
|
+
}}
|
|
79
|
+
ref={navigationRef}
|
|
80
|
+
onReady={() => {
|
|
81
|
+
isReady.current = true;
|
|
82
|
+
}}
|
|
83
|
+
independent={true}>
|
|
84
|
+
<Stack.Navigator initialRouteName="Stack" headerMode="screen">
|
|
85
|
+
<Stack.Screen
|
|
86
|
+
name="Stack"
|
|
87
|
+
component={StackScreen}
|
|
88
|
+
initialParams={{screen, initialParams}}
|
|
89
|
+
options={{...getStackOptions(), ...options}}
|
|
90
|
+
/>
|
|
91
|
+
<Stack.Screen
|
|
92
|
+
name="Dialog"
|
|
93
|
+
component={StackScreen}
|
|
94
|
+
options={getDialogOptions()}
|
|
95
|
+
initialParams={{screen}}
|
|
96
|
+
/>
|
|
97
|
+
<Stack.Screen
|
|
98
|
+
name="Modal"
|
|
99
|
+
component={ModalScreen}
|
|
100
|
+
options={getModalOptions()}
|
|
101
|
+
initialParams={{screen}}
|
|
102
|
+
/>
|
|
103
|
+
</Stack.Navigator>
|
|
104
|
+
</ReactNavigationContainer>
|
|
105
|
+
</ApplicationContext.Provider>
|
|
116
106
|
</SafeAreaProvider>
|
|
117
107
|
);
|
|
118
108
|
};
|
package/Application/Navigator.ts
CHANGED
|
@@ -8,13 +8,15 @@ import {
|
|
|
8
8
|
|
|
9
9
|
class Navigator {
|
|
10
10
|
ref?: any;
|
|
11
|
+
isReady?: any;
|
|
11
12
|
toolkitConfig?: HeaderToolkitProps;
|
|
12
13
|
maxApi?: any;
|
|
13
14
|
dismissData?: any;
|
|
14
|
-
toolkitCallback?: (
|
|
15
|
+
toolkitCallback?: (key: string) => void;
|
|
15
16
|
|
|
16
|
-
constructor(navigation: any) {
|
|
17
|
+
constructor(navigation: any, isReady: any) {
|
|
17
18
|
this.ref = navigation;
|
|
19
|
+
this.isReady = isReady;
|
|
18
20
|
}
|
|
19
21
|
|
|
20
22
|
/**
|
|
@@ -22,7 +24,9 @@ class Navigator {
|
|
|
22
24
|
* @param params
|
|
23
25
|
*/
|
|
24
26
|
push = (params: ScreenParams) => {
|
|
25
|
-
this.
|
|
27
|
+
if (this.isReady.current) {
|
|
28
|
+
this.ref.current?.dispatch?.(StackActions.push('Stack', params));
|
|
29
|
+
}
|
|
26
30
|
};
|
|
27
31
|
|
|
28
32
|
/**
|
|
@@ -30,14 +34,18 @@ class Navigator {
|
|
|
30
34
|
* @param params
|
|
31
35
|
*/
|
|
32
36
|
replace = (params: ScreenParams) => {
|
|
33
|
-
this.
|
|
37
|
+
if (this.isReady.current) {
|
|
38
|
+
this.ref.current?.dispatch?.(StackActions.replace('Stack', params));
|
|
39
|
+
}
|
|
34
40
|
};
|
|
35
41
|
/**
|
|
36
42
|
* pop to dismiss a screen
|
|
37
43
|
* @param count
|
|
38
44
|
*/
|
|
39
45
|
pop = (count?: number) => {
|
|
40
|
-
this.
|
|
46
|
+
if (this.isReady.current) {
|
|
47
|
+
this.ref.current?.dispatch?.(StackActions.pop(count ?? 1));
|
|
48
|
+
}
|
|
41
49
|
};
|
|
42
50
|
|
|
43
51
|
/**
|
|
@@ -45,7 +53,9 @@ class Navigator {
|
|
|
45
53
|
* @param params
|
|
46
54
|
*/
|
|
47
55
|
present = (params: ScreenParams) => {
|
|
48
|
-
this.
|
|
56
|
+
if (this.isReady.current) {
|
|
57
|
+
this.ref.current?.dispatch?.(StackActions.push('Dialog', params));
|
|
58
|
+
}
|
|
49
59
|
};
|
|
50
60
|
|
|
51
61
|
/**
|
|
@@ -53,7 +63,9 @@ class Navigator {
|
|
|
53
63
|
* @param params
|
|
54
64
|
*/
|
|
55
65
|
showModal = (params: ModalParams) => {
|
|
56
|
-
this.
|
|
66
|
+
if (this.isReady.current) {
|
|
67
|
+
this.ref.current?.dispatch?.(StackActions.push('Modal', params));
|
|
68
|
+
}
|
|
57
69
|
};
|
|
58
70
|
|
|
59
71
|
/**
|
|
@@ -61,19 +73,23 @@ class Navigator {
|
|
|
61
73
|
* @param params
|
|
62
74
|
*/
|
|
63
75
|
showBottomSheet = (params: BottomSheetParams) => {
|
|
64
|
-
this.
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
76
|
+
if (this.isReady.current) {
|
|
77
|
+
this.ref.current?.dispatch?.(
|
|
78
|
+
StackActions.push('Modal', {
|
|
79
|
+
...params,
|
|
80
|
+
isBottomSheet: true,
|
|
81
|
+
})
|
|
82
|
+
);
|
|
83
|
+
}
|
|
70
84
|
};
|
|
71
85
|
|
|
72
86
|
/**
|
|
73
87
|
* pop all screen route
|
|
74
88
|
*/
|
|
75
89
|
popToTop = () => {
|
|
76
|
-
this.
|
|
90
|
+
if (this.isReady.current) {
|
|
91
|
+
this.ref.current?.dispatch?.(StackActions.popToTop());
|
|
92
|
+
}
|
|
77
93
|
};
|
|
78
94
|
|
|
79
95
|
/**
|
|
@@ -82,12 +98,14 @@ class Navigator {
|
|
|
82
98
|
* @param params
|
|
83
99
|
*/
|
|
84
100
|
navigate = (name: string, params: any) => {
|
|
85
|
-
this.
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
101
|
+
if (this.isReady.current) {
|
|
102
|
+
this.ref.current?.dispatch?.(
|
|
103
|
+
CommonActions.navigate({
|
|
104
|
+
name,
|
|
105
|
+
params,
|
|
106
|
+
})
|
|
107
|
+
);
|
|
108
|
+
}
|
|
91
109
|
};
|
|
92
110
|
|
|
93
111
|
/**
|
|
@@ -95,18 +113,20 @@ class Navigator {
|
|
|
95
113
|
* @param params
|
|
96
114
|
*/
|
|
97
115
|
reset = (params: ScreenParams) => {
|
|
98
|
-
this.
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
116
|
+
if (this.isReady.current) {
|
|
117
|
+
this.ref.current?.dispatch?.(
|
|
118
|
+
CommonActions.reset({
|
|
119
|
+
index: 0,
|
|
120
|
+
routes: [
|
|
121
|
+
{
|
|
122
|
+
name: 'Stack',
|
|
123
|
+
key: `Stack_${new Date().getTime()}`,
|
|
124
|
+
params,
|
|
125
|
+
},
|
|
126
|
+
],
|
|
127
|
+
})
|
|
128
|
+
);
|
|
129
|
+
}
|
|
110
130
|
};
|
|
111
131
|
|
|
112
132
|
/**
|
|
@@ -121,9 +141,7 @@ class Navigator {
|
|
|
121
141
|
* set callback function for toolkit
|
|
122
142
|
* @param callback
|
|
123
143
|
*/
|
|
124
|
-
setToolkitCallback = (
|
|
125
|
-
callback: (item: {key: string; action: string}) => void,
|
|
126
|
-
) => {
|
|
144
|
+
setToolkitCallback = (callback: (key: string) => void) => {
|
|
127
145
|
this.toolkitCallback = callback;
|
|
128
146
|
};
|
|
129
147
|
}
|