@momo-kits/foundation 0.102.6-beta.8 → 0.102.6-beta.9

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,18 +15,19 @@ import {Colors, Radius, Spacing} from '../Consts';
15
15
  */
16
16
  const StackScreen: React.FC<ScreenParams> = props => {
17
17
  const {showGrid, navigator} = useContext(ApplicationContext);
18
- const startTime = useRef(Date.now());
19
- const endTime = useRef(Date.now());
20
- const timeLoad = useRef(0);
21
- const timeInteraction = useRef(0);
22
- const timeoutLoad = useRef<any>();
23
- const tracked = useRef<any>({
18
+ const tracking = useRef<any>({
19
+ timeoutLoad: undefined,
20
+ interaction: undefined,
21
+ startTime: Date.now(),
22
+ endTime: Date.now(),
24
23
  traceIdLoad: undefined,
25
24
  traceIdInteraction: undefined,
26
25
  releaseLoad: undefined,
27
26
  releaseInteraction: undefined,
27
+ timeLoad: 0,
28
+ timeInteraction: 0,
28
29
  });
29
- const interaction = useRef<any>();
30
+
30
31
  const context = useContext<any>(MiniAppContext);
31
32
  const {screen: Component, options, initialParams} = props.route.params;
32
33
  const navigation = new Navigation(props.navigation);
@@ -71,19 +72,22 @@ const StackScreen: React.FC<ScreenParams> = props => {
71
72
  }, 300);
72
73
  }
73
74
  navigator?.maxApi?.of?.({screenName});
74
- navigator?.maxApi?.getDataObserver('CURRENT_SCREEN', (data: any) => {
75
- if (data) {
76
- Alert.alert('getDataObserver', JSON.stringify(data));
77
- }
78
- navigator?.maxApi?.setObserver('CURRENT_SCREEN', {screenName});
75
+ props.navigation?.addListener?.('focus', () => {
76
+ navigator?.maxApi?.getDataObserver('CURRENT_SCREEN', (data: any) => {
77
+ if (data) {
78
+ Alert.alert('getDataObserver', JSON.stringify(data));
79
+ }
80
+ navigator?.maxApi?.setObserver('CURRENT_SCREEN', {screenName});
81
+ });
79
82
  });
83
+
80
84
  navigator?.maxApi?.startTraceScreenLoad?.(screenName, (data: any) => {
81
- tracked.current.traceIdLoad = data?.traceId;
85
+ tracking.current.traceIdLoad = data?.traceId;
82
86
  });
83
87
  navigator?.maxApi?.startTraceScreenInteraction?.(
84
88
  screenName,
85
89
  (data: any) => {
86
- tracked.current.traceIdInteraction = data?.traceId;
90
+ tracking.current.traceIdInteraction = data?.traceId;
87
91
  }
88
92
  );
89
93
  return () => {
@@ -96,9 +100,10 @@ const StackScreen: React.FC<ScreenParams> = props => {
96
100
  * tracking for screen load
97
101
  */
98
102
  const onScreenLoad = () => {
99
- if (!tracked.current?.releaseLoad) {
100
- if (timeLoad.current === 0) {
101
- timeLoad.current = endTime.current - startTime.current;
103
+ if (!tracking.current?.releaseLoad) {
104
+ if (tracking.current.timeLoad === 0) {
105
+ tracking.current.timeLoad =
106
+ tracking.current.endTime - tracking.current.startTime;
102
107
  }
103
108
 
104
109
  context.autoTracking?.({
@@ -109,24 +114,24 @@ const StackScreen: React.FC<ScreenParams> = props => {
109
114
  action: 'push',
110
115
  componentName: 'Screen',
111
116
  state: 'load',
112
- duration: timeLoad.current,
117
+ duration: tracking.current.timeLoad,
113
118
  });
114
119
  navigator?.maxApi?.stopTrace?.(
115
- tracked.current.traceIdLoad,
116
- {value: timeLoad.current / 1000},
120
+ tracking.current.traceIdLoad,
121
+ {value: tracking.current.timeLoad / 1000},
117
122
  null
118
123
  );
119
- tracked.current.releaseLoad = true;
124
+ tracking.current.releaseLoad = true;
120
125
 
121
126
  /**
122
127
  * debug
123
128
  */
124
129
  navigator?.maxApi?.showToastDebug?.({
125
130
  appId: context.appId,
126
- message: `${screenName} screen_load_time ${timeLoad.current}`,
131
+ message: `${screenName} screen_load_time ${tracking.current.timeLoad}`,
127
132
  type: 'ERROR',
128
133
  });
129
- if (timeLoad.current <= 0 && context.enableAutoId) {
134
+ if (tracking.current.timeLoad <= 0 && context.enableAutoId) {
130
135
  Alert.alert(screenName, "Can't get screen load time");
131
136
  }
132
137
  }
@@ -136,12 +141,13 @@ const StackScreen: React.FC<ScreenParams> = props => {
136
141
  * tracking for screen load
137
142
  */
138
143
  const onScreenInteraction = () => {
139
- if (!tracked.current?.releaseInteraction) {
140
- if (timeLoad.current === 0) {
141
- timeLoad.current = endTime.current - startTime.current;
144
+ if (!tracking.current?.releaseInteraction) {
145
+ if (tracking.current.timeLoad === 0) {
146
+ tracking.current.timeLoad =
147
+ tracking.current.endTime - tracking.current.startTime;
142
148
  }
143
- if (timeInteraction.current === 0) {
144
- timeInteraction.current = timeLoad.current;
149
+ if (tracking.current.timeInteraction === 0) {
150
+ tracking.current.timeInteraction = tracking.current.timeLoad;
145
151
  }
146
152
 
147
153
  context.autoTracking?.({
@@ -151,24 +157,24 @@ const StackScreen: React.FC<ScreenParams> = props => {
151
157
  screenName,
152
158
  componentName: 'Screen',
153
159
  state: 'interaction',
154
- duration: timeInteraction.current - timeLoad.current,
160
+ duration: tracking.current.timeInteraction - tracking.current.timeLoad,
155
161
  });
156
162
  navigator?.maxApi?.stopTrace?.(
157
- tracked.current.traceIdInteraction,
158
- {value: timeInteraction.current / 1000},
163
+ tracking.current.traceIdInteraction,
164
+ {value: tracking.current.timeInteraction / 1000},
159
165
  null
160
166
  );
161
- tracked.current.releaseInteraction = true;
167
+ tracking.current.releaseInteraction = true;
162
168
 
163
169
  /**
164
170
  * debug toast
165
171
  */
166
172
  navigator?.maxApi?.showToastDebug?.({
167
173
  appId: context.appId,
168
- message: `${screenName} screen_interaction_time ${timeInteraction.current}`,
174
+ message: `${screenName} screen_interaction_time ${tracking.current.timeInteraction}`,
169
175
  type: 'ERROR',
170
176
  });
171
- if (timeInteraction.current <= 0 && context.enableAutoId) {
177
+ if (tracking.current.timeInteraction <= 0 && context.enableAutoId) {
172
178
  Alert.alert(screenName, "Can't get screen interaction time");
173
179
  }
174
180
  }
@@ -179,15 +185,18 @@ const StackScreen: React.FC<ScreenParams> = props => {
179
185
  value={{
180
186
  screenName,
181
187
  onElementLoad: () => {
182
- clearTimeout(timeoutLoad.current);
183
- endTime.current = Date.now();
184
- interaction.current?.cancel?.();
185
- interaction.current = InteractionManager.runAfterInteractions(() => {
186
- timeInteraction.current = Date.now() - startTime.current;
187
- });
188
- timeoutLoad.current = setTimeout(() => {
189
- if (timeLoad.current === 0) {
190
- timeLoad.current = endTime.current - startTime.current;
188
+ clearTimeout(tracking.current.timeoutLoad);
189
+ tracking.current.endTime = Date.now();
190
+ tracking.current.interaction?.cancel?.();
191
+ tracking.current.interaction =
192
+ InteractionManager.runAfterInteractions(() => {
193
+ tracking.current.timeInteraction =
194
+ Date.now() - tracking.current.startTime;
195
+ });
196
+ tracking.current.timeoutLoad = setTimeout(() => {
197
+ if (tracking.current.timeLoad === 0) {
198
+ tracking.current.timeLoad =
199
+ tracking.current.endTime - tracking.current.startTime;
191
200
  }
192
201
  onScreenLoad();
193
202
  onScreenInteraction();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@momo-kits/foundation",
3
- "version": "0.102.6-beta.8",
3
+ "version": "0.102.6-beta.9",
4
4
  "description": "React Native Component Kits",
5
5
  "main": "index.ts",
6
6
  "scripts": {},