@momo-kits/foundation 0.169.16-beta.7 → 0.169.16-beta.8
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 +2 -2
- package/Application/BottomTab/BottomTabBar.styles.ts +1 -1
- package/Application/BottomTab/DuoTabBar.styles.ts +1 -1
- package/Application/BottomTab/Legacy/TabScreen.tsx +22 -16
- package/Application/BottomTab/Legacy/hooks.ts +1 -1
- package/Application/BottomTab/Legacy/index.tsx +1 -5
- package/Application/BottomTab/TabBarIcon.tsx +1 -1
- package/Application/BottomTab/TabScreen.tsx +22 -12
- package/Application/BottomTab/index.tsx +1 -1
- package/Application/Components/HeaderLeft.tsx +2 -2
- package/Application/Components/SearchHeader.tsx +2 -2
- package/Application/Components/SwipeBackHaptic.tsx +1 -1
- package/Application/Components/useToolkitActions.tsx +64 -34
- package/Application/ModalScreen.tsx +4 -4
- package/Application/NavigationContainer.tsx +10 -11
- package/Application/Navigator.ts +2 -7
- package/Application/StackScreen.tracking.ts +12 -22
- package/Application/StackScreen.tsx +34 -26
- package/Application/TooltipPortal.tsx +3 -3
- package/Application/WidgetContainer.tsx +6 -9
- package/Application/hooks.ts +1 -15
- package/Application/index.ts +0 -4
- package/Application/types.ts +3 -16
- package/Button/index.tsx +2 -2
- package/Divider/DashDivider.tsx +2 -2
- package/Divider/index.tsx +3 -3
- package/FoundationList/index.tsx +1 -1
- package/Icon/types.ts +2 -1
- package/Image/index.tsx +7 -62
- package/Image/styles.ts +0 -2
- package/Image/types.ts +1 -9
- package/Input/Input.tsx +2 -2
- package/Input/InputMoney.tsx +2 -7
- package/Input/InputMoneyView.tsx +2 -2
- package/Input/InputOTP.tsx +2 -2
- package/Input/InputPhoneNumber.tsx +2 -2
- package/Input/InputSearch.tsx +2 -2
- package/Input/InputTextArea.tsx +2 -2
- package/Input/SearchTextTyping.tsx +2 -2
- package/Input/SystemTextInput.tsx +1 -2
- package/Input/TextTyping.tsx +2 -7
- package/Pagination/types.ts +2 -6
- package/package.json +26 -28
- package/Application/KitsBindingProvider.tsx +0 -22
- package/Application/KitsHost.ts +0 -183
- package/Application/__tests__/KitsHost.test.ts +0 -155
- package/Application/types.binding.ts +0 -134
|
@@ -215,7 +215,7 @@ const BottomSheet: React.FC<BottomSheetParams> = props => {
|
|
|
215
215
|
onRequestClose={() => {
|
|
216
216
|
handleDismiss();
|
|
217
217
|
}}
|
|
218
|
-
style={StyleSheet.
|
|
218
|
+
style={StyleSheet.absoluteFillObject}
|
|
219
219
|
isModalKit={true}
|
|
220
220
|
supportedOrientations={isDuo ? DUO_ORIENTATIONS : undefined}
|
|
221
221
|
>
|
|
@@ -230,7 +230,7 @@ const BottomSheet: React.FC<BottomSheetParams> = props => {
|
|
|
230
230
|
style={styles.container}
|
|
231
231
|
>
|
|
232
232
|
<Pressable
|
|
233
|
-
style={StyleSheet.
|
|
233
|
+
style={StyleSheet.absoluteFillObject}
|
|
234
234
|
onPress={() => {
|
|
235
235
|
action.current = 'touch';
|
|
236
236
|
handleDismiss();
|
|
@@ -68,7 +68,7 @@ export const styles = StyleSheet.create({
|
|
|
68
68
|
},
|
|
69
69
|
// custom label content over the label text, centered and unclipped
|
|
70
70
|
ctaLabelOverlay: {
|
|
71
|
-
...
|
|
71
|
+
...StyleSheet.absoluteFillObject,
|
|
72
72
|
alignItems: 'center',
|
|
73
73
|
justifyContent: 'center',
|
|
74
74
|
},
|
|
@@ -57,7 +57,7 @@ export const styles = StyleSheet.create({
|
|
|
57
57
|
},
|
|
58
58
|
// custom label content over the label text, centered and unclipped
|
|
59
59
|
railCtaLabelOverlay: {
|
|
60
|
-
...
|
|
60
|
+
...StyleSheet.absoluteFillObject,
|
|
61
61
|
alignItems: 'center',
|
|
62
62
|
justifyContent: 'center',
|
|
63
63
|
},
|
|
@@ -20,10 +20,6 @@ import { styles } from './index.styles';
|
|
|
20
20
|
|
|
21
21
|
const Stack = createStackNavigator();
|
|
22
22
|
|
|
23
|
-
/**
|
|
24
|
-
* Content of one tab in the docked bar: its own stack, faded in on focus, plus
|
|
25
|
-
* screen_navigated tracking.
|
|
26
|
-
*/
|
|
27
23
|
const TabScreen: React.FC<any> = ({ route, navigation }) => {
|
|
28
24
|
const { navigator } = useContext(ApplicationContext);
|
|
29
25
|
const context = useContext<any>(MiniAppContext);
|
|
@@ -42,7 +38,7 @@ const TabScreen: React.FC<any> = ({ route, navigation }) => {
|
|
|
42
38
|
transform: [{ scale: scale.value }],
|
|
43
39
|
}));
|
|
44
40
|
|
|
45
|
-
const
|
|
41
|
+
const onScreenNavigated = (pre: string, current: string) => {
|
|
46
42
|
if (!isBackgroundToForeground) {
|
|
47
43
|
const data: any = {
|
|
48
44
|
preScreenName: pre,
|
|
@@ -60,7 +56,7 @@ const TabScreen: React.FC<any> = ({ route, navigation }) => {
|
|
|
60
56
|
/**
|
|
61
57
|
* debug toast
|
|
62
58
|
*/
|
|
63
|
-
navigator?.
|
|
59
|
+
navigator?.maxApi?.showToastDebug?.({
|
|
64
60
|
appId: context.appId,
|
|
65
61
|
message: `${screenName} screen_navigated`,
|
|
66
62
|
type: 'ERROR',
|
|
@@ -75,10 +71,15 @@ const TabScreen: React.FC<any> = ({ route, navigation }) => {
|
|
|
75
71
|
scale.value = withTiming(1, { duration: 200 });
|
|
76
72
|
|
|
77
73
|
setTimeout(() => {
|
|
78
|
-
navigator?.
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
74
|
+
navigator?.maxApi?.getDataObserver?.(
|
|
75
|
+
'current_screen',
|
|
76
|
+
(data: any) => {
|
|
77
|
+
onScreenNavigated(data?.screenName, screenName);
|
|
78
|
+
navigator?.maxApi?.setObserver?.('current_screen', {
|
|
79
|
+
screenName,
|
|
80
|
+
});
|
|
81
|
+
},
|
|
82
|
+
);
|
|
82
83
|
}, 100);
|
|
83
84
|
|
|
84
85
|
return () => {
|
|
@@ -95,17 +96,22 @@ const TabScreen: React.FC<any> = ({ route, navigation }) => {
|
|
|
95
96
|
|
|
96
97
|
useEffect(
|
|
97
98
|
() => {
|
|
98
|
-
const
|
|
99
|
+
const onFocusApp = navigator?.maxApi?.listen?.('onFocusApp', () => {
|
|
99
100
|
if (navigation.isFocused()) {
|
|
100
|
-
navigator?.
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
101
|
+
navigator?.maxApi?.getDataObserver?.(
|
|
102
|
+
'current_screen',
|
|
103
|
+
(data: any) => {
|
|
104
|
+
onScreenNavigated(data?.screenName, screenName);
|
|
105
|
+
navigator?.maxApi?.setObserver?.('current_screen', {
|
|
106
|
+
screenName,
|
|
107
|
+
});
|
|
108
|
+
},
|
|
109
|
+
);
|
|
104
110
|
}
|
|
105
111
|
});
|
|
106
112
|
|
|
107
113
|
return () => {
|
|
108
|
-
|
|
114
|
+
onFocusApp?.remove?.();
|
|
109
115
|
};
|
|
110
116
|
},
|
|
111
117
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
@@ -185,7 +185,7 @@ const useLiquidSelection = ({
|
|
|
185
185
|
};
|
|
186
186
|
|
|
187
187
|
const tick = useCallback(() => {
|
|
188
|
-
callbacks.current.navigator?.
|
|
188
|
+
callbacks.current.navigator?.maxApi?.triggerEventVibration?.('light');
|
|
189
189
|
}, []);
|
|
190
190
|
|
|
191
191
|
const select = useCallback(
|
|
@@ -28,10 +28,6 @@ import { styles } from './index.styles';
|
|
|
28
28
|
|
|
29
29
|
const Tab = createBottomTabNavigator();
|
|
30
30
|
|
|
31
|
-
/**
|
|
32
|
-
* Pre-redesign app tab navigator with the docked phone bar; a tab press ticks a
|
|
33
|
-
* light haptic through the host binding.
|
|
34
|
-
*/
|
|
35
31
|
const BottomTab: React.FC<BottomTabProps> = ({
|
|
36
32
|
nested,
|
|
37
33
|
tabs,
|
|
@@ -104,7 +100,7 @@ const BottomTab: React.FC<BottomTabProps> = ({
|
|
|
104
100
|
state?: (e: any) => void;
|
|
105
101
|
} = {
|
|
106
102
|
tabPress: e => {
|
|
107
|
-
navigator?.
|
|
103
|
+
navigator?.maxApi?.triggerEventVibration?.('light');
|
|
108
104
|
listeners?.tabPress?.(e);
|
|
109
105
|
},
|
|
110
106
|
focus: e => {
|
|
@@ -150,7 +150,7 @@ const styles = StyleSheet.create({
|
|
|
150
150
|
height: TabBarMetrics.iconSize,
|
|
151
151
|
},
|
|
152
152
|
layer: {
|
|
153
|
-
...
|
|
153
|
+
...StyleSheet.absoluteFillObject,
|
|
154
154
|
alignItems: 'center',
|
|
155
155
|
justifyContent: 'center',
|
|
156
156
|
},
|
|
@@ -39,7 +39,7 @@ const TabScreen: React.FC<any> = ({ route, navigation }) => {
|
|
|
39
39
|
);
|
|
40
40
|
const tabInsetStyle = { paddingBottom: isInsetClaimed ? 0 : tabBarInset };
|
|
41
41
|
|
|
42
|
-
const handleScreenNavigated = (pre: string
|
|
42
|
+
const handleScreenNavigated = (pre: string, current: string) => {
|
|
43
43
|
if (!isBackgroundToForeground) {
|
|
44
44
|
const data: any = {
|
|
45
45
|
preScreenName: pre,
|
|
@@ -54,7 +54,7 @@ const TabScreen: React.FC<any> = ({ route, navigation }) => {
|
|
|
54
54
|
...data,
|
|
55
55
|
});
|
|
56
56
|
|
|
57
|
-
navigator?.
|
|
57
|
+
navigator?.maxApi?.showToastDebug?.({
|
|
58
58
|
appId: context.appId,
|
|
59
59
|
message: `${screenName} screen_navigated`,
|
|
60
60
|
type: 'ERROR',
|
|
@@ -66,10 +66,15 @@ const TabScreen: React.FC<any> = ({ route, navigation }) => {
|
|
|
66
66
|
React.useCallback(
|
|
67
67
|
() => {
|
|
68
68
|
setTimeout(() => {
|
|
69
|
-
navigator?.
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
69
|
+
navigator?.maxApi?.getDataObserver?.(
|
|
70
|
+
'current_screen',
|
|
71
|
+
(data: any) => {
|
|
72
|
+
handleScreenNavigated(data?.screenName, screenName);
|
|
73
|
+
navigator?.maxApi?.setObserver?.('current_screen', {
|
|
74
|
+
screenName,
|
|
75
|
+
});
|
|
76
|
+
},
|
|
77
|
+
);
|
|
73
78
|
}, NAVIGATED_REPORT_DELAY);
|
|
74
79
|
},
|
|
75
80
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
@@ -79,17 +84,22 @@ const TabScreen: React.FC<any> = ({ route, navigation }) => {
|
|
|
79
84
|
|
|
80
85
|
useEffect(
|
|
81
86
|
() => {
|
|
82
|
-
const focusAppListener = navigator?.
|
|
87
|
+
const focusAppListener = navigator?.maxApi?.listen?.('onFocusApp', () => {
|
|
83
88
|
if (navigation.isFocused()) {
|
|
84
|
-
navigator?.
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
89
|
+
navigator?.maxApi?.getDataObserver?.(
|
|
90
|
+
'current_screen',
|
|
91
|
+
(data: any) => {
|
|
92
|
+
handleScreenNavigated(data?.screenName, screenName);
|
|
93
|
+
navigator?.maxApi?.setObserver?.('current_screen', {
|
|
94
|
+
screenName,
|
|
95
|
+
});
|
|
96
|
+
},
|
|
97
|
+
);
|
|
88
98
|
}
|
|
89
99
|
});
|
|
90
100
|
|
|
91
101
|
return () => {
|
|
92
|
-
focusAppListener?.remove();
|
|
102
|
+
focusAppListener?.remove?.();
|
|
93
103
|
};
|
|
94
104
|
},
|
|
95
105
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
@@ -120,7 +120,7 @@ const FloatingBottomTab: React.FC<BottomTabProps> = ({
|
|
|
120
120
|
state?: (e: any) => void;
|
|
121
121
|
} = {
|
|
122
122
|
tabPress: e => {
|
|
123
|
-
navigator?.
|
|
123
|
+
navigator?.maxApi?.triggerEventVibration?.('light');
|
|
124
124
|
listeners?.tabPress?.(e);
|
|
125
125
|
},
|
|
126
126
|
focus: e => {
|
|
@@ -38,8 +38,8 @@ const HeaderLeft: React.FC<HeaderBackProps> = ({
|
|
|
38
38
|
|
|
39
39
|
if (canGoBack) {
|
|
40
40
|
navigator?.ref?.current?.goBack?.();
|
|
41
|
-
} else if (navigator) {
|
|
42
|
-
navigator
|
|
41
|
+
} else if (navigator?.maxApi) {
|
|
42
|
+
navigator?.maxApi?.dismiss?.(navigator?.dismissData);
|
|
43
43
|
} else {
|
|
44
44
|
(globalThis as any)?.miniAppApi?.dispatch?.('dismiss', context);
|
|
45
45
|
}
|
|
@@ -78,8 +78,8 @@ const SearchHeader = React.forwardRef<InputRef, SearchHeaderProps>(
|
|
|
78
78
|
|
|
79
79
|
if (canGoBack) {
|
|
80
80
|
navigator?.ref?.current?.goBack?.();
|
|
81
|
-
} else if (navigator) {
|
|
82
|
-
navigator
|
|
81
|
+
} else if (navigator?.maxApi) {
|
|
82
|
+
navigator?.maxApi?.dismiss?.(navigator?.dismissData);
|
|
83
83
|
} else {
|
|
84
84
|
(globalThis as any)?.miniAppApi?.dispatch?.('dismiss', context);
|
|
85
85
|
}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { useContext, useEffect, useState } from 'react';
|
|
1
|
+
import { useCallback, useContext, useEffect, useState } from 'react';
|
|
2
2
|
import { ApplicationContext, MiniAppContext } from '../../Context';
|
|
3
3
|
import { PopupNotify } from '../../Popup';
|
|
4
4
|
import { Tool, ToolGroup } from '../types';
|
|
5
5
|
|
|
6
|
+
const DID_SYNC_NEW_HOME = 'did_sync_new_home';
|
|
6
7
|
const LOADING_RESET_DELAY = 1000;
|
|
7
8
|
|
|
8
9
|
type ToolkitActionsParams = {
|
|
@@ -32,28 +33,42 @@ const useToolkitActions = ({
|
|
|
32
33
|
const [isFavorite, setIsFavorite] = useState<boolean>(false);
|
|
33
34
|
const [isLoading, setIsLoading] = useState(false);
|
|
34
35
|
|
|
35
|
-
const
|
|
36
|
-
|
|
36
|
+
const checkAppIsFavorite = useCallback(() => {
|
|
37
|
+
return navigator?.maxApi?.dispatchFunction?.(
|
|
38
|
+
'isFavoriteApp',
|
|
39
|
+
{ code: context?.code },
|
|
40
|
+
(result: boolean) => {
|
|
41
|
+
setIsFavorite(result);
|
|
42
|
+
},
|
|
43
|
+
);
|
|
44
|
+
}, [context?.code, navigator?.maxApi]);
|
|
37
45
|
|
|
38
46
|
useEffect(() => {
|
|
39
|
-
if (
|
|
40
|
-
|
|
47
|
+
if (useShortcut) {
|
|
48
|
+
checkAppIsFavorite();
|
|
49
|
+
|
|
50
|
+
const favoriteObserver = navigator?.maxApi?.observer?.(
|
|
51
|
+
DID_SYNC_NEW_HOME,
|
|
52
|
+
(updatedData: any) => {
|
|
53
|
+
const isInFavorites = updatedData?.items?.includes(context?.code);
|
|
54
|
+
setIsFavorite(isInFavorites);
|
|
55
|
+
},
|
|
56
|
+
);
|
|
57
|
+
return () => {
|
|
58
|
+
favoriteObserver?.remove?.();
|
|
59
|
+
};
|
|
41
60
|
}
|
|
42
|
-
|
|
43
|
-
const favoriteObserver = binding.observeFavorites(appCodes => {
|
|
44
|
-
setIsFavorite(appCodes.includes(appCode));
|
|
45
|
-
});
|
|
46
|
-
return () => {
|
|
47
|
-
request.cancel();
|
|
48
|
-
favoriteObserver.remove();
|
|
49
|
-
};
|
|
50
|
-
}, [useShortcut, appCode, binding]);
|
|
61
|
+
}, [useShortcut, context, checkAppIsFavorite, navigator?.maxApi]);
|
|
51
62
|
|
|
52
63
|
const handleDismiss = () => {
|
|
53
64
|
if (useCloseIcon) {
|
|
54
|
-
|
|
65
|
+
navigator?.maxApi?.dispatchFunction?.(
|
|
66
|
+
'dismiss',
|
|
67
|
+
navigator?.dismissData,
|
|
68
|
+
undefined,
|
|
69
|
+
);
|
|
55
70
|
} else {
|
|
56
|
-
|
|
71
|
+
navigator?.maxApi?.dispatchFunction?.('dismissAll');
|
|
57
72
|
}
|
|
58
73
|
};
|
|
59
74
|
|
|
@@ -96,7 +111,20 @@ const useToolkitActions = ({
|
|
|
96
111
|
screenName: currentRoute?.params?.screen?.name ?? currentRoute?.name,
|
|
97
112
|
});
|
|
98
113
|
setIsLoading(true);
|
|
99
|
-
|
|
114
|
+
navigator?.maxApi?.dispatchFunction?.(
|
|
115
|
+
'onToolAction',
|
|
116
|
+
{
|
|
117
|
+
item: {
|
|
118
|
+
key: 'onFavorite',
|
|
119
|
+
},
|
|
120
|
+
context,
|
|
121
|
+
},
|
|
122
|
+
({ success }: { success: boolean }) => {
|
|
123
|
+
if (success) {
|
|
124
|
+
setIsFavorite(shouldBeFavorite);
|
|
125
|
+
}
|
|
126
|
+
},
|
|
127
|
+
);
|
|
100
128
|
setTimeout(() => {
|
|
101
129
|
setIsLoading(false);
|
|
102
130
|
}, LOADING_RESET_DELAY);
|
|
@@ -111,13 +139,7 @@ const useToolkitActions = ({
|
|
|
111
139
|
screenName: currentRoute?.params?.screen?.name ?? currentRoute?.name,
|
|
112
140
|
});
|
|
113
141
|
|
|
114
|
-
|
|
115
|
-
appId: context?.appId,
|
|
116
|
-
code: appCode,
|
|
117
|
-
name: context?.name,
|
|
118
|
-
icon: context?.icon,
|
|
119
|
-
description: context?.description,
|
|
120
|
-
});
|
|
142
|
+
navigator?.maxApi?.dispatchFunction?.('showHelpCenter', context);
|
|
121
143
|
};
|
|
122
144
|
|
|
123
145
|
const handlePressIconMore = () => {
|
|
@@ -129,17 +151,25 @@ const useToolkitActions = ({
|
|
|
129
151
|
screenName: currentRoute?.params?.screen?.name ?? currentRoute?.name,
|
|
130
152
|
});
|
|
131
153
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
154
|
+
navigator?.maxApi?.dispatchFunction?.(
|
|
155
|
+
'showTools',
|
|
156
|
+
{
|
|
157
|
+
useSystemTools,
|
|
158
|
+
tools,
|
|
159
|
+
context,
|
|
160
|
+
},
|
|
161
|
+
(key: string) => {
|
|
162
|
+
for (const group of tools) {
|
|
163
|
+
const pressedTool = group?.items?.find?.(
|
|
164
|
+
(tool: Tool) => tool?.key === key,
|
|
165
|
+
);
|
|
166
|
+
if (pressedTool) {
|
|
167
|
+
pressedTool?.onPress();
|
|
168
|
+
break;
|
|
169
|
+
}
|
|
140
170
|
}
|
|
141
|
-
}
|
|
142
|
-
|
|
171
|
+
},
|
|
172
|
+
);
|
|
143
173
|
};
|
|
144
174
|
|
|
145
175
|
let iconShortcut = isFavorite ? 'pin_star_checked' : 'pin_star';
|
|
@@ -66,7 +66,7 @@ const Modal: React.FC<ModalParams> = props => {
|
|
|
66
66
|
|
|
67
67
|
// Auto-tracks the popup as displayed on the current screen.
|
|
68
68
|
useEffect(() => {
|
|
69
|
-
navigator?.
|
|
69
|
+
navigator?.maxApi?.getDataObserver?.('current_screen', (curScreen: any) => {
|
|
70
70
|
context.autoTracking({
|
|
71
71
|
...context,
|
|
72
72
|
screenName: curScreen?.screenName,
|
|
@@ -75,7 +75,7 @@ const Modal: React.FC<ModalParams> = props => {
|
|
|
75
75
|
title,
|
|
76
76
|
});
|
|
77
77
|
});
|
|
78
|
-
}, [context, description, navigator?.
|
|
78
|
+
}, [context, description, navigator?.maxApi, title]);
|
|
79
79
|
|
|
80
80
|
const opacity = useRef(new Animated.Value(0)).current;
|
|
81
81
|
const scale = useRef(new Animated.Value(INITIAL_SCALE)).current;
|
|
@@ -161,7 +161,7 @@ const Modal: React.FC<ModalParams> = props => {
|
|
|
161
161
|
transparent
|
|
162
162
|
visible={true}
|
|
163
163
|
onRequestClose={handleDismiss}
|
|
164
|
-
style={StyleSheet.
|
|
164
|
+
style={StyleSheet.absoluteFillObject}
|
|
165
165
|
isModalKit={true}
|
|
166
166
|
supportedOrientations={isDuo ? DUO_ORIENTATIONS : undefined}
|
|
167
167
|
>
|
|
@@ -170,7 +170,7 @@ const Modal: React.FC<ModalParams> = props => {
|
|
|
170
170
|
behavior={Platform.OS === 'ios' ? 'padding' : undefined}
|
|
171
171
|
>
|
|
172
172
|
<Pressable
|
|
173
|
-
style={StyleSheet.
|
|
173
|
+
style={StyleSheet.absoluteFillObject}
|
|
174
174
|
onPress={() => handleDismiss(undefined, barrierDismissible)}
|
|
175
175
|
>
|
|
176
176
|
<Animated.View style={[styles.overlayContent, scrimStyle]} />
|
|
@@ -18,7 +18,7 @@ import ModalScreen from './ModalScreen';
|
|
|
18
18
|
import Navigator from './Navigator';
|
|
19
19
|
import { getModalOptions, getStackOptions } from './navigationOptions';
|
|
20
20
|
import { isWhiteListDesignSystem } from './utils';
|
|
21
|
-
import {
|
|
21
|
+
import { useNativeCanGoBack } from './hooks';
|
|
22
22
|
import { NavigationContainerProps } from './types';
|
|
23
23
|
import { ApplicationContext, MiniAppContext } from '../Context';
|
|
24
24
|
import Localize from './Localize';
|
|
@@ -34,14 +34,14 @@ import { ReservedRegionsProvider } from '../Layout/ReservedRegions';
|
|
|
34
34
|
const Stack = createStackNavigator();
|
|
35
35
|
|
|
36
36
|
/**
|
|
37
|
-
* Root of a mini app: safe area, reserved regions
|
|
38
|
-
*
|
|
37
|
+
* Root of a mini app: safe area, reserved regions and the merged mini app
|
|
38
|
+
* context around the kit's navigator.
|
|
39
39
|
*/
|
|
40
40
|
const NavigationContainer: React.FC<NavigationContainerProps> = ({
|
|
41
41
|
screen,
|
|
42
42
|
theme = defaultTheme,
|
|
43
43
|
options,
|
|
44
|
-
|
|
44
|
+
maxApi,
|
|
45
45
|
initialParams,
|
|
46
46
|
localize = new Localize({ vi: {}, en: {} }),
|
|
47
47
|
features = {
|
|
@@ -53,14 +53,13 @@ const NavigationContainer: React.FC<NavigationContainerProps> = ({
|
|
|
53
53
|
}) => {
|
|
54
54
|
const context = useContext<any>(MiniAppContext);
|
|
55
55
|
const [currentContext, setCurrentContext] = useState<any>({});
|
|
56
|
-
const resolved = useKitsBinding(binding);
|
|
57
56
|
|
|
58
57
|
useEffect(() => {
|
|
59
|
-
const sub =
|
|
58
|
+
const sub = maxApi?.observer?.('font_scale_config', (data: any) => {
|
|
60
59
|
setCurrentContext((prev: any) => ({ ...prev, fontScale: data }));
|
|
61
60
|
});
|
|
62
|
-
return () => sub
|
|
63
|
-
}, [
|
|
61
|
+
return () => sub?.remove?.();
|
|
62
|
+
}, [maxApi]);
|
|
64
63
|
|
|
65
64
|
const mergedContext = {
|
|
66
65
|
...context,
|
|
@@ -86,7 +85,7 @@ const NavigationContainer: React.FC<NavigationContainerProps> = ({
|
|
|
86
85
|
screen={screen}
|
|
87
86
|
theme={theme}
|
|
88
87
|
options={options}
|
|
89
|
-
|
|
88
|
+
maxApi={maxApi}
|
|
90
89
|
setCurrentContext={setCurrentContext}
|
|
91
90
|
initialParams={initialParams}
|
|
92
91
|
localize={localize}
|
|
@@ -105,7 +104,7 @@ const Navigation: React.FC<any> = ({
|
|
|
105
104
|
screen,
|
|
106
105
|
theme = defaultTheme,
|
|
107
106
|
options,
|
|
108
|
-
|
|
107
|
+
maxApi,
|
|
109
108
|
initialParams,
|
|
110
109
|
setCurrentContext,
|
|
111
110
|
localize = new Localize({ vi: {}, en: {} }),
|
|
@@ -132,7 +131,7 @@ const Navigation: React.FC<any> = ({
|
|
|
132
131
|
headerGradient = context?.designSystemConfig?.config?.headerGradient;
|
|
133
132
|
}
|
|
134
133
|
|
|
135
|
-
navigator.current.
|
|
134
|
+
navigator.current.maxApi = maxApi;
|
|
136
135
|
|
|
137
136
|
/** Text for a localization key, or the current-language side of `{ vi, en }`. */
|
|
138
137
|
const translate = (data?: string | { vi: string; en: string }) => {
|
package/Application/Navigator.ts
CHANGED
|
@@ -1,9 +1,5 @@
|
|
|
1
1
|
import {CommonActions, StackActions} from '@react-navigation/native';
|
|
2
2
|
import {BottomSheetParams, ModalParams, ScreenParams} from './types';
|
|
3
|
-
import { resolveKitsBinding } from './KitsHost';
|
|
4
|
-
import type { ResolvedKitsBinding } from './types.binding';
|
|
5
|
-
|
|
6
|
-
const HOST_BINDING = resolveKitsBinding();
|
|
7
3
|
|
|
8
4
|
/**
|
|
9
5
|
* Imperative navigation API exposed to features through `ApplicationContext`.
|
|
@@ -13,8 +9,7 @@ class Navigator {
|
|
|
13
9
|
ref?: any;
|
|
14
10
|
isReady?: any;
|
|
15
11
|
isWidget?: any;
|
|
16
|
-
|
|
17
|
-
binding: ResolvedKitsBinding = HOST_BINDING;
|
|
12
|
+
maxApi?: any;
|
|
18
13
|
dismissData?: any;
|
|
19
14
|
|
|
20
15
|
constructor(navigation: any, isReady: any, isWidget = false) {
|
|
@@ -126,7 +121,7 @@ class Navigator {
|
|
|
126
121
|
}
|
|
127
122
|
};
|
|
128
123
|
|
|
129
|
-
/** Sets the payload the header passes to `
|
|
124
|
+
/** Sets the payload the header passes to `maxApi.dismiss` on close. */
|
|
130
125
|
setDismissData = (data: any) => {
|
|
131
126
|
this.dismissData = data;
|
|
132
127
|
};
|
|
@@ -1,27 +1,13 @@
|
|
|
1
1
|
import { Alert } from 'react-native';
|
|
2
2
|
import { version } from '../package.json';
|
|
3
|
-
import type { NavigatorProps } from './types';
|
|
4
|
-
|
|
5
|
-
const MS_PER_SECOND = 1000;
|
|
6
3
|
|
|
7
4
|
type ScreenTrackingDeps = {
|
|
8
5
|
tracking: { current: any };
|
|
9
6
|
context: any;
|
|
10
|
-
navigator
|
|
7
|
+
navigator: any;
|
|
11
8
|
screenName: string;
|
|
12
9
|
};
|
|
13
10
|
|
|
14
|
-
/** Ends a host performance trace; skipped when the host never returned an id. */
|
|
15
|
-
const stopTrace = (
|
|
16
|
-
navigator: NavigatorProps | undefined,
|
|
17
|
-
traceId: string | undefined,
|
|
18
|
-
durationMs: number,
|
|
19
|
-
) => {
|
|
20
|
-
if (traceId) {
|
|
21
|
-
navigator?.binding.stopTrace(traceId, durationMs / MS_PER_SECOND);
|
|
22
|
-
}
|
|
23
|
-
};
|
|
24
|
-
|
|
25
11
|
/**
|
|
26
12
|
* Auto-tracking reporters of a stack screen. Each event fires at most once per
|
|
27
13
|
* screen, guarded by the `release*` flags on `tracking.current`.
|
|
@@ -51,10 +37,14 @@ export const createScreenTracking = ({
|
|
|
51
37
|
version: version,
|
|
52
38
|
lastElement: tracking.current.lastElement,
|
|
53
39
|
});
|
|
54
|
-
stopTrace(
|
|
40
|
+
navigator?.maxApi?.stopTrace?.(
|
|
41
|
+
tracking.current.traceIdLoad,
|
|
42
|
+
{ value: timeLoad / 1000 },
|
|
43
|
+
null,
|
|
44
|
+
);
|
|
55
45
|
tracking.current.releaseLoad = true;
|
|
56
46
|
|
|
57
|
-
navigator?.
|
|
47
|
+
navigator?.maxApi?.showToastDebug?.({
|
|
58
48
|
appId: context.appId,
|
|
59
49
|
message: `${screenName} screen_load_time ${timeLoad}`,
|
|
60
50
|
type: 'ERROR',
|
|
@@ -90,14 +80,14 @@ export const createScreenTracking = ({
|
|
|
90
80
|
params: tracking.current.params,
|
|
91
81
|
version: version,
|
|
92
82
|
});
|
|
93
|
-
stopTrace(
|
|
94
|
-
navigator,
|
|
83
|
+
navigator?.maxApi?.stopTrace?.(
|
|
95
84
|
tracking.current.traceIdInteraction,
|
|
96
|
-
tracking.current.timeInteraction,
|
|
85
|
+
{ value: tracking.current.timeInteraction / 1000 },
|
|
86
|
+
null,
|
|
97
87
|
);
|
|
98
88
|
tracking.current.releaseInteraction = true;
|
|
99
89
|
|
|
100
|
-
navigator?.
|
|
90
|
+
navigator?.maxApi?.showToastDebug?.({
|
|
101
91
|
appId: context.appId,
|
|
102
92
|
message: `${screenName} screen_interaction_time ${tracking.current.timeInteraction}`,
|
|
103
93
|
type: 'ERROR',
|
|
@@ -119,7 +109,7 @@ export const createScreenTracking = ({
|
|
|
119
109
|
});
|
|
120
110
|
tracking.current.releaseUserInteraction = true;
|
|
121
111
|
|
|
122
|
-
navigator?.
|
|
112
|
+
navigator?.maxApi?.showToastDebug?.({
|
|
123
113
|
appId: context.appId,
|
|
124
114
|
message: `${screenName} user_interaction ${timeLoad}`,
|
|
125
115
|
type: 'ERROR',
|