@momo-kits/foundation 0.102.7-beta.0 → 0.102.7-optimize.0
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/Localize.ts +37 -0
- package/Application/NavigationContainer.tsx +10 -21
- package/Application/Navigator.ts +9 -9
- package/Application/index.ts +3 -1
- package/Application/types.ts +3 -2
- package/Input/styles.ts +1 -2
- package/index.ts +0 -1
- package/package.json +1 -1
- package/publish.sh +2 -2
|
@@ -0,0 +1,37 @@
|
|
|
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
|
+
translate(key: string) {
|
|
21
|
+
return this.assets[this.currentLanguage]?.[key] || key;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
translateData(data: {vi: string; en: string}) {
|
|
25
|
+
return data[this.currentLanguage] || data.vi || JSON.stringify(data);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
addTranslations(translations: LocalizationObject) {
|
|
29
|
+
this.assets = translations;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
setLanguage(language: 'en' | 'vi') {
|
|
33
|
+
this.currentLanguage = language;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export default Localize;
|
|
@@ -10,9 +10,9 @@ import StackScreen from './StackScreen';
|
|
|
10
10
|
import ModalScreen from './ModalScreen';
|
|
11
11
|
import Navigator from './Navigator';
|
|
12
12
|
import {getDialogOptions, getModalOptions, getStackOptions} from './utils';
|
|
13
|
-
import {
|
|
13
|
+
import {NavigationContainerProps} from './types';
|
|
14
14
|
import {ApplicationContext} from './index';
|
|
15
|
-
import
|
|
15
|
+
import Localize from './Localize';
|
|
16
16
|
|
|
17
17
|
const Stack = createStackNavigator();
|
|
18
18
|
|
|
@@ -21,15 +21,18 @@ const NavigationContainer: React.FC<NavigationContainerProps> = ({
|
|
|
21
21
|
theme,
|
|
22
22
|
options,
|
|
23
23
|
maxApi,
|
|
24
|
-
localization,
|
|
25
24
|
initialParams,
|
|
25
|
+
localize = new Localize({vi: {}, en: {}}),
|
|
26
26
|
}) => {
|
|
27
27
|
const navigationRef = useRef<NavigationContainerRef>(null);
|
|
28
28
|
const isReady = useRef(false);
|
|
29
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,22 +50,8 @@ 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 (
|
|
@@ -87,7 +76,7 @@ const NavigationContainer: React.FC<NavigationContainerProps> = ({
|
|
|
87
76
|
notification: theme.colors.error.primary,
|
|
88
77
|
},
|
|
89
78
|
}}
|
|
90
|
-
ref={
|
|
79
|
+
ref={navigationRef}
|
|
91
80
|
onReady={() => {
|
|
92
81
|
isReady.current = true;
|
|
93
82
|
}}
|
package/Application/Navigator.ts
CHANGED
|
@@ -25,7 +25,7 @@ class Navigator {
|
|
|
25
25
|
*/
|
|
26
26
|
push = (params: ScreenParams) => {
|
|
27
27
|
if (this.isReady.current) {
|
|
28
|
-
this.ref.current
|
|
28
|
+
this.ref.current?.dispatch?.(StackActions.push('Stack', params));
|
|
29
29
|
}
|
|
30
30
|
};
|
|
31
31
|
|
|
@@ -35,7 +35,7 @@ class Navigator {
|
|
|
35
35
|
*/
|
|
36
36
|
replace = (params: ScreenParams) => {
|
|
37
37
|
if (this.isReady.current) {
|
|
38
|
-
this.ref.current
|
|
38
|
+
this.ref.current?.dispatch?.(StackActions.replace('Stack', params));
|
|
39
39
|
}
|
|
40
40
|
};
|
|
41
41
|
/**
|
|
@@ -44,7 +44,7 @@ class Navigator {
|
|
|
44
44
|
*/
|
|
45
45
|
pop = (count?: number) => {
|
|
46
46
|
if (this.isReady.current) {
|
|
47
|
-
this.ref.current
|
|
47
|
+
this.ref.current?.dispatch?.(StackActions.pop(count ?? 1));
|
|
48
48
|
}
|
|
49
49
|
};
|
|
50
50
|
|
|
@@ -54,7 +54,7 @@ class Navigator {
|
|
|
54
54
|
*/
|
|
55
55
|
present = (params: ScreenParams) => {
|
|
56
56
|
if (this.isReady.current) {
|
|
57
|
-
this.ref.current
|
|
57
|
+
this.ref.current?.dispatch?.(StackActions.push('Dialog', params));
|
|
58
58
|
}
|
|
59
59
|
};
|
|
60
60
|
|
|
@@ -64,7 +64,7 @@ class Navigator {
|
|
|
64
64
|
*/
|
|
65
65
|
showModal = (params: ModalParams) => {
|
|
66
66
|
if (this.isReady.current) {
|
|
67
|
-
this.ref.current
|
|
67
|
+
this.ref.current?.dispatch?.(StackActions.push('Modal', params));
|
|
68
68
|
}
|
|
69
69
|
};
|
|
70
70
|
|
|
@@ -74,7 +74,7 @@ class Navigator {
|
|
|
74
74
|
*/
|
|
75
75
|
showBottomSheet = (params: BottomSheetParams) => {
|
|
76
76
|
if (this.isReady.current) {
|
|
77
|
-
this.ref.current
|
|
77
|
+
this.ref.current?.dispatch?.(
|
|
78
78
|
StackActions.push('Modal', {
|
|
79
79
|
...params,
|
|
80
80
|
isBottomSheet: true,
|
|
@@ -88,7 +88,7 @@ class Navigator {
|
|
|
88
88
|
*/
|
|
89
89
|
popToTop = () => {
|
|
90
90
|
if (this.isReady.current) {
|
|
91
|
-
this.ref.current
|
|
91
|
+
this.ref.current?.dispatch?.(StackActions.popToTop());
|
|
92
92
|
}
|
|
93
93
|
};
|
|
94
94
|
|
|
@@ -99,7 +99,7 @@ class Navigator {
|
|
|
99
99
|
*/
|
|
100
100
|
navigate = (name: string, params: any) => {
|
|
101
101
|
if (this.isReady.current) {
|
|
102
|
-
this.ref.current
|
|
102
|
+
this.ref.current?.dispatch?.(
|
|
103
103
|
CommonActions.navigate({
|
|
104
104
|
name,
|
|
105
105
|
params,
|
|
@@ -114,7 +114,7 @@ class Navigator {
|
|
|
114
114
|
*/
|
|
115
115
|
reset = (params: ScreenParams) => {
|
|
116
116
|
if (this.isReady.current) {
|
|
117
|
-
this.ref.current
|
|
117
|
+
this.ref.current?.dispatch?.(
|
|
118
118
|
CommonActions.reset({
|
|
119
119
|
index: 0,
|
|
120
120
|
routes: [
|
package/Application/index.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import {Platform} from 'react-native';
|
|
2
|
+
import {createContext} from 'react';
|
|
2
3
|
import {NavigationContainer} from './NavigationContainer';
|
|
4
|
+
import Localize from './Localize';
|
|
3
5
|
import Screen from '../Layout/Screen';
|
|
4
6
|
import {
|
|
5
7
|
HeaderAnimated,
|
|
@@ -10,7 +12,6 @@ import {
|
|
|
10
12
|
HeaderRightAction,
|
|
11
13
|
} from './Components';
|
|
12
14
|
import BottomTab from './BottomTab';
|
|
13
|
-
import {createContext} from 'react';
|
|
14
15
|
import {defaultContext} from '../Consts';
|
|
15
16
|
|
|
16
17
|
const Context = createContext({});
|
|
@@ -26,6 +27,7 @@ export {
|
|
|
26
27
|
ScreenContext,
|
|
27
28
|
ComponentContext,
|
|
28
29
|
NavigationContainer,
|
|
30
|
+
Localize,
|
|
29
31
|
Screen,
|
|
30
32
|
BottomTab,
|
|
31
33
|
NavigationButton,
|
package/Application/types.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import {StackNavigationOptions} from '@react-navigation/stack';
|
|
2
1
|
import {EventArg} from '@react-navigation/core';
|
|
2
|
+
import {StackNavigationOptions} from '@react-navigation/stack';
|
|
3
3
|
import React from 'react';
|
|
4
4
|
import {Animated, ViewProps} from 'react-native';
|
|
5
5
|
import {PopupNotifyProps} from '../Popup/types';
|
|
6
|
+
import Localize from './Localize';
|
|
6
7
|
import Navigation from './Navigation';
|
|
7
8
|
import Navigator from './Navigator';
|
|
8
9
|
|
|
@@ -85,8 +86,8 @@ export type NavigationContainerProps = {
|
|
|
85
86
|
options?: NavigationOptions;
|
|
86
87
|
theme: Theme;
|
|
87
88
|
maxApi: any;
|
|
88
|
-
localization?: LocalizationObject;
|
|
89
89
|
initialParams?: any;
|
|
90
|
+
localize: Localize;
|
|
90
91
|
};
|
|
91
92
|
|
|
92
93
|
export type NavigationScreenProps = {
|
package/Input/styles.ts
CHANGED
|
@@ -32,10 +32,9 @@ export default StyleSheet.create({
|
|
|
32
32
|
alignItems: 'center',
|
|
33
33
|
},
|
|
34
34
|
floatingIcon: {marginLeft: Spacing.XS},
|
|
35
|
-
errorIcon: {marginRight: Spacing.XS},
|
|
35
|
+
errorIcon: {marginRight: Spacing.XS, marginTop: Spacing.XXS},
|
|
36
36
|
errorView: {
|
|
37
37
|
flexDirection: 'row',
|
|
38
|
-
alignItems: 'center',
|
|
39
38
|
marginTop: Spacing.XS,
|
|
40
39
|
},
|
|
41
40
|
inputView: {
|
package/index.ts
CHANGED
package/package.json
CHANGED
package/publish.sh
CHANGED
|
@@ -9,8 +9,8 @@ elif [ "$1" == "latest" ]; then
|
|
|
9
9
|
npm version prerelease --preid=rc
|
|
10
10
|
npm publish --tag latest --access=public
|
|
11
11
|
else
|
|
12
|
-
npm version $(npm view @momo-kits/foundation@beta version)
|
|
13
|
-
npm version prerelease --preid=beta
|
|
12
|
+
# npm version $(npm view @momo-kits/foundation@beta version)
|
|
13
|
+
# npm version prerelease --preid=beta
|
|
14
14
|
npm publish --tag beta --access=public
|
|
15
15
|
fi
|
|
16
16
|
|