@momo-kits/foundation 0.103.1-beta.1 → 0.103.1-beta.2
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/Components.tsx +4 -1
- package/Application/Navigator.ts +151 -63
- package/Application/constants.ts +9 -0
- package/Application/types.ts +22 -0
- package/Popup/PopupNotify.tsx +4 -2
- package/Popup/PopupPromotion.tsx +4 -2
- package/package.json +1 -1
|
@@ -26,6 +26,7 @@ import {
|
|
|
26
26
|
HeaderBackgroundProps,
|
|
27
27
|
HeaderBackProps,
|
|
28
28
|
NavigationButtonProps,
|
|
29
|
+
RouteParams,
|
|
29
30
|
TitleCustomProps,
|
|
30
31
|
} from './types';
|
|
31
32
|
import {scaleSize, Text} from '../Text';
|
|
@@ -153,7 +154,9 @@ const HeaderLeft: React.FC<HeaderBackProps> = ({
|
|
|
153
154
|
const params = {
|
|
154
155
|
appId: context.appId,
|
|
155
156
|
code: context.code,
|
|
156
|
-
screen_name:
|
|
157
|
+
screen_name:
|
|
158
|
+
(currentRoute?.params as RouteParams)?.screen?.name ??
|
|
159
|
+
currentRoute?.name,
|
|
157
160
|
trigger_id: '111154000000000000',
|
|
158
161
|
icon_name: 'back',
|
|
159
162
|
};
|
package/Application/Navigator.ts
CHANGED
|
@@ -1,95 +1,170 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
CommonActions,
|
|
3
|
+
NavigationContainerRef,
|
|
4
|
+
StackActions,
|
|
5
|
+
} from '@react-navigation/native';
|
|
2
6
|
import {
|
|
3
7
|
BottomSheetParams,
|
|
4
8
|
HeaderToolkitProps,
|
|
5
9
|
ModalParams,
|
|
10
|
+
NavigatorCallbackParamsType,
|
|
6
11
|
ScreenParams,
|
|
7
12
|
} from './types';
|
|
13
|
+
import React from 'react';
|
|
14
|
+
import {
|
|
15
|
+
NavigationActionCallbackErrorEnum,
|
|
16
|
+
NavigationActionCallbackStatusEnum,
|
|
17
|
+
} from './constants';
|
|
8
18
|
|
|
9
19
|
class Navigator {
|
|
10
|
-
ref
|
|
11
|
-
isReady
|
|
20
|
+
ref: React.RefObject<NavigationContainerRef>;
|
|
21
|
+
isReady: React.MutableRefObject<boolean>;
|
|
12
22
|
toolkitConfig?: HeaderToolkitProps;
|
|
13
23
|
maxApi?: any;
|
|
14
|
-
dismissData?:
|
|
24
|
+
dismissData?: unknown;
|
|
15
25
|
toolkitCallback?: (key: string) => void;
|
|
16
26
|
|
|
17
|
-
constructor(
|
|
27
|
+
constructor(
|
|
28
|
+
navigation: React.RefObject<NavigationContainerRef>,
|
|
29
|
+
isReady: React.MutableRefObject<boolean>
|
|
30
|
+
) {
|
|
18
31
|
this.ref = navigation;
|
|
19
32
|
this.isReady = isReady;
|
|
20
33
|
}
|
|
21
34
|
|
|
35
|
+
private validateRefAndRunAction = (params: {
|
|
36
|
+
action: (navigationRef: NavigationContainerRef) => void;
|
|
37
|
+
callback?: (params: NavigatorCallbackParamsType) => void;
|
|
38
|
+
}) => {
|
|
39
|
+
try {
|
|
40
|
+
if (this.isReady.current && this.ref.current) {
|
|
41
|
+
params.action(this.ref.current);
|
|
42
|
+
params.callback?.({status: NavigationActionCallbackStatusEnum.Success});
|
|
43
|
+
} else {
|
|
44
|
+
params.callback?.({
|
|
45
|
+
status: NavigationActionCallbackStatusEnum.Failed,
|
|
46
|
+
type: NavigationActionCallbackErrorEnum.NotReady,
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
} catch (error) {
|
|
50
|
+
params.callback?.({
|
|
51
|
+
status: NavigationActionCallbackStatusEnum.Failed,
|
|
52
|
+
type: NavigationActionCallbackErrorEnum.Error,
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
|
|
22
57
|
/**
|
|
23
58
|
* push new stack screen
|
|
24
59
|
* @param params
|
|
25
60
|
*/
|
|
26
|
-
push = (
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
61
|
+
push = (
|
|
62
|
+
params: ScreenParams,
|
|
63
|
+
callback?: (params: NavigatorCallbackParamsType) => void
|
|
64
|
+
) => {
|
|
65
|
+
this.validateRefAndRunAction({
|
|
66
|
+
action: navigationRef => {
|
|
67
|
+
navigationRef.dispatch(StackActions.push('Stack', params));
|
|
68
|
+
},
|
|
69
|
+
callback,
|
|
70
|
+
});
|
|
30
71
|
};
|
|
31
72
|
|
|
32
73
|
/**
|
|
33
74
|
* replace current screen with new screen
|
|
34
75
|
* @param params
|
|
35
76
|
*/
|
|
36
|
-
replace = (
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
77
|
+
replace = (
|
|
78
|
+
params: ScreenParams,
|
|
79
|
+
callback?: (params: NavigatorCallbackParamsType) => void
|
|
80
|
+
) => {
|
|
81
|
+
this.validateRefAndRunAction({
|
|
82
|
+
action: navigationRef => {
|
|
83
|
+
navigationRef.dispatch(StackActions.replace('Stack', params));
|
|
84
|
+
},
|
|
85
|
+
callback,
|
|
86
|
+
});
|
|
40
87
|
};
|
|
41
88
|
/**
|
|
42
89
|
* pop to dismiss a screen
|
|
43
90
|
* @param count
|
|
44
91
|
*/
|
|
45
|
-
pop = (
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
92
|
+
pop = (
|
|
93
|
+
count?: number,
|
|
94
|
+
callback?: (params: NavigatorCallbackParamsType) => void
|
|
95
|
+
) => {
|
|
96
|
+
this.validateRefAndRunAction({
|
|
97
|
+
action: navigationRef => {
|
|
98
|
+
navigationRef.dispatch(StackActions.pop(count ?? 1));
|
|
99
|
+
},
|
|
100
|
+
callback,
|
|
101
|
+
});
|
|
49
102
|
};
|
|
50
103
|
|
|
51
104
|
/**
|
|
52
105
|
* present a new screen, show from bottom iOS
|
|
53
106
|
* @param params
|
|
54
107
|
*/
|
|
55
|
-
present = (
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
108
|
+
present = (
|
|
109
|
+
params: ScreenParams,
|
|
110
|
+
callback?: (params: NavigatorCallbackParamsType) => void
|
|
111
|
+
) => {
|
|
112
|
+
this.validateRefAndRunAction({
|
|
113
|
+
action: navigationRef => {
|
|
114
|
+
navigationRef.dispatch(StackActions.push('Dialog', params));
|
|
115
|
+
},
|
|
116
|
+
callback,
|
|
117
|
+
});
|
|
59
118
|
};
|
|
60
119
|
|
|
61
120
|
/**
|
|
62
121
|
* show a modal popup
|
|
63
122
|
* @param params
|
|
64
123
|
*/
|
|
65
|
-
showModal = (
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
124
|
+
showModal = (
|
|
125
|
+
params: ModalParams,
|
|
126
|
+
callback?: (params: NavigatorCallbackParamsType) => void
|
|
127
|
+
) => {
|
|
128
|
+
this.validateRefAndRunAction({
|
|
129
|
+
action: navigationRef => {
|
|
130
|
+
navigationRef.dispatch(StackActions.push('Modal', params));
|
|
131
|
+
},
|
|
132
|
+
callback,
|
|
133
|
+
});
|
|
69
134
|
};
|
|
70
135
|
|
|
71
136
|
/**
|
|
72
137
|
* show a bottom sheet
|
|
73
138
|
* @param params
|
|
139
|
+
* @param callback
|
|
74
140
|
*/
|
|
75
|
-
showBottomSheet = (
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
141
|
+
showBottomSheet = (
|
|
142
|
+
params: BottomSheetParams,
|
|
143
|
+
callback?: (params: NavigatorCallbackParamsType) => void
|
|
144
|
+
) => {
|
|
145
|
+
this.validateRefAndRunAction({
|
|
146
|
+
action: navigationRef => {
|
|
147
|
+
navigationRef.dispatch(
|
|
148
|
+
StackActions.push('Modal', {
|
|
149
|
+
...params,
|
|
150
|
+
isBottomSheet: true,
|
|
151
|
+
})
|
|
152
|
+
);
|
|
153
|
+
},
|
|
154
|
+
callback,
|
|
155
|
+
});
|
|
84
156
|
};
|
|
85
157
|
|
|
86
158
|
/**
|
|
87
159
|
* pop all screen route
|
|
88
160
|
*/
|
|
89
|
-
popToTop = () => {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
161
|
+
popToTop = (callback?: (params: NavigatorCallbackParamsType) => void) => {
|
|
162
|
+
this.validateRefAndRunAction({
|
|
163
|
+
action: navigationRef => {
|
|
164
|
+
navigationRef.dispatch(StackActions.popToTop());
|
|
165
|
+
},
|
|
166
|
+
callback,
|
|
167
|
+
});
|
|
93
168
|
};
|
|
94
169
|
|
|
95
170
|
/**
|
|
@@ -97,43 +172,56 @@ class Navigator {
|
|
|
97
172
|
* @param name
|
|
98
173
|
* @param params
|
|
99
174
|
*/
|
|
100
|
-
navigate = (
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
175
|
+
navigate = (
|
|
176
|
+
name: string,
|
|
177
|
+
params: any,
|
|
178
|
+
callback?: (params: NavigatorCallbackParamsType) => void
|
|
179
|
+
) => {
|
|
180
|
+
this.validateRefAndRunAction({
|
|
181
|
+
action: navigationRef => {
|
|
182
|
+
navigationRef.dispatch(
|
|
183
|
+
CommonActions.navigate({
|
|
184
|
+
name,
|
|
185
|
+
params,
|
|
186
|
+
})
|
|
187
|
+
);
|
|
188
|
+
},
|
|
189
|
+
callback,
|
|
190
|
+
});
|
|
109
191
|
};
|
|
110
192
|
|
|
111
193
|
/**
|
|
112
194
|
* reset a navigation flow with new screen
|
|
113
195
|
* @param params
|
|
114
196
|
*/
|
|
115
|
-
reset = (
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
197
|
+
reset = (
|
|
198
|
+
params: ScreenParams,
|
|
199
|
+
callback?: (params: NavigatorCallbackParamsType) => void
|
|
200
|
+
) => {
|
|
201
|
+
this.validateRefAndRunAction({
|
|
202
|
+
action: navigationRef => {
|
|
203
|
+
navigationRef.dispatch(
|
|
204
|
+
CommonActions.reset({
|
|
205
|
+
index: 0,
|
|
206
|
+
routes: [
|
|
207
|
+
{
|
|
208
|
+
name: 'Stack',
|
|
209
|
+
key: `Stack_${new Date().getTime()}`,
|
|
210
|
+
params,
|
|
211
|
+
},
|
|
212
|
+
],
|
|
213
|
+
})
|
|
214
|
+
);
|
|
215
|
+
},
|
|
216
|
+
callback,
|
|
217
|
+
});
|
|
130
218
|
};
|
|
131
219
|
|
|
132
220
|
/**
|
|
133
221
|
* dismiss a feature data
|
|
134
222
|
* @param data
|
|
135
223
|
*/
|
|
136
|
-
setDismissData = (data:
|
|
224
|
+
setDismissData = (data: unknown) => {
|
|
137
225
|
this.dismissData = data;
|
|
138
226
|
};
|
|
139
227
|
|
package/Application/types.ts
CHANGED
|
@@ -6,6 +6,10 @@ import {PopupNotifyProps} from '../Popup/types';
|
|
|
6
6
|
import Localize from './Localize';
|
|
7
7
|
import Navigation from './Navigation';
|
|
8
8
|
import Navigator from './Navigator';
|
|
9
|
+
import {
|
|
10
|
+
NavigationActionCallbackErrorEnum,
|
|
11
|
+
NavigationActionCallbackStatusEnum,
|
|
12
|
+
} from './constants';
|
|
9
13
|
|
|
10
14
|
type Screen = React.ComponentType<NavigationScreenProps>;
|
|
11
15
|
|
|
@@ -243,3 +247,21 @@ export type AnimatedHeader = {
|
|
|
243
247
|
component?: (props?: any) => React.ReactElement;
|
|
244
248
|
headerTitle?: (props?: any) => React.ReactElement;
|
|
245
249
|
};
|
|
250
|
+
|
|
251
|
+
export interface RouteParams {
|
|
252
|
+
screen?: {
|
|
253
|
+
name?: string;
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
type NavigatorActionSuccessCallbackType = {
|
|
257
|
+
status: NavigationActionCallbackStatusEnum.Success;
|
|
258
|
+
};
|
|
259
|
+
|
|
260
|
+
type NavigatorActionFailCallbackType = {
|
|
261
|
+
status: NavigationActionCallbackStatusEnum.Failed;
|
|
262
|
+
type: NavigationActionCallbackErrorEnum;
|
|
263
|
+
};
|
|
264
|
+
|
|
265
|
+
export type NavigatorCallbackParamsType =
|
|
266
|
+
| NavigatorActionSuccessCallbackType
|
|
267
|
+
| NavigatorActionFailCallbackType;
|
package/Popup/PopupNotify.tsx
CHANGED
|
@@ -7,6 +7,7 @@ import {Icon} from '../Icon';
|
|
|
7
7
|
import {Image} from '../Image';
|
|
8
8
|
import {scaleSize, Text} from '../Text';
|
|
9
9
|
import {PopupNotifyProps} from './types';
|
|
10
|
+
import {RouteParams} from '../Application/types';
|
|
10
11
|
|
|
11
12
|
const PopupNotify: React.FC<PopupNotifyProps> = ({
|
|
12
13
|
id,
|
|
@@ -35,9 +36,10 @@ const PopupNotify: React.FC<PopupNotifyProps> = ({
|
|
|
35
36
|
useEffect(() => {
|
|
36
37
|
const routes = navigator?.ref.current?.getRootState()?.routes || [];
|
|
37
38
|
const routesLength = routes.length;
|
|
38
|
-
let screen_name = routes?.[0]?.params?.screen?.name;
|
|
39
|
+
let screen_name = (routes?.[0]?.params as RouteParams)?.screen?.name;
|
|
39
40
|
if (routesLength > 1) {
|
|
40
|
-
screen_name = routes[routesLength - 2]?.params?.screen
|
|
41
|
+
screen_name = (routes[routesLength - 2]?.params as RouteParams)?.screen
|
|
42
|
+
?.name;
|
|
41
43
|
}
|
|
42
44
|
const tracking = {
|
|
43
45
|
appId: context.appId,
|
package/Popup/PopupPromotion.tsx
CHANGED
|
@@ -5,6 +5,7 @@ import {ApplicationContext, MiniAppContext} from '../Application';
|
|
|
5
5
|
import {Image} from '../Image';
|
|
6
6
|
import {Radius, Spacing} from '../Consts';
|
|
7
7
|
import {Icon} from '../Icon';
|
|
8
|
+
import {RouteParams} from '../Application/types';
|
|
8
9
|
|
|
9
10
|
const PopupPromotion: React.FC<PopupPromotionProps> = ({
|
|
10
11
|
id,
|
|
@@ -21,9 +22,10 @@ const PopupPromotion: React.FC<PopupPromotionProps> = ({
|
|
|
21
22
|
useEffect(() => {
|
|
22
23
|
const routes = navigator?.ref.current?.getRootState()?.routes || [];
|
|
23
24
|
const routesLength = routes.length;
|
|
24
|
-
let screen_name = routes?.[0]?.params?.screen?.name;
|
|
25
|
+
let screen_name = (routes?.[0]?.params as RouteParams)?.screen?.name;
|
|
25
26
|
if (routesLength > 1) {
|
|
26
|
-
screen_name = routes[routesLength - 2]?.params?.screen
|
|
27
|
+
screen_name = (routes[routesLength - 2]?.params as RouteParams)?.screen
|
|
28
|
+
?.name;
|
|
27
29
|
}
|
|
28
30
|
const tracking = {
|
|
29
31
|
appId: context.appId,
|