@momo-kits/foundation 0.169.16-beta.5 → 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.
@@ -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 onScreenNavigated = (pre: string, current: string) => {
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?.maxApi?.showToastDebug?.({
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?.maxApi?.getDataObserver?.(
75
- 'current_screen',
76
- (data: any) => {
77
- onScreenNavigated(data?.screenName, screenName);
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 onFocusApp = navigator?.maxApi?.listen?.('onFocusApp', () => {
98
+ const focusAppListener = navigator?.binding.onFocusApp(() => {
100
99
  if (navigation.isFocused()) {
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
- );
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
- onFocusApp?.remove?.();
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?.maxApi?.triggerEventVibration?.('light');
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?.maxApi?.triggerEventVibration?.('light');
107
+ navigator?.binding.vibrateLight();
104
108
  listeners?.tabPress?.(e);
105
109
  },
106
110
  focus: e => {
@@ -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?.maxApi?.showToastDebug?.({
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?.maxApi?.getDataObserver?.(
70
- 'current_screen',
71
- (data: any) => {
72
- handleScreenNavigated(data?.screenName, screenName);
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?.maxApi?.listen?.('onFocusApp', () => {
82
+ const focusAppListener = navigator?.binding.onFocusApp(() => {
88
83
  if (navigation.isFocused()) {
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
- );
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?.maxApi?.triggerEventVibration?.('light');
123
+ navigator?.binding.vibrateLight();
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?.maxApi) {
42
- navigator?.maxApi?.dismiss?.(navigator?.dismissData);
41
+ } else if (navigator) {
42
+ navigator.binding.dismiss('current', 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?.maxApi) {
82
- navigator?.maxApi?.dismiss?.(navigator?.dismissData);
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
  }
@@ -79,7 +79,7 @@ const SwipeBackHaptic = () => {
79
79
 
80
80
  if (!hasFired.current) {
81
81
  hasFired.current = true;
82
- navigator?.maxApi?.triggerEventVibration?.('light');
82
+ navigator?.binding.vibrateLight();
83
83
  }
84
84
  });
85
85
 
@@ -1,9 +1,8 @@
1
- import { useCallback, useContext, useEffect, useState } from 'react';
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 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]);
35
+ const binding = navigator?.binding;
36
+ const appCode = context?.code;
45
37
 
46
38
  useEffect(() => {
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
- };
39
+ if (!useShortcut || !binding) {
40
+ return;
60
41
  }
61
- }, [useShortcut, context, checkAppIsFavorite, navigator?.maxApi]);
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?.maxApi?.dispatchFunction?.(
66
- 'dismiss',
67
- navigator?.dismissData,
68
- undefined,
69
- );
54
+ binding?.dismiss('current', navigator?.dismissData);
70
55
  } else {
71
- navigator?.maxApi?.dispatchFunction?.('dismissAll');
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
- 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
- );
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
- navigator?.maxApi?.dispatchFunction?.('showHelpCenter', context);
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
- 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
- }
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 };
@@ -0,0 +1,182 @@
1
+ import type {
2
+ KitsBinding,
3
+ KitsRequest,
4
+ KitsSubscription,
5
+ ResolvedKitsBinding,
6
+ } from './types.binding';
7
+
8
+ type BindingMethod = keyof KitsBinding;
9
+
10
+ const NO_REQUEST: KitsRequest = { cancel: () => {} };
11
+ const NO_SUBSCRIPTION: KitsSubscription = { remove: () => {} };
12
+
13
+ const NO_OP_BINDING: ResolvedKitsBinding = {
14
+ dismiss: () => {},
15
+ trackEvent: () => {},
16
+ getLanguage: () => NO_REQUEST,
17
+ vibrateLight: () => {},
18
+ checkFavorite: () => NO_REQUEST,
19
+ toggleFavorite: () => NO_REQUEST,
20
+ showToolkit: () => NO_REQUEST,
21
+ showHelpCenter: () => NO_REQUEST,
22
+ logError: () => {},
23
+ observeConfig: () => NO_SUBSCRIPTION,
24
+ observeFavorites: () => NO_SUBSCRIPTION,
25
+ getCurrentScreen: () => NO_REQUEST,
26
+ setCurrentScreen: () => {},
27
+ onFocusApp: () => NO_SUBSCRIPTION,
28
+ startScreenTrace: () => NO_REQUEST,
29
+ stopTrace: () => {},
30
+ showToastDebug: () => {},
31
+ showNoticePopup: () => {},
32
+ openWeb: () => {},
33
+ startFeatureCode: () => {},
34
+ };
35
+
36
+ // Resolved bindings delegate to the host, so one installed as the host would loop.
37
+ const resolvedBindings = new WeakSet<KitsBinding>();
38
+ let installed: KitsBinding | undefined;
39
+
40
+ /**
41
+ * The host app installs its binding here once; containers use it unless a caller
42
+ * passes or provides another. Until then `binding` does nothing, never throws.
43
+ */
44
+ const KitsHost = {
45
+ get binding(): KitsBinding {
46
+ return installed ?? NO_OP_BINDING;
47
+ },
48
+ /** The last install wins. The kit borrows the binding and never closes it. */
49
+ install(binding: KitsBinding) {
50
+ installed = binding;
51
+ },
52
+ uninstall() {
53
+ installed = undefined;
54
+ },
55
+ };
56
+
57
+ /**
58
+ * Object that implements `method`, looked up at call time: `binding`, else the
59
+ * installed host binding unless that is `binding` itself, else the no-op.
60
+ */
61
+ const getMethodOwner = (
62
+ binding: KitsBinding | undefined,
63
+ method: BindingMethod,
64
+ ): KitsBinding => {
65
+ if (typeof binding?.[method] === 'function') {
66
+ return binding;
67
+ }
68
+ const host = KitsHost.binding;
69
+ const isOtherHost = host !== binding && !resolvedBindings.has(host);
70
+ if (isOtherHost && typeof host[method] === 'function') {
71
+ return host;
72
+ }
73
+ return NO_OP_BINDING;
74
+ };
75
+
76
+ /**
77
+ * Starts a host request whose callback is dropped once the kit cancels it, so a
78
+ * late host answer never reaches an unmounted screen. `cancel` is idempotent.
79
+ */
80
+ const startRequest = <T>(
81
+ start: (callback: (value: T) => void) => KitsRequest | undefined,
82
+ callback: (value: T) => void,
83
+ ): KitsRequest => {
84
+ let isActive = true;
85
+ const request = start(value => {
86
+ if (isActive) {
87
+ callback(value);
88
+ }
89
+ });
90
+ return {
91
+ cancel: () => {
92
+ if (!isActive) {
93
+ return;
94
+ }
95
+ isActive = false;
96
+ request?.cancel();
97
+ },
98
+ };
99
+ };
100
+
101
+ /** Every method of `binding`, each falling back to `KitsHost` when missing. */
102
+ const resolveKitsBinding = (binding?: KitsBinding): ResolvedKitsBinding => {
103
+ /** Owner of `method` for this binding. */
104
+ const owner = (method: BindingMethod) => getMethodOwner(binding, method);
105
+ const resolved: ResolvedKitsBinding = {
106
+ dismiss: (target, data) => owner('dismiss').dismiss?.(target, data),
107
+ trackEvent: (eventName, attributes) => {
108
+ owner('trackEvent').trackEvent?.(eventName, attributes);
109
+ },
110
+ getLanguage: callback => {
111
+ return startRequest(
112
+ cb => owner('getLanguage').getLanguage?.(cb),
113
+ callback,
114
+ );
115
+ },
116
+ vibrateLight: () => owner('vibrateLight').vibrateLight?.(),
117
+ checkFavorite: (appCode, callback) => {
118
+ return startRequest(
119
+ cb => owner('checkFavorite').checkFavorite?.(appCode, cb),
120
+ callback,
121
+ );
122
+ },
123
+ toggleFavorite: (appCode, callback) => {
124
+ return startRequest(
125
+ cb => owner('toggleFavorite').toggleFavorite?.(appCode, cb),
126
+ callback,
127
+ );
128
+ },
129
+ showToolkit: (request, onAction) => {
130
+ return startRequest(
131
+ cb => owner('showToolkit').showToolkit?.(request, cb),
132
+ onAction,
133
+ );
134
+ },
135
+ showHelpCenter: request => {
136
+ return owner('showHelpCenter').showHelpCenter?.(request) ?? NO_REQUEST;
137
+ },
138
+ logError: message => owner('logError').logError?.(message),
139
+ observeConfig: (key, callback) => {
140
+ const host = owner('observeConfig');
141
+ return host.observeConfig?.(key, callback) ?? NO_SUBSCRIPTION;
142
+ },
143
+ observeFavorites: callback => {
144
+ const host = owner('observeFavorites');
145
+ return host.observeFavorites?.(callback) ?? NO_SUBSCRIPTION;
146
+ },
147
+ getCurrentScreen: callback => {
148
+ return startRequest(
149
+ cb => owner('getCurrentScreen').getCurrentScreen?.(cb),
150
+ callback,
151
+ );
152
+ },
153
+ setCurrentScreen: screen => {
154
+ owner('setCurrentScreen').setCurrentScreen?.(screen);
155
+ },
156
+ onFocusApp: listener => {
157
+ return owner('onFocusApp').onFocusApp?.(listener) ?? NO_SUBSCRIPTION;
158
+ },
159
+ startScreenTrace: (kind, screenName, context, callback) => {
160
+ const host = owner('startScreenTrace');
161
+ return startRequest(
162
+ cb => host.startScreenTrace?.(kind, screenName, context, cb),
163
+ callback,
164
+ );
165
+ },
166
+ stopTrace: (traceId, value) => {
167
+ owner('stopTrace').stopTrace?.(traceId, value);
168
+ },
169
+ showToastDebug: toast => owner('showToastDebug').showToastDebug?.(toast),
170
+ showNoticePopup: popup => {
171
+ owner('showNoticePopup').showNoticePopup?.(popup);
172
+ },
173
+ openWeb: request => owner('openWeb').openWeb?.(request),
174
+ startFeatureCode: (featureCode, params) => {
175
+ owner('startFeatureCode').startFeatureCode?.(featureCode, params);
176
+ },
177
+ };
178
+ resolvedBindings.add(resolved);
179
+ return resolved;
180
+ };
181
+
182
+ export { KitsHost, resolveKitsBinding };
@@ -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?.maxApi?.getDataObserver?.('current_screen', (curScreen: any) => {
69
+ navigator?.binding.getCurrentScreen(curScreen => {
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?.maxApi, title]);
78
+ }, [context, description, navigator?.binding, title]);
79
79
 
80
80
  const opacity = useRef(new Animated.Value(0)).current;
81
81
  const scale = useRef(new Animated.Value(INITIAL_SCALE)).current;
@@ -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 { useNativeCanGoBack } from './hooks';
21
+ import { useKitsBinding, useNativeCanGoBack } from './hooks';
22
22
  import { NavigationContainerProps } from './types';
23
23
  import { ApplicationContext, MiniAppContext } from '../Context';
24
24
  import Localize from './Localize';
@@ -30,18 +30,19 @@ import { HeaderBackground } from './Components/HeaderBackground';
30
30
  import { useScreenLayout } from '../Layout';
31
31
  import { getHeaderRowOptions } from '../Layout/utils';
32
32
  import { ReservedRegionsProvider } from '../Layout/ReservedRegions';
33
+ import { KitsBindingContext } from './KitsBindingProvider';
33
34
 
34
35
  const Stack = createStackNavigator();
35
36
 
36
37
  /**
37
- * Root of a mini app: safe area, reserved regions and the merged mini app
38
- * context around the kit's navigator.
38
+ * Root of a mini app: safe area, reserved regions, the merged mini app context
39
+ * and its host binding around the kit's navigator.
39
40
  */
40
41
  const NavigationContainer: React.FC<NavigationContainerProps> = ({
41
42
  screen,
42
43
  theme = defaultTheme,
43
44
  options,
44
- maxApi,
45
+ binding,
45
46
  initialParams,
46
47
  localize = new Localize({ vi: {}, en: {} }),
47
48
  features = {
@@ -53,13 +54,14 @@ const NavigationContainer: React.FC<NavigationContainerProps> = ({
53
54
  }) => {
54
55
  const context = useContext<any>(MiniAppContext);
55
56
  const [currentContext, setCurrentContext] = useState<any>({});
57
+ const { source, resolved } = useKitsBinding(binding);
56
58
 
57
59
  useEffect(() => {
58
- const sub = maxApi?.observer?.('font_scale_config', (data: any) => {
60
+ const sub = resolved.observeConfig('font_scale_config', data => {
59
61
  setCurrentContext((prev: any) => ({ ...prev, fontScale: data }));
60
62
  });
61
- return () => sub?.remove?.();
62
- }, [maxApi]);
63
+ return () => sub.remove();
64
+ }, [resolved]);
63
65
 
64
66
  const mergedContext = {
65
67
  ...context,
@@ -81,15 +83,17 @@ const NavigationContainer: React.FC<NavigationContainerProps> = ({
81
83
  >
82
84
  <ReservedRegionsProvider>
83
85
  <MiniAppContext.Provider value={mergedContext}>
84
- <Navigation
85
- screen={screen}
86
- theme={theme}
87
- options={options}
88
- maxApi={maxApi}
89
- setCurrentContext={setCurrentContext}
90
- initialParams={initialParams}
91
- localize={localize}
92
- />
86
+ <KitsBindingContext.Provider value={source}>
87
+ <Navigation
88
+ screen={screen}
89
+ theme={theme}
90
+ options={options}
91
+ binding={resolved}
92
+ setCurrentContext={setCurrentContext}
93
+ initialParams={initialParams}
94
+ localize={localize}
95
+ />
96
+ </KitsBindingContext.Provider>
93
97
  </MiniAppContext.Provider>
94
98
  </ReservedRegionsProvider>
95
99
  </SafeAreaProvider>
@@ -104,7 +108,7 @@ const Navigation: React.FC<any> = ({
104
108
  screen,
105
109
  theme = defaultTheme,
106
110
  options,
107
- maxApi,
111
+ binding,
108
112
  initialParams,
109
113
  setCurrentContext,
110
114
  localize = new Localize({ vi: {}, en: {} }),
@@ -131,7 +135,7 @@ const Navigation: React.FC<any> = ({
131
135
  headerGradient = context?.designSystemConfig?.config?.headerGradient;
132
136
  }
133
137
 
134
- navigator.current.maxApi = maxApi;
138
+ navigator.current.binding = binding;
135
139
 
136
140
  /** Text for a localization key, or the current-language side of `{ vi, en }`. */
137
141
  const translate = (data?: string | { vi: string; en: string }) => {