@momo-kits/foundation 0.81.52 → 0.81.53-beta.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/BottomSheet.tsx +216 -0
- package/Application/BottomTab/BottomTabBar.tsx +278 -0
- package/Application/{BottomTab.tsx → BottomTab/index.tsx} +43 -18
- package/Application/Components.tsx +71 -53
- package/Application/ModalScreen.tsx +12 -183
- package/Application/Navigation.ts +2 -2
- package/Application/NavigationContainer.tsx +54 -53
- package/Application/Navigator.ts +53 -35
- package/Application/StackScreen.tsx +225 -30
- package/Application/index.ts +8 -12
- package/Application/types.ts +45 -27
- package/Application/utils.tsx +19 -15
- package/Assets/icon_bank.json +1 -1
- package/Badge/Badge.tsx +1 -1
- package/Button/index.tsx +44 -25
- 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 +45 -22
- package/Input/InputSearch.tsx +92 -44
- package/Input/InputTextArea.tsx +26 -6
- package/Input/common.tsx +48 -22
- package/Input/index.tsx +94 -77
- package/Input/styles.ts +35 -5
- 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 +87 -49
- package/Layout/Section.tsx +4 -3
- package/Layout/styles.ts +11 -7
- package/Layout/utils.ts +4 -4
- package/Loader/index.tsx +2 -0
- package/Popup/PopupNotify.tsx +55 -44
- 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/styles.ts +3 -2
- package/Text/index.tsx +24 -5
- package/Text/styles.ts +8 -8
- 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/package.json +6 -6
- package/publish.sh +16 -21
- package/tsconfig.json +1 -1
|
@@ -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,
|
|
@@ -12,7 +11,7 @@ import ModalScreen from './ModalScreen';
|
|
|
12
11
|
import Navigator from './Navigator';
|
|
13
12
|
import {getDialogOptions, getModalOptions, getStackOptions} from './utils';
|
|
14
13
|
import {LocalizationObject, NavigationContainerProps} from './types';
|
|
15
|
-
import {ApplicationContext
|
|
14
|
+
import {ApplicationContext} from './index';
|
|
16
15
|
import kitLocalization from '../Assets/language.json';
|
|
17
16
|
|
|
18
17
|
const Stack = createStackNavigator();
|
|
@@ -23,10 +22,11 @@ const NavigationContainer: React.FC<NavigationContainerProps> = ({
|
|
|
23
22
|
options,
|
|
24
23
|
maxApi,
|
|
25
24
|
localization,
|
|
25
|
+
initialParams,
|
|
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
|
|
|
@@ -57,7 +57,7 @@ const NavigationContainer: React.FC<NavigationContainerProps> = ({
|
|
|
57
57
|
* @param key
|
|
58
58
|
*/
|
|
59
59
|
const translate = (key: string) => {
|
|
60
|
-
const language: 'vi' | 'en' =
|
|
60
|
+
const language: 'vi' | 'en' = 'vi';
|
|
61
61
|
const mergedLocalization: LocalizationObject = {
|
|
62
62
|
vi: {...localization?.vi, ...kitLocalization.vi},
|
|
63
63
|
en: {...localization?.en, ...kitLocalization.en},
|
|
@@ -67,52 +67,53 @@ const NavigationContainer: React.FC<NavigationContainerProps> = ({
|
|
|
67
67
|
|
|
68
68
|
return (
|
|
69
69
|
<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
|
-
|
|
70
|
+
<ApplicationContext.Provider
|
|
71
|
+
value={{
|
|
72
|
+
navigator: navigator.current,
|
|
73
|
+
config: config.current,
|
|
74
|
+
theme,
|
|
75
|
+
showGrid,
|
|
76
|
+
translate,
|
|
77
|
+
}}>
|
|
78
|
+
<ReactNavigationContainer
|
|
79
|
+
theme={{
|
|
80
|
+
...theme,
|
|
81
|
+
colors: {
|
|
82
|
+
...theme.colors,
|
|
83
|
+
background: theme.colors.background.default,
|
|
84
|
+
card: theme.colors.background.surface,
|
|
85
|
+
text: theme.colors.text.default,
|
|
86
|
+
border: theme.colors.border.default,
|
|
87
|
+
notification: theme.colors.error.primary,
|
|
88
|
+
},
|
|
89
|
+
}}
|
|
90
|
+
ref={navigator.current?.ref}
|
|
91
|
+
onReady={() => {
|
|
92
|
+
isReady.current = true;
|
|
93
|
+
}}
|
|
94
|
+
independent={true}>
|
|
95
|
+
<Stack.Navigator initialRouteName="Stack" headerMode="screen">
|
|
96
|
+
<Stack.Screen
|
|
97
|
+
name="Stack"
|
|
98
|
+
component={StackScreen}
|
|
99
|
+
initialParams={{screen, initialParams}}
|
|
100
|
+
options={{...getStackOptions(), ...options}}
|
|
101
|
+
/>
|
|
102
|
+
<Stack.Screen
|
|
103
|
+
name="Dialog"
|
|
104
|
+
component={StackScreen}
|
|
105
|
+
options={getDialogOptions()}
|
|
106
|
+
initialParams={{screen}}
|
|
107
|
+
/>
|
|
108
|
+
<Stack.Screen
|
|
109
|
+
name="Modal"
|
|
110
|
+
component={ModalScreen}
|
|
111
|
+
options={getModalOptions()}
|
|
112
|
+
initialParams={{screen}}
|
|
113
|
+
/>
|
|
114
|
+
</Stack.Navigator>
|
|
115
|
+
</ReactNavigationContainer>
|
|
116
|
+
</ApplicationContext.Provider>
|
|
116
117
|
</SafeAreaProvider>
|
|
117
118
|
);
|
|
118
119
|
};
|
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
|
}
|
|
@@ -1,24 +1,124 @@
|
|
|
1
|
-
import React, {useContext, useEffect, useLayoutEffect} from 'react';
|
|
1
|
+
import React, {useContext, useEffect, useLayoutEffect, useRef} from 'react';
|
|
2
|
+
import {useHeaderHeight} from '@react-navigation/stack';
|
|
3
|
+
import {Alert, InteractionManager, Linking, View} from 'react-native';
|
|
2
4
|
import {ScreenParams} from './types';
|
|
3
5
|
import Navigation from './Navigation';
|
|
4
|
-
import {ApplicationContext, MiniAppContext} from './index';
|
|
6
|
+
import {ApplicationContext, MiniAppContext, ScreenContext} from './index';
|
|
5
7
|
import {GridSystem} from '../Layout';
|
|
6
|
-
import {
|
|
8
|
+
import {Text} from '../Text';
|
|
9
|
+
import {Colors, Radius, Spacing} from '../Consts';
|
|
7
10
|
|
|
11
|
+
/**
|
|
12
|
+
* Empty screen for unvalidated screen name
|
|
13
|
+
* @constructor
|
|
14
|
+
*/
|
|
15
|
+
const EmptyScreen: React.FC = () => {
|
|
16
|
+
return (
|
|
17
|
+
<View
|
|
18
|
+
style={{
|
|
19
|
+
backgroundColor: Colors.black_01,
|
|
20
|
+
padding: Spacing.M,
|
|
21
|
+
borderRadius: Radius.M,
|
|
22
|
+
}}>
|
|
23
|
+
<Text typography={'header_m_bold'}>Unvalidated screen name</Text>
|
|
24
|
+
<Text
|
|
25
|
+
typography={'description_default_regular'}
|
|
26
|
+
style={{paddingVertical: Spacing.S}}>
|
|
27
|
+
Your screen has not been rendered because Platform has not detected the
|
|
28
|
+
screen name. Please migrate to support this feature.
|
|
29
|
+
</Text>
|
|
30
|
+
<Text typography={'header_default'} style={{width: '100%'}}>
|
|
31
|
+
Possible fixes:
|
|
32
|
+
</Text>
|
|
33
|
+
<View style={{marginLeft: Spacing.S}}>
|
|
34
|
+
<Text typography={'body_default_regular'}>1. Off webpack config</Text>
|
|
35
|
+
<Text typography={'body_default_regular'}>
|
|
36
|
+
2. Screen name refactoring
|
|
37
|
+
</Text>
|
|
38
|
+
<View style={{marginLeft: Spacing.S}}>
|
|
39
|
+
<Text
|
|
40
|
+
typography={'description_default_regular'}
|
|
41
|
+
style={{marginBottom: Spacing.S}}>
|
|
42
|
+
- Với các screen push/import dạng arrow function ={'>'} đổi thành
|
|
43
|
+
named function
|
|
44
|
+
</Text>
|
|
45
|
+
<Text
|
|
46
|
+
typography={'description_default_regular'}
|
|
47
|
+
style={{marginBottom: Spacing.S}}>
|
|
48
|
+
- Với các screen import dạng High Order Component ={'>'} rename
|
|
49
|
+
generic function thành named function
|
|
50
|
+
</Text>
|
|
51
|
+
<Text
|
|
52
|
+
typography={'description_default_regular'}
|
|
53
|
+
style={{marginBottom: Spacing.S}}>
|
|
54
|
+
- Với Tab Navigator, Platform sẽ lấy Tab Container làm screen name.
|
|
55
|
+
Trong trường hợp miniapp muốn track riêng action cho từng tab, tham
|
|
56
|
+
khảo theo docs
|
|
57
|
+
</Text>
|
|
58
|
+
</View>
|
|
59
|
+
</View>
|
|
60
|
+
<Text typography={'header_s_semibold'}>More information: </Text>
|
|
61
|
+
<Text
|
|
62
|
+
typography={'body_default_regular'}
|
|
63
|
+
color={Colors.blue_01}
|
|
64
|
+
onPress={() => {
|
|
65
|
+
Linking.openURL(
|
|
66
|
+
'https://gitlab.mservice.com.vn/momo-platform/mini-app/-/tree/vn.momo.uikits/dev/app'
|
|
67
|
+
);
|
|
68
|
+
}}>
|
|
69
|
+
Mini App: vn.momo.uikits/dev
|
|
70
|
+
</Text>
|
|
71
|
+
<Text
|
|
72
|
+
typography={'body_default_regular'}
|
|
73
|
+
color={Colors.blue_01}
|
|
74
|
+
onPress={() => {
|
|
75
|
+
Linking.openURL(
|
|
76
|
+
'https://docs.google.com/presentation/d/1bIFoh8gRXb6hsnGJz4O1Kxg4_oNikB1KuuEt2wULCDM/edit?usp=sharing'
|
|
77
|
+
);
|
|
78
|
+
}}>
|
|
79
|
+
https://docs.google.com/presentation/d/1bIFoh8gRXb6hsnGJz4O1Kxg4_oNikB1KuuEt2wULCDM/edit?usp=sharing
|
|
80
|
+
</Text>
|
|
81
|
+
</View>
|
|
82
|
+
);
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* container for stack screen
|
|
87
|
+
* @param props
|
|
88
|
+
* @constructor
|
|
89
|
+
*/
|
|
8
90
|
const StackScreen: React.FC<ScreenParams> = props => {
|
|
9
91
|
const {theme, showGrid, navigator} = useContext(ApplicationContext);
|
|
10
|
-
const
|
|
92
|
+
const startTime = useRef(Date.now());
|
|
93
|
+
const endTime = useRef(Date.now());
|
|
94
|
+
const timeLoad = useRef(0);
|
|
95
|
+
const timeInteraction = useRef(0);
|
|
96
|
+
const timeoutLoad = useRef<any>();
|
|
97
|
+
const tracked = useRef<any>({
|
|
98
|
+
traceIdLoad: undefined,
|
|
99
|
+
traceIdInteraction: undefined,
|
|
100
|
+
releaseLoad: undefined,
|
|
101
|
+
releaseInteraction: undefined,
|
|
102
|
+
timeoutLoad: undefined,
|
|
103
|
+
timeoutInteraction: undefined,
|
|
104
|
+
});
|
|
105
|
+
const interaction = useRef<any>();
|
|
106
|
+
const context = useContext<any>(MiniAppContext);
|
|
11
107
|
|
|
12
|
-
const {screen: Component, options}
|
|
108
|
+
const {screen: Component, options, initialParams} = props.route.params;
|
|
13
109
|
const navigation = new Navigation(props.navigation, theme);
|
|
14
110
|
const heightHeader = useHeaderHeight();
|
|
15
111
|
|
|
16
|
-
const
|
|
112
|
+
const data = {
|
|
113
|
+
...initialParams,
|
|
17
114
|
...props.route.params,
|
|
18
115
|
navigation,
|
|
19
116
|
};
|
|
20
117
|
|
|
21
|
-
delete
|
|
118
|
+
delete data.screen;
|
|
119
|
+
delete data.initialParams;
|
|
120
|
+
|
|
121
|
+
const screenName = Component?.name || Component?.type?.name || 'Invalid';
|
|
22
122
|
|
|
23
123
|
/**
|
|
24
124
|
* set options for screen
|
|
@@ -27,44 +127,139 @@ const StackScreen: React.FC<ScreenParams> = props => {
|
|
|
27
127
|
if (options) {
|
|
28
128
|
navigation.setOptions(options);
|
|
29
129
|
}
|
|
130
|
+
navigator?.maxApi?.startTraceScreenLoad?.(screenName, (data: any) => {
|
|
131
|
+
tracked.current.traceIdLoad = data?.traceId;
|
|
132
|
+
});
|
|
133
|
+
navigator?.maxApi?.startTraceScreenInteraction?.(
|
|
134
|
+
screenName,
|
|
135
|
+
(data: any) => {
|
|
136
|
+
tracked.current.traceIdInteraction = data?.traceId;
|
|
137
|
+
}
|
|
138
|
+
);
|
|
30
139
|
}, [options]);
|
|
31
140
|
|
|
32
141
|
/**
|
|
33
142
|
* tracking for screen
|
|
34
143
|
*/
|
|
35
144
|
useEffect(() => {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
145
|
+
if (['Invalid', 'screen'].includes(screenName) && context.enableAutoId) {
|
|
146
|
+
setTimeout(() => {
|
|
147
|
+
navigator?.showModal({screen: EmptyScreen});
|
|
148
|
+
}, 300);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
navigator?.maxApi?.of?.({screenName});
|
|
152
|
+
tracked.current.timeoutLoad = setTimeout(() => {
|
|
153
|
+
onScreenLoad();
|
|
154
|
+
}, 5000);
|
|
155
|
+
tracked.current.timeoutInteraction = setTimeout(() => {
|
|
156
|
+
onScreenInteraction();
|
|
157
|
+
}, 5000);
|
|
158
|
+
|
|
159
|
+
return () => {
|
|
160
|
+
clearTimeout(tracked.current.timeoutLoad);
|
|
161
|
+
clearTimeout(tracked.current.timeoutInteraction);
|
|
162
|
+
onScreenLoad();
|
|
163
|
+
onScreenInteraction();
|
|
39
164
|
};
|
|
165
|
+
}, []);
|
|
40
166
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
167
|
+
/**
|
|
168
|
+
* tracking for screen load
|
|
169
|
+
*/
|
|
170
|
+
const onScreenLoad = () => {
|
|
171
|
+
if (!tracked.current?.releaseLoad) {
|
|
172
|
+
if (timeLoad.current === 0) {
|
|
173
|
+
timeLoad.current = endTime.current - startTime.current;
|
|
174
|
+
}
|
|
175
|
+
context.autoTracking?.({
|
|
176
|
+
appId: context.appId,
|
|
177
|
+
code: context.code,
|
|
178
|
+
buildNumber: context.buildNumber,
|
|
179
|
+
screenName,
|
|
180
|
+
componentName: 'Screen',
|
|
181
|
+
state: 'load',
|
|
182
|
+
duration: timeLoad.current,
|
|
183
|
+
});
|
|
184
|
+
navigator?.maxApi?.stopTrace?.(
|
|
185
|
+
tracked.current.traceIdLoad,
|
|
186
|
+
{value: timeLoad.current / 1000},
|
|
187
|
+
null
|
|
188
|
+
);
|
|
189
|
+
navigator?.maxApi?.showToastDebug?.({
|
|
190
|
+
appId: `auto - ${context.appId}`,
|
|
191
|
+
message: `${screenName} screen_load_time ${timeLoad.current}`,
|
|
192
|
+
});
|
|
193
|
+
if (timeLoad.current === 0 && context.enableAutoId) {
|
|
194
|
+
Alert.alert(screenName, "Can't get screen load time");
|
|
195
|
+
}
|
|
196
|
+
tracked.current.releaseLoad = true;
|
|
46
197
|
}
|
|
198
|
+
};
|
|
47
199
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
200
|
+
/**
|
|
201
|
+
* tracking for screen load
|
|
202
|
+
*/
|
|
203
|
+
const onScreenInteraction = () => {
|
|
204
|
+
if (!tracked.current?.releaseInteraction) {
|
|
205
|
+
if (timeLoad.current === 0) {
|
|
206
|
+
timeLoad.current = endTime.current - startTime.current;
|
|
207
|
+
}
|
|
208
|
+
if (timeInteraction.current === 0 && context.enableAutoId) {
|
|
209
|
+
if (context.enableAutoId) {
|
|
210
|
+
Alert.alert(screenName, "Can't get screen interaction time");
|
|
211
|
+
}
|
|
212
|
+
timeInteraction.current = timeLoad.current;
|
|
213
|
+
}
|
|
53
214
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
215
|
+
context.autoTracking?.({
|
|
216
|
+
appId: context.appId,
|
|
217
|
+
code: context.code,
|
|
218
|
+
buildNumber: context.buildNumber,
|
|
219
|
+
screenName,
|
|
220
|
+
componentName: 'Screen',
|
|
221
|
+
state: 'interaction',
|
|
222
|
+
duration: timeInteraction.current - timeLoad.current,
|
|
59
223
|
});
|
|
60
|
-
|
|
61
|
-
|
|
224
|
+
navigator?.maxApi?.stopTrace?.(
|
|
225
|
+
tracked.current.traceIdInteraction,
|
|
226
|
+
{value: timeInteraction.current / 1000},
|
|
227
|
+
null
|
|
228
|
+
);
|
|
229
|
+
navigator?.maxApi?.showToastDebug?.({
|
|
230
|
+
appId: `auto - ${context.appId}`,
|
|
231
|
+
message: `${screenName} screen_interaction_time ${timeInteraction.current}`,
|
|
232
|
+
});
|
|
233
|
+
tracked.current.releaseInteraction = true;
|
|
234
|
+
}
|
|
235
|
+
};
|
|
62
236
|
|
|
63
237
|
return (
|
|
64
|
-
|
|
65
|
-
|
|
238
|
+
<ScreenContext.Provider
|
|
239
|
+
value={{
|
|
240
|
+
screenName,
|
|
241
|
+
onElementLoad: () => {
|
|
242
|
+
clearTimeout(timeoutLoad.current);
|
|
243
|
+
endTime.current = Date.now();
|
|
244
|
+
interaction.current?.cancel?.();
|
|
245
|
+
interaction.current = InteractionManager.runAfterInteractions(() => {
|
|
246
|
+
timeInteraction.current = Date.now() - startTime.current;
|
|
247
|
+
});
|
|
248
|
+
timeoutLoad.current = setTimeout(() => {
|
|
249
|
+
if (timeLoad.current === 0) {
|
|
250
|
+
timeLoad.current = endTime.current - startTime.current;
|
|
251
|
+
}
|
|
252
|
+
}, 2000);
|
|
253
|
+
},
|
|
254
|
+
}}>
|
|
255
|
+
<Component
|
|
256
|
+
heightHeader={heightHeader}
|
|
257
|
+
{...data}
|
|
258
|
+
onScreenLoad={onScreenLoad}
|
|
259
|
+
onScreenInteraction={onScreenInteraction}
|
|
260
|
+
/>
|
|
66
261
|
{showGrid && <GridSystem />}
|
|
67
|
-
|
|
262
|
+
</ScreenContext.Provider>
|
|
68
263
|
);
|
|
69
264
|
};
|
|
70
265
|
|
package/Application/index.ts
CHANGED
|
@@ -1,41 +1,37 @@
|
|
|
1
|
+
import {Platform} from 'react-native';
|
|
1
2
|
import {NavigationContainer} from './NavigationContainer';
|
|
2
3
|
import Screen from '../Layout/Screen';
|
|
3
4
|
import {
|
|
4
5
|
HeaderAnimated,
|
|
5
6
|
HeaderBackground,
|
|
6
7
|
HeaderCustom,
|
|
7
|
-
HeaderLeft,
|
|
8
8
|
HeaderRightAction,
|
|
9
9
|
HeaderTitle,
|
|
10
|
-
HeaderToolkitAction,
|
|
11
10
|
NavigationButton,
|
|
12
11
|
} from './Components';
|
|
13
12
|
import BottomTab from './BottomTab';
|
|
14
13
|
import {createContext} from 'react';
|
|
15
14
|
import {defaultContext} from '../Consts';
|
|
16
|
-
import {MiniAppInfo} from './types';
|
|
17
15
|
|
|
16
|
+
const Context = createContext({});
|
|
18
17
|
const ApplicationContext = createContext(defaultContext);
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
toolkitConfig: {},
|
|
24
|
-
fromCode: '',
|
|
25
|
-
});
|
|
18
|
+
|
|
19
|
+
const MiniAppContext = (Platform as any).MiniAppContext ?? createContext({});
|
|
20
|
+
const ScreenContext = (Platform as any).ScreenContext ?? createContext({});
|
|
21
|
+
const ComponentContext = (Platform as any).ComponentContext ?? Context;
|
|
26
22
|
|
|
27
23
|
export {
|
|
28
24
|
ApplicationContext,
|
|
29
25
|
MiniAppContext,
|
|
26
|
+
ScreenContext,
|
|
27
|
+
ComponentContext,
|
|
30
28
|
NavigationContainer,
|
|
31
29
|
Screen,
|
|
32
30
|
BottomTab,
|
|
33
31
|
NavigationButton,
|
|
34
32
|
HeaderTitle,
|
|
35
|
-
HeaderLeft,
|
|
36
33
|
HeaderBackground,
|
|
37
34
|
HeaderRightAction,
|
|
38
|
-
HeaderToolkitAction,
|
|
39
35
|
HeaderCustom,
|
|
40
36
|
HeaderAnimated,
|
|
41
37
|
};
|