@momo-kits/foundation 0.81.43-tracking.2 → 0.81.43-tracking.4

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',
@@ -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,
@@ -6,7 +6,7 @@ import {
6
6
  NavigationContainerRef,
7
7
  } from '@react-navigation/native';
8
8
  import {createStackNavigator} from '@react-navigation/stack';
9
- import {Alert, DeviceEventEmitter, NativeModules} from 'react-native';
9
+ import {DeviceEventEmitter, NativeModules} from 'react-native';
10
10
  import StackScreen from './StackScreen';
11
11
  import ModalScreen from './ModalScreen';
12
12
  import Navigator from './Navigator';
@@ -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
 
@@ -128,10 +126,6 @@ class Navigator {
128
126
  ) => {
129
127
  this.toolkitCallback = callback;
130
128
  };
131
-
132
- setTrackingInfo = (newInfo: TrackingInfo) => {
133
- this.trackingInfo = {...this.trackingInfo, ...newInfo};
134
- };
135
129
  }
136
130
 
137
131
  export default Navigator;
@@ -1,7 +1,7 @@
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
 
@@ -10,8 +10,10 @@ const {
10
10
  } = require('react-native/Libraries/Components/ScreenContext');
11
11
 
12
12
  const StackScreen: React.FC<ScreenParams> = props => {
13
- const {screen: Component, options}: ScreenParams = props.route.params;
14
13
  const {theme, showGrid, navigator} = useContext(ApplicationContext);
14
+ const context = useContext(MiniAppContext);
15
+
16
+ const {screen: Component, options}: ScreenParams = props.route.params;
15
17
  const navigation = new Navigation(props.navigation, theme);
16
18
  const heightHeader = useHeaderHeight();
17
19
 
@@ -35,42 +37,37 @@ const StackScreen: React.FC<ScreenParams> = props => {
35
37
  * tracking for screen
36
38
  */
37
39
  useEffect(() => {
38
- if (navigator?.trackingInfo) {
39
- const tracking = {
40
- feature_code: navigator.trackingInfo.code,
41
- app_id: navigator.trackingInfo.appId,
42
- miniapp_version: navigator.trackingInfo.buildNumber,
43
- flow_partner_id: navigator.trackingInfo.flowPartnerId,
44
- screen_name: Component.name,
45
- };
40
+ const tracking = {
41
+ ...context,
42
+ screen_name: Component.name,
43
+ };
44
+
45
+ const routes = props.navigation.getState()?.routes || [];
46
+ const routesLength = routes.length;
47
+ let pre_screen_name = '';
48
+ if (routesLength > 1) {
49
+ pre_screen_name = routes[routesLength - 2]?.params?.screen?.name;
50
+ }
46
51
 
47
- const routes = props.navigation.getState()?.routes || [];
48
- const routesLength = routes.length;
49
- let pre_screen_name = '';
50
- if (routesLength > 1) {
51
- pre_screen_name = routes[routesLength - 2]?.params?.screen?.name;
52
- }
52
+ navigator?.maxApi?.trackEvent?.('service_frame_displayed', {
53
+ ...tracking,
54
+ pre_screen_name,
55
+ trigger_id: '111378000000000000',
56
+ });
53
57
 
54
- navigator?.maxApi?.trackEvent?.('service_frame_displayed', {
58
+ return props.navigation.addListener('beforeRemove', () => {
59
+ navigator?.maxApi?.trackEvent?.('service_icon_clicked', {
55
60
  ...tracking,
56
- pre_screen_name,
57
- trigger_id: '111378000000000000',
58
- });
59
-
60
- return props.navigation.addListener('beforeRemove', () => {
61
- navigator?.maxApi?.trackEvent?.('service_icon_clicked', {
62
- ...tracking,
63
- trigger_id: '111154000000000000',
64
- icon_name: 'back',
65
- });
61
+ trigger_id: '111154000000000000',
62
+ icon_name: 'back',
66
63
  });
67
- }
64
+ });
68
65
  }, []);
69
66
 
70
67
  return (
71
68
  <ScreenContext.Provider
72
69
  value={{
73
- ...navigator?.trackingInfo,
70
+ ...context,
74
71
  screenName: Component.name,
75
72
  autoTracking: navigator?.maxApi?.autoTracking,
76
73
  }}>
@@ -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,22 +90,12 @@ export type LocalizationObject = {
80
90
  };
81
91
  };
82
92
 
83
- export type TrackingInfo = {
84
- [key: string]: any;
85
- appId: string;
86
- code: string;
87
- screenName: string;
88
- buildNumber: string;
89
- flowPartnerId?: string;
90
- };
91
-
92
93
  export type NavigationContainerProps = {
93
94
  screen: Screen;
94
95
  options?: NavigationOptions;
95
96
  theme: Theme;
96
97
  maxApi: any;
97
98
  localization?: LocalizationObject;
98
- trackingInfo?: TrackingInfo;
99
99
  };
100
100
 
101
101
  export type NavigationScreenProps = {
package/Button/index.tsx CHANGED
@@ -14,7 +14,6 @@ import {Colors, Spacing} from '../Consts';
14
14
  import styles from './styles';
15
15
  import {Icon} from '../Icon';
16
16
  import {Loader} from '../Loader';
17
- import {TrackingInfo} from '../Application/types';
18
17
 
19
18
  const {
20
19
  ScreenContext,
@@ -105,7 +104,7 @@ const Button: FC<ButtonProps> = ({
105
104
  };
106
105
  }
107
106
 
108
- const screenInfo = useContext<TrackingInfo>(ScreenContext);
107
+ const screenInfo = useContext<any>(ScreenContext);
109
108
  const getSizeStyle = () => {
110
109
  const styleSheet: {[key: string]: any} = styles;
111
110
  return styleSheet[size ?? 'small'];
@@ -5,7 +5,6 @@ import styles from './styles';
5
5
  import {ApplicationContext} from '../Application';
6
6
  import {Text} from '../Text';
7
7
  import {Icon} from '../Icon';
8
- import {TrackingInfo} from '../Application/types';
9
8
 
10
9
  const {
11
10
  ScreenContext,
@@ -24,7 +23,7 @@ const CheckBox: FC<CheckBoxProps> = ({
24
23
  const iconSource = indeterminate ? 'ic_minus' : 'ic_checked';
25
24
  let borderColor = theme.colors.text.default;
26
25
  let backgroundColor = theme.colors.background.surface;
27
- const screenInfo = useContext<TrackingInfo>(ScreenContext);
26
+ const screenInfo = useContext<any>(ScreenContext);
28
27
 
29
28
  if (haveValue) {
30
29
  borderColor = theme.colors.primary;
@@ -9,7 +9,6 @@ import {ApplicationContext} from '../Application';
9
9
  import {Colors} from '../Consts';
10
10
  import {Icon} from '../Icon';
11
11
  import styles from './styles';
12
- import {TrackingInfo} from '../Application/types';
13
12
 
14
13
  const {
15
14
  ScreenContext,
@@ -41,7 +40,7 @@ const IconButton: React.FC<IconButtonProps> = ({
41
40
  ...rest
42
41
  }) => {
43
42
  const {theme} = useContext(ApplicationContext);
44
- const screenInfo = useContext<TrackingInfo>(ScreenContext);
43
+ const screenInfo = useContext<any>(ScreenContext);
45
44
 
46
45
  /**
47
46
  * get size icon button
package/Input/Input.tsx CHANGED
@@ -13,7 +13,7 @@ import {InputProps} from './index';
13
13
  import {Icon} from '../Icon';
14
14
  import {checkTyping} from './utils';
15
15
  import {Loader} from '../Loader';
16
- import {TrackingInfo} from '../Application/types';
16
+
17
17
  const {
18
18
  ScreenContext,
19
19
  } = require('react-native/Libraries/Components/ScreenContext');
@@ -53,7 +53,7 @@ const Input = forwardRef(
53
53
  const [haveValue, setHaveValue] = useState(!!value || !!props.defaultValue);
54
54
  const inputRef = (ref as React.RefObject<TextInput>) ?? useRef<TextInput>();
55
55
  const accessibilityLabel = `Input/${floatingValue ?? placeholder}`;
56
- const screenInfo = useContext<TrackingInfo>(ScreenContext);
56
+ const screenInfo = useContext<any>(ScreenContext);
57
57
 
58
58
  const onClearText = () => {
59
59
  inputRef?.current?.clear();
@@ -12,7 +12,7 @@ import {ErrorView, FloatingView, getBorderColor, getSizeStyle} from './common';
12
12
  import {InputMoneyProps} from './index';
13
13
  import {Icon} from '../Icon';
14
14
  import {formatMoneyToNumber, formatNumberToMoney} from './utils';
15
- import {TrackingInfo} from '../Application/types';
15
+
16
16
  const {
17
17
  ScreenContext,
18
18
  } = require('react-native/Libraries/Components/ScreenContext');
@@ -45,7 +45,7 @@ const InputMoney = forwardRef(
45
45
  const [focused, setFocused] = useState(false);
46
46
  const inputRef = (ref as React.RefObject<TextInput>) ?? useRef<TextInput>();
47
47
  const accessibilityLabel = `InputMoney/${floatingValue}`;
48
- const screenInfo = useContext<TrackingInfo>(ScreenContext);
48
+ const screenInfo = useContext<any>(ScreenContext);
49
49
 
50
50
  const validateText = (text: string) => {
51
51
  const valueFormat = formatMoneyToNumber(text, 'đ');
@@ -21,7 +21,7 @@ import styles from './styles';
21
21
  import {ErrorView, getBorderColor} from './common';
22
22
  import {ApplicationContext} from '../Application';
23
23
  import {Spacing} from '../Consts';
24
- import {TrackingInfo} from '../Application/types';
24
+
25
25
  const {
26
26
  ScreenContext,
27
27
  } = require('react-native/Libraries/Components/ScreenContext');
@@ -95,7 +95,7 @@ const InputOTP = forwardRef(
95
95
  const inputRef = useRef<TextInput>(null);
96
96
  const {theme} = useContext(ApplicationContext);
97
97
  const accessibilityLabel = `InputOTP/${floatingValue ?? placeholder}`;
98
- const screenInfo = useContext<TrackingInfo>(ScreenContext);
98
+ const screenInfo = useContext<any>(ScreenContext);
99
99
 
100
100
  useImperativeHandle(ref, () => ({
101
101
  onChangeText: (text: string) => {
@@ -12,7 +12,7 @@ import styles from './styles';
12
12
  import {Icon} from '../Icon';
13
13
  import {Text} from '../Text';
14
14
  import {checkTyping} from './utils';
15
- import {TrackingInfo} from '../Application/types';
15
+
16
16
  const {
17
17
  ScreenContext,
18
18
  } = require('react-native/Libraries/Components/ScreenContext');
@@ -45,7 +45,7 @@ const InputSearch = forwardRef(
45
45
  const [haveValue, setHaveValue] = useState(!!value || !!defaultValue);
46
46
  const inputRef = (ref as React.RefObject<TextInput>) ?? useRef<TextInput>();
47
47
  const accessibilityLabel = `InputMoney/${placeholder}`;
48
- const screenInfo = useContext<TrackingInfo>(ScreenContext);
48
+ const screenInfo = useContext<any>(ScreenContext);
49
49
 
50
50
  const _onFocus = (e: NativeSyntheticEvent<TextInputFocusEventData>) => {
51
51
  setFocused(true);
@@ -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/Radio/index.tsx CHANGED
@@ -6,7 +6,6 @@ import {Text} from '../Text';
6
6
  import styles from './styles';
7
7
  import {ApplicationContext} from '../Application';
8
8
  import {Spacing} from '../Consts';
9
- import {TrackingInfo} from '../Application/types';
10
9
 
11
10
  const {
12
11
  ScreenContext,
@@ -42,7 +41,7 @@ const Radio: FC<RadioProps> = ({
42
41
  };
43
42
  }
44
43
 
45
- const screenInfo = useContext<TrackingInfo>(ScreenContext);
44
+ const screenInfo = useContext<any>(ScreenContext);
46
45
 
47
46
  return (
48
47
  <ScreenContext.Provider
package/Switch/index.tsx CHANGED
@@ -3,7 +3,6 @@ import {TouchableOpacity, View} from 'react-native';
3
3
  import {SwitchProps} from './types';
4
4
  import styles from './styles';
5
5
  import {Colors} from '../Consts';
6
- import {TrackingInfo} from '../Application/types';
7
6
 
8
7
  const {
9
8
  ScreenContext,
@@ -13,7 +12,7 @@ const Switch: FC<SwitchProps> = props => {
13
12
  const {value, onChange, disabled, style} = props;
14
13
  const circleBackgroundColor = value ? Colors.black_01 : Colors.black_03;
15
14
  const circleAlign = value ? 'flex-end' : 'flex-start';
16
- const screenInfo = useContext<TrackingInfo>(ScreenContext);
15
+ const screenInfo = useContext<any>(ScreenContext);
17
16
 
18
17
  let backgroundColor = value ? Colors.green_03 : Colors.black_07;
19
18
  if (disabled) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@momo-kits/foundation",
3
- "version": "0.81.43-tracking.2",
3
+ "version": "0.81.43-tracking.4",
4
4
  "description": "React Native Component Kits",
5
5
  "main": "index.ts",
6
6
  "scripts": {