@momo-kits/foundation 0.169.16-beta.4 → 0.169.16-beta.6
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 +16 -22
- package/Application/BottomTab/Legacy/hooks.ts +1 -1
- package/Application/BottomTab/Legacy/index.tsx +5 -1
- package/Application/BottomTab/TabBarIcon.tsx +1 -1
- package/Application/BottomTab/TabScreen.tsx +12 -22
- package/Application/BottomTab/index.tsx +1 -1
- package/Application/Components/HeaderLeft.tsx +11 -7
- package/Application/Components/HeaderRight.styles.ts +5 -1
- package/Application/Components/HeaderRight.tsx +7 -21
- package/Application/Components/SearchHeader.tsx +2 -2
- package/Application/Components/SwipeBackHaptic.tsx +1 -1
- package/Application/Components/useHeaderRightWidth.ts +2 -2
- package/Application/Components/useToolkitActions.tsx +34 -64
- package/Application/KitsBindingProvider.tsx +22 -0
- package/Application/KitsHost.ts +182 -0
- package/Application/ModalScreen.tsx +4 -4
- package/Application/NavigationContainer.tsx +22 -18
- package/Application/Navigator.ts +7 -2
- package/Application/StackScreen.tracking.ts +22 -12
- package/Application/StackScreen.tsx +26 -34
- package/Application/TooltipPortal.tsx +3 -3
- package/Application/WidgetContainer.tsx +83 -77
- package/Application/__tests__/KitsHost.test.ts +76 -0
- package/Application/headerLayout.ts +6 -13
- package/Application/hooks.ts +16 -1
- package/Application/index.ts +4 -0
- package/Application/navigationOptions.tsx +5 -12
- package/Application/types.binding.ts +134 -0
- package/Application/types.ts +14 -3
- 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 +1 -2
- package/Image/index.tsx +62 -7
- package/Image/styles.ts +2 -0
- package/Image/types.ts +9 -1
- package/Input/Input.tsx +2 -2
- package/Input/InputMoney.tsx +7 -2
- 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 +2 -1
- package/Input/TextTyping.tsx +7 -2
- package/Layout/screenHeader.tsx +15 -17
- package/Pagination/types.ts +6 -2
- package/package.json +28 -26
|
@@ -215,7 +215,7 @@ const BottomSheet: React.FC<BottomSheetParams> = props => {
|
|
|
215
215
|
onRequestClose={() => {
|
|
216
216
|
handleDismiss();
|
|
217
217
|
}}
|
|
218
|
-
style={StyleSheet.
|
|
218
|
+
style={StyleSheet.absoluteFill}
|
|
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.absoluteFill}
|
|
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
|
+
...{position: 'absolute', top: 0, bottom: 0, left: 0, right: 0},
|
|
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
|
+
...{position: 'absolute', top: 0, bottom: 0, left: 0, right: 0},
|
|
61
61
|
alignItems: 'center',
|
|
62
62
|
justifyContent: 'center',
|
|
63
63
|
},
|
|
@@ -20,6 +20,10 @@ 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
|
+
*/
|
|
23
27
|
const TabScreen: React.FC<any> = ({ route, navigation }) => {
|
|
24
28
|
const { navigator } = useContext(ApplicationContext);
|
|
25
29
|
const context = useContext<any>(MiniAppContext);
|
|
@@ -38,7 +42,7 @@ const TabScreen: React.FC<any> = ({ route, navigation }) => {
|
|
|
38
42
|
transform: [{ scale: scale.value }],
|
|
39
43
|
}));
|
|
40
44
|
|
|
41
|
-
const
|
|
45
|
+
const handleScreenNavigated = (pre: string | undefined, current: string) => {
|
|
42
46
|
if (!isBackgroundToForeground) {
|
|
43
47
|
const data: any = {
|
|
44
48
|
preScreenName: pre,
|
|
@@ -56,7 +60,7 @@ const TabScreen: React.FC<any> = ({ route, navigation }) => {
|
|
|
56
60
|
/**
|
|
57
61
|
* debug toast
|
|
58
62
|
*/
|
|
59
|
-
navigator?.
|
|
63
|
+
navigator?.binding.showToastDebug({
|
|
60
64
|
appId: context.appId,
|
|
61
65
|
message: `${screenName} screen_navigated`,
|
|
62
66
|
type: 'ERROR',
|
|
@@ -71,15 +75,10 @@ const TabScreen: React.FC<any> = ({ route, navigation }) => {
|
|
|
71
75
|
scale.value = withTiming(1, { duration: 200 });
|
|
72
76
|
|
|
73
77
|
setTimeout(() => {
|
|
74
|
-
navigator?.
|
|
75
|
-
|
|
76
|
-
(
|
|
77
|
-
|
|
78
|
-
navigator?.maxApi?.setObserver?.('current_screen', {
|
|
79
|
-
screenName,
|
|
80
|
-
});
|
|
81
|
-
},
|
|
82
|
-
);
|
|
78
|
+
navigator?.binding.getCurrentScreen(data => {
|
|
79
|
+
handleScreenNavigated(data?.screenName, screenName);
|
|
80
|
+
navigator?.binding.setCurrentScreen({ screenName });
|
|
81
|
+
});
|
|
83
82
|
}, 100);
|
|
84
83
|
|
|
85
84
|
return () => {
|
|
@@ -96,22 +95,17 @@ const TabScreen: React.FC<any> = ({ route, navigation }) => {
|
|
|
96
95
|
|
|
97
96
|
useEffect(
|
|
98
97
|
() => {
|
|
99
|
-
const
|
|
98
|
+
const focusAppListener = navigator?.binding.onFocusApp(() => {
|
|
100
99
|
if (navigation.isFocused()) {
|
|
101
|
-
navigator?.
|
|
102
|
-
|
|
103
|
-
(
|
|
104
|
-
|
|
105
|
-
navigator?.maxApi?.setObserver?.('current_screen', {
|
|
106
|
-
screenName,
|
|
107
|
-
});
|
|
108
|
-
},
|
|
109
|
-
);
|
|
100
|
+
navigator?.binding.getCurrentScreen(data => {
|
|
101
|
+
handleScreenNavigated(data?.screenName, screenName);
|
|
102
|
+
navigator?.binding.setCurrentScreen({ screenName });
|
|
103
|
+
});
|
|
110
104
|
}
|
|
111
105
|
});
|
|
112
106
|
|
|
113
107
|
return () => {
|
|
114
|
-
|
|
108
|
+
focusAppListener?.remove();
|
|
115
109
|
};
|
|
116
110
|
},
|
|
117
111
|
// 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?.binding.vibrateLight();
|
|
189
189
|
}, []);
|
|
190
190
|
|
|
191
191
|
const select = useCallback(
|
|
@@ -28,6 +28,10 @@ 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
|
+
*/
|
|
31
35
|
const BottomTab: React.FC<BottomTabProps> = ({
|
|
32
36
|
nested,
|
|
33
37
|
tabs,
|
|
@@ -100,7 +104,7 @@ const BottomTab: React.FC<BottomTabProps> = ({
|
|
|
100
104
|
state?: (e: any) => void;
|
|
101
105
|
} = {
|
|
102
106
|
tabPress: e => {
|
|
103
|
-
navigator?.
|
|
107
|
+
navigator?.binding.vibrateLight();
|
|
104
108
|
listeners?.tabPress?.(e);
|
|
105
109
|
},
|
|
106
110
|
focus: e => {
|
|
@@ -150,7 +150,7 @@ const styles = StyleSheet.create({
|
|
|
150
150
|
height: TabBarMetrics.iconSize,
|
|
151
151
|
},
|
|
152
152
|
layer: {
|
|
153
|
-
...
|
|
153
|
+
...{position: 'absolute', top: 0, bottom: 0, left: 0, right: 0},
|
|
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, current: string) => {
|
|
42
|
+
const handleScreenNavigated = (pre: string | undefined, 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?.binding.showToastDebug({
|
|
58
58
|
appId: context.appId,
|
|
59
59
|
message: `${screenName} screen_navigated`,
|
|
60
60
|
type: 'ERROR',
|
|
@@ -66,15 +66,10 @@ const TabScreen: React.FC<any> = ({ route, navigation }) => {
|
|
|
66
66
|
React.useCallback(
|
|
67
67
|
() => {
|
|
68
68
|
setTimeout(() => {
|
|
69
|
-
navigator?.
|
|
70
|
-
|
|
71
|
-
(
|
|
72
|
-
|
|
73
|
-
navigator?.maxApi?.setObserver?.('current_screen', {
|
|
74
|
-
screenName,
|
|
75
|
-
});
|
|
76
|
-
},
|
|
77
|
-
);
|
|
69
|
+
navigator?.binding.getCurrentScreen(data => {
|
|
70
|
+
handleScreenNavigated(data?.screenName, screenName);
|
|
71
|
+
navigator?.binding.setCurrentScreen({ screenName });
|
|
72
|
+
});
|
|
78
73
|
}, NAVIGATED_REPORT_DELAY);
|
|
79
74
|
},
|
|
80
75
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
@@ -84,22 +79,17 @@ const TabScreen: React.FC<any> = ({ route, navigation }) => {
|
|
|
84
79
|
|
|
85
80
|
useEffect(
|
|
86
81
|
() => {
|
|
87
|
-
const focusAppListener = navigator?.
|
|
82
|
+
const focusAppListener = navigator?.binding.onFocusApp(() => {
|
|
88
83
|
if (navigation.isFocused()) {
|
|
89
|
-
navigator?.
|
|
90
|
-
|
|
91
|
-
(
|
|
92
|
-
|
|
93
|
-
navigator?.maxApi?.setObserver?.('current_screen', {
|
|
94
|
-
screenName,
|
|
95
|
-
});
|
|
96
|
-
},
|
|
97
|
-
);
|
|
84
|
+
navigator?.binding.getCurrentScreen(data => {
|
|
85
|
+
handleScreenNavigated(data?.screenName, screenName);
|
|
86
|
+
navigator?.binding.setCurrentScreen({ screenName });
|
|
87
|
+
});
|
|
98
88
|
}
|
|
99
89
|
});
|
|
100
90
|
|
|
101
91
|
return () => {
|
|
102
|
-
focusAppListener?.remove
|
|
92
|
+
focusAppListener?.remove();
|
|
103
93
|
};
|
|
104
94
|
},
|
|
105
95
|
// 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?.binding.vibrateLight();
|
|
124
124
|
listeners?.tabPress?.(e);
|
|
125
125
|
},
|
|
126
126
|
focus: e => {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BackHandler,
|
|
1
|
+
import { BackHandler, StyleSheet, View } from 'react-native';
|
|
2
2
|
import type { HeaderBackProps } from '../types';
|
|
3
3
|
import React, { useCallback, useContext, useEffect } from 'react';
|
|
4
4
|
import { ApplicationContext, MiniAppContext } from '../../Context';
|
|
@@ -8,12 +8,11 @@ import { SideBarButton } from './SideBarButton';
|
|
|
8
8
|
import Animated from 'react-native-reanimated';
|
|
9
9
|
import { useSideBarItemStyle } from '../../Layout/utils';
|
|
10
10
|
import { useSideBarCounterStyle } from './DuoQuickReturnHeader';
|
|
11
|
-
import {
|
|
11
|
+
import { HeaderBarMetrics } from '../headerLayout';
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* Header back button, also bound to the Android hardware back. `preventBack`
|
|
15
15
|
* confirms in a popup first; the iPhone Duo side bar uses the 48pt side bar button.
|
|
16
|
-
* In the bar it sits `sidePadding` from the window edge on every iPhone width.
|
|
17
16
|
*/
|
|
18
17
|
const HeaderLeft: React.FC<HeaderBackProps> = ({
|
|
19
18
|
tintColor,
|
|
@@ -26,7 +25,6 @@ const HeaderLeft: React.FC<HeaderBackProps> = ({
|
|
|
26
25
|
const { navigator } = useContext(ApplicationContext);
|
|
27
26
|
const sideBarStyle = useSideBarItemStyle('left', 0);
|
|
28
27
|
const counterStyle = useSideBarCounterStyle();
|
|
29
|
-
const { width } = useWindowDimensions();
|
|
30
28
|
|
|
31
29
|
const goBack = useCallback(() => {
|
|
32
30
|
const canGoBack = navigator?.ref?.current?.canGoBack?.();
|
|
@@ -40,8 +38,8 @@ const HeaderLeft: React.FC<HeaderBackProps> = ({
|
|
|
40
38
|
|
|
41
39
|
if (canGoBack) {
|
|
42
40
|
navigator?.ref?.current?.goBack?.();
|
|
43
|
-
} else if (navigator
|
|
44
|
-
navigator
|
|
41
|
+
} else if (navigator) {
|
|
42
|
+
navigator.binding.dismiss('current', navigator.dismissData);
|
|
45
43
|
} else {
|
|
46
44
|
(globalThis as any)?.miniAppApi?.dispatch?.('dismiss', context);
|
|
47
45
|
}
|
|
@@ -100,7 +98,7 @@ const HeaderLeft: React.FC<HeaderBackProps> = ({
|
|
|
100
98
|
}
|
|
101
99
|
|
|
102
100
|
return (
|
|
103
|
-
<View style={
|
|
101
|
+
<View style={styles.headerLeft}>
|
|
104
102
|
<NavigationButton
|
|
105
103
|
accessibilityLabel="btn_navigation_back"
|
|
106
104
|
icon="arrow-back"
|
|
@@ -111,4 +109,10 @@ const HeaderLeft: React.FC<HeaderBackProps> = ({
|
|
|
111
109
|
);
|
|
112
110
|
};
|
|
113
111
|
|
|
112
|
+
const styles = StyleSheet.create({
|
|
113
|
+
headerLeft: {
|
|
114
|
+
marginLeft: HeaderBarMetrics.sidePadding,
|
|
115
|
+
},
|
|
116
|
+
});
|
|
117
|
+
|
|
114
118
|
export { HeaderLeft };
|
|
@@ -2,7 +2,7 @@ import { Platform, StyleSheet } from 'react-native';
|
|
|
2
2
|
import { Colors, Spacing } from '../../Consts';
|
|
3
3
|
import { HeaderBarMetrics } from '../headerLayout';
|
|
4
4
|
|
|
5
|
-
const { buttonSize, pillWidth, pillHeight } = HeaderBarMetrics;
|
|
5
|
+
const { buttonSize, pillWidth, pillHeight, sidePadding } = HeaderBarMetrics;
|
|
6
6
|
|
|
7
7
|
export const styles = StyleSheet.create({
|
|
8
8
|
navigationButton: {
|
|
@@ -48,6 +48,7 @@ export const styles = StyleSheet.create({
|
|
|
48
48
|
flexDirection: 'row',
|
|
49
49
|
justifyContent: 'center',
|
|
50
50
|
alignItems: 'center',
|
|
51
|
+
paddingRight: sidePadding,
|
|
51
52
|
},
|
|
52
53
|
toolkitContainer: {
|
|
53
54
|
height: pillHeight,
|
|
@@ -133,6 +134,9 @@ export const styles = StyleSheet.create({
|
|
|
133
134
|
},
|
|
134
135
|
}),
|
|
135
136
|
},
|
|
137
|
+
onBoarding: {
|
|
138
|
+
marginRight: Spacing.M,
|
|
139
|
+
},
|
|
136
140
|
toolkitWide: {
|
|
137
141
|
width: pillWidth,
|
|
138
142
|
},
|
|
@@ -1,16 +1,10 @@
|
|
|
1
1
|
import React, { useCallback, useContext, useEffect } from 'react';
|
|
2
|
-
import {
|
|
3
|
-
type LayoutChangeEvent,
|
|
4
|
-
TouchableOpacity,
|
|
5
|
-
useWindowDimensions,
|
|
6
|
-
View,
|
|
7
|
-
} from 'react-native';
|
|
2
|
+
import { type LayoutChangeEvent, TouchableOpacity, View } from 'react-native';
|
|
8
3
|
import { NavigationRouteContext } from '@react-navigation/native';
|
|
9
4
|
import { ApplicationContext } from '../../Context';
|
|
10
5
|
import { Text } from '../../Text';
|
|
11
6
|
import Animated from 'react-native-reanimated';
|
|
12
|
-
import {
|
|
13
|
-
import { getHeaderRowInset } from '../headerLayout';
|
|
7
|
+
import { useSideBarItemStyle } from '../../Layout/utils';
|
|
14
8
|
import { useSideBarCounterStyle } from './DuoQuickReturnHeader';
|
|
15
9
|
import { HeaderToolkitAction } from './HeaderToolkitAction';
|
|
16
10
|
import { styles } from './HeaderRight.styles';
|
|
@@ -19,8 +13,7 @@ import { setHeaderRightWidth } from './useHeaderRightWidth';
|
|
|
19
13
|
/**
|
|
20
14
|
* Header right slot: a custom `headerRight` render function, the onboarding skip
|
|
21
15
|
* button, or the toolkit (stacked vertically in the floating iPhone Duo side bar).
|
|
22
|
-
* The bar toolkit
|
|
23
|
-
* from that edge so header searches stop short of it.
|
|
16
|
+
* The bar toolkit reports its width so header searches stop short of it.
|
|
24
17
|
*/
|
|
25
18
|
const HeaderRight: React.FC<any> = props => {
|
|
26
19
|
const { translate } = useContext(ApplicationContext);
|
|
@@ -29,18 +22,14 @@ const HeaderRight: React.FC<any> = props => {
|
|
|
29
22
|
const sideBarStyle = useSideBarItemStyle('right', 1);
|
|
30
23
|
const counterStyle = useSideBarCounterStyle();
|
|
31
24
|
const routeKey = useContext(NavigationRouteContext)?.key;
|
|
32
|
-
const { width } = useWindowDimensions();
|
|
33
|
-
const rowMargin = getHeaderMargin(width);
|
|
34
|
-
const rowInset = getHeaderRowInset(width);
|
|
35
25
|
|
|
36
26
|
const handleToolkitLayout = useCallback(
|
|
37
27
|
(event: LayoutChangeEvent) => {
|
|
38
28
|
if (routeKey) {
|
|
39
|
-
|
|
40
|
-
setHeaderRightWidth(routeKey, toolkitWidth);
|
|
29
|
+
setHeaderRightWidth(routeKey, event.nativeEvent.layout.width);
|
|
41
30
|
}
|
|
42
31
|
},
|
|
43
|
-
[routeKey
|
|
32
|
+
[routeKey],
|
|
44
33
|
);
|
|
45
34
|
|
|
46
35
|
useEffect(() => {
|
|
@@ -57,7 +46,7 @@ const HeaderRight: React.FC<any> = props => {
|
|
|
57
46
|
|
|
58
47
|
if (useOnBoarding && onPress) {
|
|
59
48
|
return (
|
|
60
|
-
<TouchableOpacity onPress={onPress} style={
|
|
49
|
+
<TouchableOpacity onPress={onPress} style={styles.onBoarding}>
|
|
61
50
|
<Text typography={'action_s_bold'}>
|
|
62
51
|
{buttonOnBoarding || translate?.('skip')}
|
|
63
52
|
</Text>
|
|
@@ -81,10 +70,7 @@ const HeaderRight: React.FC<any> = props => {
|
|
|
81
70
|
}
|
|
82
71
|
|
|
83
72
|
return (
|
|
84
|
-
<View
|
|
85
|
-
style={[styles.headerRightButton, { paddingRight: rowInset }]}
|
|
86
|
-
onLayout={handleToolkitLayout}
|
|
87
|
-
>
|
|
73
|
+
<View style={styles.headerRightButton} onLayout={handleToolkitLayout}>
|
|
88
74
|
<HeaderToolkitAction {...props.headerRight} tintColor={props.tintColor} />
|
|
89
75
|
</View>
|
|
90
76
|
);
|
|
@@ -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) {
|
|
82
|
+
navigator.binding.dismiss('current', navigator.dismissData);
|
|
83
83
|
} else {
|
|
84
84
|
(globalThis as any)?.miniAppApi?.dispatch?.('dismiss', context);
|
|
85
85
|
}
|
|
@@ -16,8 +16,8 @@ const subscribe = (listener: () => void) => {
|
|
|
16
16
|
};
|
|
17
17
|
|
|
18
18
|
/**
|
|
19
|
-
* Records
|
|
20
|
-
*
|
|
19
|
+
* Records the laid out width of a route's header right, side padding included;
|
|
20
|
+
* `undefined` clears it when the header right unmounts.
|
|
21
21
|
*/
|
|
22
22
|
const setHeaderRightWidth = (routeKey: string, width?: number) => {
|
|
23
23
|
if (widths.get(routeKey) === width) {
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { 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';
|
|
7
6
|
const LOADING_RESET_DELAY = 1000;
|
|
8
7
|
|
|
9
8
|
type ToolkitActionsParams = {
|
|
@@ -33,42 +32,28 @@ const useToolkitActions = ({
|
|
|
33
32
|
const [isFavorite, setIsFavorite] = useState<boolean>(false);
|
|
34
33
|
const [isLoading, setIsLoading] = useState(false);
|
|
35
34
|
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
'isFavoriteApp',
|
|
39
|
-
{ code: context?.code },
|
|
40
|
-
(result: boolean) => {
|
|
41
|
-
setIsFavorite(result);
|
|
42
|
-
},
|
|
43
|
-
);
|
|
44
|
-
}, [context?.code, navigator?.maxApi]);
|
|
35
|
+
const binding = navigator?.binding;
|
|
36
|
+
const appCode = context?.code;
|
|
45
37
|
|
|
46
38
|
useEffect(() => {
|
|
47
|
-
if (useShortcut) {
|
|
48
|
-
|
|
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
|
-
};
|
|
39
|
+
if (!useShortcut || !binding) {
|
|
40
|
+
return;
|
|
60
41
|
}
|
|
61
|
-
|
|
42
|
+
const request = binding.checkFavorite(appCode, setIsFavorite);
|
|
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]);
|
|
62
51
|
|
|
63
52
|
const handleDismiss = () => {
|
|
64
53
|
if (useCloseIcon) {
|
|
65
|
-
navigator?.
|
|
66
|
-
'dismiss',
|
|
67
|
-
navigator?.dismissData,
|
|
68
|
-
undefined,
|
|
69
|
-
);
|
|
54
|
+
binding?.dismiss('current', navigator?.dismissData);
|
|
70
55
|
} else {
|
|
71
|
-
|
|
56
|
+
binding?.dismiss('all');
|
|
72
57
|
}
|
|
73
58
|
};
|
|
74
59
|
|
|
@@ -111,20 +96,7 @@ const useToolkitActions = ({
|
|
|
111
96
|
screenName: currentRoute?.params?.screen?.name ?? currentRoute?.name,
|
|
112
97
|
});
|
|
113
98
|
setIsLoading(true);
|
|
114
|
-
|
|
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
|
-
);
|
|
99
|
+
binding?.toggleFavorite(appCode, setIsFavorite);
|
|
128
100
|
setTimeout(() => {
|
|
129
101
|
setIsLoading(false);
|
|
130
102
|
}, LOADING_RESET_DELAY);
|
|
@@ -139,7 +111,13 @@ const useToolkitActions = ({
|
|
|
139
111
|
screenName: currentRoute?.params?.screen?.name ?? currentRoute?.name,
|
|
140
112
|
});
|
|
141
113
|
|
|
142
|
-
|
|
114
|
+
binding?.showHelpCenter({
|
|
115
|
+
appId: context?.appId,
|
|
116
|
+
code: appCode,
|
|
117
|
+
name: context?.name,
|
|
118
|
+
icon: context?.icon,
|
|
119
|
+
description: context?.description,
|
|
120
|
+
});
|
|
143
121
|
};
|
|
144
122
|
|
|
145
123
|
const handlePressIconMore = () => {
|
|
@@ -151,25 +129,17 @@ const useToolkitActions = ({
|
|
|
151
129
|
screenName: currentRoute?.params?.screen?.name ?? currentRoute?.name,
|
|
152
130
|
});
|
|
153
131
|
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
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
|
-
}
|
|
132
|
+
binding?.showToolkit({ useSystemTools, tools, context }, key => {
|
|
133
|
+
for (const group of tools) {
|
|
134
|
+
const pressedTool = group?.items?.find?.(
|
|
135
|
+
(tool: Tool) => tool?.key === key,
|
|
136
|
+
);
|
|
137
|
+
if (pressedTool) {
|
|
138
|
+
pressedTool?.onPress();
|
|
139
|
+
break;
|
|
170
140
|
}
|
|
171
|
-
}
|
|
172
|
-
);
|
|
141
|
+
}
|
|
142
|
+
});
|
|
173
143
|
};
|
|
174
144
|
|
|
175
145
|
let iconShortcut = isFavorite ? 'pin_star_checked' : 'pin_star';
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import React, { createContext, FC } from 'react';
|
|
2
|
+
import type { KitsBinding, KitsBindingProviderProps } from './types.binding';
|
|
3
|
+
|
|
4
|
+
/** Binding of the nearest enclosing container or provider, if any. */
|
|
5
|
+
const KitsBindingContext = createContext<KitsBinding | undefined>(undefined);
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Gives every container in its subtree `binding` unless one passes its own, so a
|
|
9
|
+
* host can wrap a mini app without the mini app passing anything.
|
|
10
|
+
*/
|
|
11
|
+
const KitsBindingProvider: FC<KitsBindingProviderProps> = ({
|
|
12
|
+
binding,
|
|
13
|
+
children,
|
|
14
|
+
}) => {
|
|
15
|
+
return (
|
|
16
|
+
<KitsBindingContext.Provider value={binding}>
|
|
17
|
+
{children}
|
|
18
|
+
</KitsBindingContext.Provider>
|
|
19
|
+
);
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export { KitsBindingContext, KitsBindingProvider };
|