@momo-kits/foundation 0.88.1 → 0.89.1-beta.10

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.
@@ -15,7 +15,7 @@ import {
15
15
  View,
16
16
  ViewStyle,
17
17
  } from 'react-native';
18
- import {ApplicationContext} from './index';
18
+ import {ApplicationContext, MiniAppContext} from './index';
19
19
  import {Colors, Radius, Spacing, Styles} from '../Consts';
20
20
  import {Image} from '../Image';
21
21
  import {
@@ -108,6 +108,7 @@ const HeaderLeft: React.FC<HeaderBackProps> = ({
108
108
  useBorder,
109
109
  accessibilityLabel = '',
110
110
  }) => {
111
+ const context = useContext(MiniAppContext);
111
112
  const {navigator} = useContext(ApplicationContext);
112
113
 
113
114
  useEffect(() => {
@@ -122,13 +123,10 @@ const HeaderLeft: React.FC<HeaderBackProps> = ({
122
123
  const goBackSafe = () => {
123
124
  const goBack = () => {
124
125
  const canGoBack = navigator?.ref.current?.canGoBack();
125
- if (!canGoBack && navigator?.trackingInfo) {
126
+ if (!canGoBack) {
126
127
  const currentRoute = navigator?.ref?.current.getCurrentRoute();
127
128
  navigator?.maxApi?.trackEvent?.('service_icon_clicked', {
128
- feature_code: navigator.trackingInfo.code,
129
- app_id: navigator.trackingInfo.appId,
130
- miniapp_version: navigator.trackingInfo.buildNumber,
131
- flow_partner_id: navigator.trackingInfo.flowPartnerId,
129
+ ...context,
132
130
  screen_name: currentRoute?.params?.screen?.name ?? currentRoute?.name,
133
131
  trigger_id: '111154000000000000',
134
132
  icon_name: 'back',
@@ -290,6 +288,7 @@ const HeaderRightAction: React.FC<any> = ({children, ...restProps}) => {
290
288
  const HeaderToolkitAction: React.FC<any> = ({
291
289
  tintColor,
292
290
  pinnedTool,
291
+ runtimeTools = [],
293
292
  preventBack,
294
293
  }) => {
295
294
  const {theme, navigator} = useContext(ApplicationContext);
@@ -310,17 +309,21 @@ const HeaderToolkitAction: React.FC<any> = ({
310
309
  }, []);
311
310
 
312
311
  const getToolkitConfig = () => {
313
- navigator?.requestApi('getToolsConfig', [undefined], (config: any) => {
314
- navigator.toolkitConfig = config;
315
- setToolConfig(navigator?.toolkitConfig);
316
- });
312
+ navigator?.maxApi?.dispatchFunction?.(
313
+ 'getToolsConfig',
314
+ [undefined],
315
+ (config: any) => {
316
+ navigator.toolkitConfig = config;
317
+ setToolConfig(navigator?.toolkitConfig);
318
+ },
319
+ );
317
320
  };
318
321
 
319
322
  const onMore = () => {
320
323
  onAction?.('onMore');
321
- navigator?.requestApi(
324
+ navigator?.maxApi?.dispatchFunction?.(
322
325
  'showTools',
323
- [undefined],
326
+ {runtimeTools},
324
327
  (res: {item: {action?: string; key: string}}) => {
325
328
  const {item} = res;
326
329
  navigator?.toolkitCallback?.(item);
@@ -339,14 +342,18 @@ const HeaderToolkitAction: React.FC<any> = ({
339
342
  title: preventBack.primary.title,
340
343
  onPress: () => {
341
344
  preventBack?.primary.onPress();
342
- navigator?.requestApi('dismiss', undefined, undefined);
345
+ navigator?.maxApi?.dispatchFunction?.(
346
+ 'dismiss',
347
+ undefined,
348
+ undefined,
349
+ );
343
350
  },
344
351
  }}
345
352
  />
346
353
  ),
347
354
  });
348
355
  } else {
349
- navigator?.requestApi('dismiss', undefined, undefined);
356
+ navigator?.maxApi?.dispatchFunction?.('dismiss', undefined, undefined);
350
357
  }
351
358
  };
352
359
 
@@ -364,9 +371,13 @@ const HeaderToolkitAction: React.FC<any> = ({
364
371
  badgeValue={badgeValue}
365
372
  badgeType={badgeType}
366
373
  onPress={() => {
367
- navigator?.requestApi('onToolAction', [pinTool?.key], () => {
368
- getToolkitConfig();
369
- });
374
+ navigator?.maxApi?.dispatchFunction?.(
375
+ 'onToolAction',
376
+ pinTool?.key,
377
+ () => {
378
+ getToolkitConfig();
379
+ },
380
+ );
370
381
  navigator?.toolkitCallback?.(pinTool.key);
371
382
  }}
372
383
  />
@@ -178,7 +178,6 @@ const BottomSheet: React.FC<BottomSheetParams> = props => {
178
178
  />
179
179
  </View>
180
180
  <NavigationContainer
181
- trackingInfo={navigator?.trackingInfo}
182
181
  maxApi={navigator?.maxApi}
183
182
  theme={{
184
183
  ...theme,
@@ -23,7 +23,6 @@ const NavigationContainer: React.FC<NavigationContainerProps> = ({
23
23
  options,
24
24
  maxApi,
25
25
  localization,
26
- trackingInfo,
27
26
  }) => {
28
27
  const navigationRef = React.useRef<NavigationContainerRef>(null);
29
28
  const navigator = useRef(new Navigator(navigationRef));
@@ -68,7 +67,6 @@ const NavigationContainer: React.FC<NavigationContainerProps> = ({
68
67
  * inject data for navigator
69
68
  */
70
69
  navigator.current.maxApi = maxApi;
71
- navigator.current.trackingInfo = trackingInfo;
72
70
 
73
71
  /**
74
72
  * translate
@@ -4,14 +4,12 @@ import {
4
4
  HeaderToolkitProps,
5
5
  ModalParams,
6
6
  ScreenParams,
7
- TrackingInfo,
8
7
  } from './types';
9
8
 
10
9
  class Navigator {
11
10
  ref?: any;
12
11
  toolkitConfig?: HeaderToolkitProps;
13
12
  maxApi?: any;
14
- trackingInfo?: TrackingInfo;
15
13
  dismissData?: any;
16
14
  toolkitCallback?: (item: any) => void;
17
15
 
@@ -111,18 +109,6 @@ class Navigator {
111
109
  );
112
110
  };
113
111
 
114
- /**
115
- * request max api for mini app
116
- * @param func
117
- * @param args
118
- * @param callback
119
- */
120
- requestApi = (func: any, args: any = [], callback: any) => {
121
- if (this.maxApi) {
122
- this.maxApi[func]?.(...args, callback);
123
- }
124
- };
125
-
126
112
  setToolkitCallback = (
127
113
  callback: (item: {key: string; action: string}) => void,
128
114
  ) => {
@@ -1,13 +1,15 @@
1
1
  import React, {useContext, useEffect, useLayoutEffect} from 'react';
2
2
  import {ScreenParams} from './types';
3
3
  import Navigation from './Navigation';
4
- import {ApplicationContext} from './index';
4
+ import {ApplicationContext, MiniAppContext} from './index';
5
5
  import {GridSystem} from '../Layout';
6
6
  import {useHeaderHeight} from '@react-navigation/stack';
7
7
 
8
8
  const StackScreen: React.FC<ScreenParams> = props => {
9
- const {screen: Component, options}: ScreenParams = props.route.params;
10
9
  const {theme, showGrid, navigator} = useContext(ApplicationContext);
10
+ const context = useContext(MiniAppContext);
11
+
12
+ const {screen: Component, options}: ScreenParams = props.route.params;
11
13
  const navigation = new Navigation(props.navigation, theme);
12
14
  const heightHeader = useHeaderHeight();
13
15
 
@@ -31,36 +33,31 @@ const StackScreen: React.FC<ScreenParams> = props => {
31
33
  * tracking for screen
32
34
  */
33
35
  useEffect(() => {
34
- if (navigator?.trackingInfo) {
35
- const tracking = {
36
- feature_code: navigator.trackingInfo.code,
37
- app_id: navigator.trackingInfo.appId,
38
- miniapp_version: navigator.trackingInfo.buildNumber,
39
- flow_partner_id: navigator.trackingInfo.flowPartnerId,
40
- screen_name: Component.name,
41
- };
36
+ const tracking = {
37
+ ...context,
38
+ screen_name: Component.name,
39
+ };
40
+
41
+ const routes = props.navigation.getState()?.routes || [];
42
+ const routesLength = routes.length;
43
+ let pre_screen_name = '';
44
+ if (routesLength > 1) {
45
+ pre_screen_name = routes[routesLength - 2]?.params?.screen?.name;
46
+ }
42
47
 
43
- const routes = props.navigation.getState()?.routes || [];
44
- const routesLength = routes.length;
45
- let pre_screen_name = '';
46
- if (routesLength > 1) {
47
- pre_screen_name = routes[routesLength - 2]?.params?.screen?.name;
48
- }
48
+ navigator?.maxApi?.trackEvent?.('service_frame_displayed', {
49
+ ...tracking,
50
+ pre_screen_name,
51
+ trigger_id: '111378000000000000',
52
+ });
49
53
 
50
- navigator?.maxApi?.trackEvent?.('service_frame_displayed', {
54
+ return props.navigation.addListener('beforeRemove', () => {
55
+ navigator?.maxApi?.trackEvent?.('service_icon_clicked', {
51
56
  ...tracking,
52
- pre_screen_name,
53
- trigger_id: '111378000000000000',
54
- });
55
-
56
- return props.navigation.addListener('beforeRemove', () => {
57
- navigator?.maxApi?.trackEvent?.('service_icon_clicked', {
58
- ...tracking,
59
- trigger_id: '111154000000000000',
60
- icon_name: 'back',
61
- });
57
+ trigger_id: '111154000000000000',
58
+ icon_name: 'back',
62
59
  });
63
- }
60
+ });
64
61
  }, []);
65
62
 
66
63
  return (
@@ -13,12 +13,21 @@ import {
13
13
  import BottomTab from './BottomTab';
14
14
  import {createContext} from 'react';
15
15
  import {defaultContext} from '../Consts';
16
+ import {MiniAppInfo} from './types';
16
17
 
17
18
  const ApplicationContext = createContext(defaultContext);
19
+ const MiniAppContext = createContext<MiniAppInfo>({
20
+ appId: '',
21
+ buildNumber: 0,
22
+ code: '',
23
+ toolkitConfig: {},
24
+ fromCode: '',
25
+ });
18
26
 
19
27
  export {
20
- NavigationContainer,
21
28
  ApplicationContext,
29
+ MiniAppContext,
30
+ NavigationContainer,
22
31
  Screen,
23
32
  BottomTab,
24
33
  NavigationButton,
@@ -71,6 +71,16 @@ export type Context = {
71
71
  translate?: (key: string) => string;
72
72
  };
73
73
 
74
+ export type MiniAppInfo = {
75
+ [key: string]: any;
76
+ code: string;
77
+ appId: string;
78
+ buildNumber: number;
79
+ flowPartnerId?: string;
80
+ toolkitConfig?: object;
81
+ fromCode?: string;
82
+ };
83
+
74
84
  export type LocalizationObject = {
75
85
  vi: {
76
86
  [key: string]: string;
@@ -80,21 +90,12 @@ export type LocalizationObject = {
80
90
  };
81
91
  };
82
92
 
83
- export type TrackingInfo = {
84
- [key: string]: any;
85
- code: string;
86
- appId: string;
87
- buildNumber: number;
88
- flowPartnerId?: string;
89
- };
90
-
91
93
  export type NavigationContainerProps = {
92
94
  screen: Screen;
93
95
  options?: NavigationOptions;
94
96
  theme: Theme;
95
97
  maxApi: any;
96
98
  localization?: LocalizationObject;
97
- trackingInfo?: TrackingInfo;
98
99
  };
99
100
 
100
101
  export type NavigationScreenProps = {
@@ -138,13 +139,22 @@ export type PinnedToolType = {
138
139
  badgeType?: 'number' | 'dot';
139
140
  };
140
141
 
142
+ export type RuntimeToolType = {
143
+ title: {vi: string; en: string};
144
+ icon: string;
145
+ key: string;
146
+ };
147
+
141
148
  export interface NavigationOptions extends StackNavigationOptions {
142
149
  preventBack?: PopupNotifyProps;
143
150
  onPressLeftHeader?: () => void;
144
151
  surface?: boolean;
145
152
  hiddenBack?: boolean;
146
153
  customTitle?: TitleCustomProps;
147
- pinnedTool?: PinnedToolType;
154
+ toolkitParams?: {
155
+ pinnedTool?: PinnedToolType;
156
+ runtimeTools?: RuntimeToolType[];
157
+ };
148
158
  }
149
159
 
150
160
  export interface HeaderBackProps extends NavigationButtonProps {
@@ -126,14 +126,15 @@ const getOptions = (params: NavigationOptions, theme: Theme) => {
126
126
  };
127
127
  }
128
128
 
129
- if (params.pinnedTool) {
129
+ if (params.toolkitParams) {
130
130
  options = {
131
131
  ...options,
132
132
  headerRight: (props: any) => {
133
133
  return (
134
134
  <HeaderToolkitAction
135
135
  preventBack={params.preventBack}
136
- pinnedTool={params.pinnedTool}
136
+ pinnedTool={params.toolkitParams?.pinnedTool}
137
+ runtimeTools={params.toolkitParams?.runtimeTools}
137
138
  {...props}
138
139
  />
139
140
  );
@@ -1,4 +1,10 @@
1
- import React, {forwardRef, useContext, useRef, useState} from 'react';
1
+ import React, {
2
+ forwardRef,
3
+ useContext,
4
+ useImperativeHandle,
5
+ useRef,
6
+ useState,
7
+ } from 'react';
2
8
  import {
3
9
  NativeSyntheticEvent,
4
10
  TextInput,
@@ -63,6 +69,12 @@ const InputMoney = forwardRef(
63
69
  onChangeText?.(formatMoneyToNumber(text, 'đ').toString());
64
70
  };
65
71
 
72
+ useImperativeHandle(ref, () => {
73
+ return {
74
+ setText: _onChangeText,
75
+ };
76
+ });
77
+
66
78
  const _onFocus = (e: NativeSyntheticEvent<TextInputFocusEventData>) => {
67
79
  setFocused(true);
68
80
  onFocus?.(e);
@@ -4,7 +4,7 @@ import {PopupNotifyProps} from './types';
4
4
  import {Radius, Spacing, Styles} from '../Consts';
5
5
  import {Image} from '../Image';
6
6
  import {Text} from '../Text';
7
- import {ApplicationContext} from '../Application';
7
+ import {ApplicationContext, MiniAppContext} from '../Application';
8
8
  import {Button} from '../Button';
9
9
  import {Icon} from '../Icon';
10
10
 
@@ -19,6 +19,7 @@ const PopupNotify: React.FC<PopupNotifyProps> = ({
19
19
  buttonDirection = 'row',
20
20
  onIconClose,
21
21
  }) => {
22
+ const context = useContext(MiniAppContext);
22
23
  const {theme, navigator, translate} = useContext(ApplicationContext);
23
24
  const [scrollContent, setScrollContent] = useState(false);
24
25
  const closeAction = useRef('touch_outside');
@@ -34,35 +35,31 @@ const PopupNotify: React.FC<PopupNotifyProps> = ({
34
35
  * tracking
35
36
  */
36
37
  useEffect(() => {
37
- if (navigator?.trackingInfo) {
38
- const routes = navigator.ref.current?.getRootState()?.routes || [];
39
- const routesLength = routes.length;
40
- let screen_name = routes?.[0]?.params?.screen?.name;
41
- if (routesLength > 1) {
42
- screen_name = routes[routesLength - 2]?.params?.screen?.name;
43
- }
44
- const tracking = {
45
- feature_code: navigator?.trackingInfo?.code,
46
- app_id: navigator?.trackingInfo?.appId,
47
- miniapp_version: navigator?.trackingInfo?.buildNumber,
48
- flow_partner_id: navigator?.trackingInfo?.flowPartnerId,
49
- screen_name,
50
- component_type: 'popup',
51
- component_name: id,
52
- error_code: error ? error : undefined,
53
- };
54
- navigator?.maxApi?.trackEvent?.('service_component_displayed', {
38
+ const routes = navigator?.ref.current?.getRootState()?.routes || [];
39
+ const routesLength = routes.length;
40
+ let screen_name = routes?.[0]?.params?.screen?.name;
41
+ if (routesLength > 1) {
42
+ screen_name = routes[routesLength - 2]?.params?.screen?.name;
43
+ }
44
+ const tracking = {
45
+ ...context,
46
+ screen_name,
47
+ component_type: 'popup',
48
+ component_name: id,
49
+ error_code: error ? error : undefined,
50
+ };
51
+ navigator?.maxApi?.trackEvent?.('service_component_displayed', {
52
+ ...tracking,
53
+ trigger_id: '111012100000000000',
54
+ });
55
+
56
+ return () => {
57
+ navigator?.maxApi?.trackEvent?.('service_popup_dismissed', {
55
58
  ...tracking,
56
- trigger_id: '111012100000000000',
59
+ trigger_id: '111154100000000001',
60
+ action_type: closeAction.current,
57
61
  });
58
- return () => {
59
- navigator?.maxApi?.trackEvent?.('service_popup_dismissed', {
60
- ...tracking,
61
- trigger_id: '111154100000000001',
62
- action_type: closeAction.current,
63
- });
64
- };
65
- }
62
+ };
66
63
  }, []);
67
64
 
68
65
  /**
@@ -1,7 +1,7 @@
1
1
  import React, {useContext, useEffect, useRef} from 'react';
2
2
  import {StyleSheet, TouchableOpacity, View} from 'react-native';
3
3
  import {PopupPromotionProps} from './types';
4
- import {ApplicationContext} from '../Application';
4
+ import {ApplicationContext, MiniAppContext} from '../Application';
5
5
  import {Image} from '../Image';
6
6
  import {Radius, Spacing} from '../Consts';
7
7
  import {Icon} from '../Icon';
@@ -11,6 +11,7 @@ const PopupPromotion: React.FC<PopupPromotionProps> = ({
11
11
  image,
12
12
  onIconClose,
13
13
  }) => {
14
+ const context = useContext(MiniAppContext);
14
15
  const {theme, navigator} = useContext(ApplicationContext);
15
16
  const closeAction = useRef('touch_outside');
16
17
 
@@ -18,34 +19,29 @@ const PopupPromotion: React.FC<PopupPromotionProps> = ({
18
19
  * tracking
19
20
  */
20
21
  useEffect(() => {
21
- if (navigator?.trackingInfo) {
22
- const routes = navigator.ref.current?.getRootState()?.routes || [];
23
- const routesLength = routes.length;
24
- let screen_name = routes?.[0]?.params?.screen?.name;
25
- if (routesLength > 1) {
26
- screen_name = routes[routesLength - 2]?.params?.screen?.name;
27
- }
28
- const tracking = {
29
- feature_code: navigator?.trackingInfo?.code,
30
- app_id: navigator?.trackingInfo?.appId,
31
- miniapp_version: navigator?.trackingInfo?.buildNumber,
32
- flow_partner_id: navigator?.trackingInfo?.flowPartnerId,
33
- screen_name,
34
- component_type: 'popup',
35
- component_name: id,
36
- };
37
- navigator?.maxApi?.trackEvent?.('service_component_displayed', {
22
+ const routes = navigator?.ref.current?.getRootState()?.routes || [];
23
+ const routesLength = routes.length;
24
+ let screen_name = routes?.[0]?.params?.screen?.name;
25
+ if (routesLength > 1) {
26
+ screen_name = routes[routesLength - 2]?.params?.screen?.name;
27
+ }
28
+ const tracking = {
29
+ ...context,
30
+ screen_name,
31
+ component_type: 'popup',
32
+ component_name: id,
33
+ };
34
+ navigator?.maxApi?.trackEvent?.('service_component_displayed', {
35
+ ...tracking,
36
+ trigger_id: '111012100000000000',
37
+ });
38
+ return () => {
39
+ navigator?.maxApi?.trackEvent?.('service_popup_dismissed', {
38
40
  ...tracking,
39
- trigger_id: '111012100000000000',
41
+ trigger_id: '111154100000000001',
42
+ action_type: closeAction.current,
40
43
  });
41
- return () => {
42
- navigator?.maxApi?.trackEvent?.('service_popup_dismissed', {
43
- ...tracking,
44
- trigger_id: '111154100000000001',
45
- action_type: closeAction.current,
46
- });
47
- };
48
- }
44
+ };
49
45
  }, []);
50
46
 
51
47
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@momo-kits/foundation",
3
- "version": "0.88.1",
3
+ "version": "0.89.1-beta.10",
4
4
  "description": "React Native Component Kits",
5
5
  "main": "index.ts",
6
6
  "scripts": {