@momo-kits/foundation 0.169.16-beta.7 → 0.169.16-beta.8
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/BottomSheet.tsx +2 -2
- package/Application/BottomTab/BottomTabBar.styles.ts +1 -1
- package/Application/BottomTab/DuoTabBar.styles.ts +1 -1
- package/Application/BottomTab/Legacy/TabScreen.tsx +22 -16
- package/Application/BottomTab/Legacy/hooks.ts +1 -1
- package/Application/BottomTab/Legacy/index.tsx +1 -5
- package/Application/BottomTab/TabBarIcon.tsx +1 -1
- package/Application/BottomTab/TabScreen.tsx +22 -12
- package/Application/BottomTab/index.tsx +1 -1
- package/Application/Components/HeaderLeft.tsx +2 -2
- package/Application/Components/SearchHeader.tsx +2 -2
- package/Application/Components/SwipeBackHaptic.tsx +1 -1
- package/Application/Components/useToolkitActions.tsx +64 -34
- package/Application/ModalScreen.tsx +4 -4
- package/Application/NavigationContainer.tsx +10 -11
- package/Application/Navigator.ts +2 -7
- package/Application/StackScreen.tracking.ts +12 -22
- package/Application/StackScreen.tsx +34 -26
- package/Application/TooltipPortal.tsx +3 -3
- package/Application/WidgetContainer.tsx +6 -9
- package/Application/hooks.ts +1 -15
- package/Application/index.ts +0 -4
- package/Application/types.ts +3 -16
- package/Button/index.tsx +2 -2
- package/Divider/DashDivider.tsx +2 -2
- package/Divider/index.tsx +3 -3
- package/FoundationList/index.tsx +1 -1
- package/Icon/types.ts +2 -1
- package/Image/index.tsx +7 -62
- package/Image/styles.ts +0 -2
- package/Image/types.ts +1 -9
- package/Input/Input.tsx +2 -2
- package/Input/InputMoney.tsx +2 -7
- package/Input/InputMoneyView.tsx +2 -2
- package/Input/InputOTP.tsx +2 -2
- package/Input/InputPhoneNumber.tsx +2 -2
- package/Input/InputSearch.tsx +2 -2
- package/Input/InputTextArea.tsx +2 -2
- package/Input/SearchTextTyping.tsx +2 -2
- package/Input/SystemTextInput.tsx +1 -2
- package/Input/TextTyping.tsx +2 -7
- package/Pagination/types.ts +2 -6
- package/package.json +26 -28
- package/Application/KitsBindingProvider.tsx +0 -22
- package/Application/KitsHost.ts +0 -183
- package/Application/__tests__/KitsHost.test.ts +0 -155
- package/Application/types.binding.ts +0 -134
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/* eslint-disable react-hooks/exhaustive-deps */
|
|
2
2
|
import React, { FC, useEffect, useRef } from 'react';
|
|
3
|
-
import { TextInput
|
|
3
|
+
import { TextInput } from 'react-native';
|
|
4
4
|
import { useScaleSize, exportFontFamily } from '../Text';
|
|
5
5
|
import styles from './styles';
|
|
6
6
|
|
|
@@ -13,7 +13,7 @@ export const TextTyping: FC<any> = ({
|
|
|
13
13
|
timeDelayEnd = 2000,
|
|
14
14
|
timeDelayNextChar = 20,
|
|
15
15
|
}) => {
|
|
16
|
-
const textRef = useRef<
|
|
16
|
+
const textRef = useRef<TextInput>(null);
|
|
17
17
|
const scaledFontSize = useScaleSize(12);
|
|
18
18
|
const typingFontFamily = exportFontFamily('regular');
|
|
19
19
|
|
|
@@ -4,12 +4,11 @@ import {
|
|
|
4
4
|
TextInput,
|
|
5
5
|
TextInputProps,
|
|
6
6
|
TouchableOpacity,
|
|
7
|
-
type TextInputInstance,
|
|
8
7
|
} from 'react-native';
|
|
9
8
|
import { Styles } from '../Consts';
|
|
10
9
|
|
|
11
10
|
interface SystemTextInputProps extends TextInputProps {
|
|
12
|
-
ref?: React.RefObject<
|
|
11
|
+
ref?: React.RefObject<TextInput | null>;
|
|
13
12
|
}
|
|
14
13
|
|
|
15
14
|
/**
|
package/Input/TextTyping.tsx
CHANGED
|
@@ -1,11 +1,6 @@
|
|
|
1
1
|
/* eslint-disable react-hooks/exhaustive-deps */
|
|
2
2
|
import React, { FC, memo, useEffect, useRef } from 'react';
|
|
3
|
-
import {
|
|
4
|
-
Platform,
|
|
5
|
-
TextInput,
|
|
6
|
-
TextStyle,
|
|
7
|
-
type TextInputInstance,
|
|
8
|
-
} from 'react-native';
|
|
3
|
+
import { Platform, TextInput, TextStyle } from 'react-native';
|
|
9
4
|
import { Colors } from '../Consts';
|
|
10
5
|
import { useScaleSize, exportFontFamily } from '../Text';
|
|
11
6
|
|
|
@@ -26,7 +21,7 @@ const TextTyping: FC<TextTypingProps> = ({
|
|
|
26
21
|
timeDelayNextChar = 20,
|
|
27
22
|
inputStyle = {},
|
|
28
23
|
}) => {
|
|
29
|
-
const textRef = useRef<
|
|
24
|
+
const textRef = useRef<TextInput>(null);
|
|
30
25
|
const scaledFontSize = useScaleSize(12);
|
|
31
26
|
const inputFontFamily = exportFontFamily('regular');
|
|
32
27
|
|
package/Pagination/types.ts
CHANGED
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ScrollViewProps,
|
|
3
|
-
ViewStyle,
|
|
4
|
-
type ScrollViewInstance,
|
|
5
|
-
} from 'react-native';
|
|
1
|
+
import {ScrollView, ScrollViewProps, ViewStyle} from 'react-native';
|
|
6
2
|
import {Ref} from 'react';
|
|
7
3
|
|
|
8
4
|
export type PaginationProps = {
|
|
@@ -36,7 +32,7 @@ export interface ScrollIndicatorProps extends ScrollViewProps {
|
|
|
36
32
|
* Optional. Represents a reference to the ScrollView component.
|
|
37
33
|
* It can be used to access the instance methods of the ScrollView.
|
|
38
34
|
*/
|
|
39
|
-
scrollViewRef?: Ref<
|
|
35
|
+
scrollViewRef?: Ref<ScrollView>;
|
|
40
36
|
}
|
|
41
37
|
|
|
42
38
|
export type ChildPaginationProps = Omit<PaginationProps, 'type'>;
|
package/package.json
CHANGED
|
@@ -1,41 +1,39 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@momo-kits/foundation",
|
|
3
|
-
"version": "0.169.16-beta.
|
|
3
|
+
"version": "0.169.16-beta.8",
|
|
4
4
|
"description": "React Native Component Kits",
|
|
5
|
+
"main": "index.ts",
|
|
6
|
+
"scripts": {},
|
|
5
7
|
"keywords": [
|
|
6
8
|
"@momo-kits/foundation"
|
|
7
9
|
],
|
|
8
|
-
"license": "MoMo",
|
|
9
|
-
"main": "index.ts",
|
|
10
|
-
"publishConfig": {
|
|
11
|
-
"registry": "https://registry.npmjs.org/"
|
|
12
|
-
},
|
|
13
|
-
"scripts": {},
|
|
14
10
|
"dependencies": {
|
|
15
|
-
"
|
|
16
|
-
"@react-navigation/
|
|
17
|
-
"@react-navigation/
|
|
18
|
-
"@react-navigation/
|
|
19
|
-
"@react-navigation/
|
|
20
|
-
"@react-navigation/
|
|
11
|
+
"react-native-fast-image": "git+https://oauth2:TGi6oBj-LdzsKpLXQSoH@gitlab.mservice.com.vn/momo-platform/public/react-native-fast-image.git#v8.11.0",
|
|
12
|
+
"@react-navigation/bottom-tabs": "7.4.2",
|
|
13
|
+
"@react-navigation/core": "7.12.1",
|
|
14
|
+
"@react-navigation/elements": "2.5.2",
|
|
15
|
+
"@react-navigation/native": "7.1.14",
|
|
16
|
+
"@react-navigation/routers": "7.4.1",
|
|
17
|
+
"@react-navigation/stack": "7.4.2",
|
|
18
|
+
"react-native-gesture-handler": "2.27.1",
|
|
19
|
+
"react-native-linear-gradient": "git+https://oauth2:TGi6oBj-LdzsKpLXQSoH@gitlab.mservice.com.vn/momo-platform/public/react-native-linear-gradient#v3.0.0",
|
|
20
|
+
"react-native-reanimated": "4.1.3",
|
|
21
|
+
"react-native-worklets": "0.6.1",
|
|
22
|
+
"react-native-safe-area-context": "5.5.2",
|
|
23
|
+
"react-native-reserved-regions": "0.2.0",
|
|
21
24
|
"@shopify/flash-list": "2.1.0",
|
|
22
|
-
"lottie-react-native": "7.
|
|
23
|
-
"react-native-fast-image": "git+https://oauth2:k_r5y_gV6sX9-TqQxgcd@gitlab.mservice.com.vn/momo-platform/public/react-native-fast-image.git#v8.11.0",
|
|
24
|
-
"react-native-gesture-handler": "3.4.0",
|
|
25
|
-
"react-native-linear-gradient": "git+https://oauth2:k_r5y_gV6sX9-TqQxgcd@gitlab.mservice.com.vn/momo-platform/public/react-native-linear-gradient#v3.0.0",
|
|
26
|
-
"react-native-reanimated": "4.7.1",
|
|
27
|
-
"react-native-safe-area-context": "5.7.0",
|
|
28
|
-
"react-native-reserved-regions": "0.2.0"
|
|
29
|
-
},
|
|
30
|
-
"devDependencies": {
|
|
31
|
-
"@types/color": "3.0.6",
|
|
32
|
-
"react-native-reanimated": "4.7.1",
|
|
33
|
-
"react-native-worklets": "0.13.0"
|
|
25
|
+
"lottie-react-native": "7.2.4"
|
|
34
26
|
},
|
|
35
27
|
"peerDependencies": {
|
|
36
28
|
"react-native": "*",
|
|
37
29
|
"react-native-svg": "*",
|
|
38
|
-
"react-native-
|
|
39
|
-
|
|
40
|
-
|
|
30
|
+
"react-native-worklets": "0.6.1"
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"@types/color": "3.0.6"
|
|
34
|
+
},
|
|
35
|
+
"publishConfig": {
|
|
36
|
+
"registry": "https://registry.npmjs.org/"
|
|
37
|
+
},
|
|
38
|
+
"license": "MoMo"
|
|
41
39
|
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import React, { createContext, FC } from 'react';
|
|
2
|
-
import type { KitsBinding, KitsBindingProviderProps } from './types.binding';
|
|
3
|
-
|
|
4
|
-
/** A host's `KitsBindingProvider` hand-off; kit containers never set it. */
|
|
5
|
-
const KitsBindingContext = createContext<KitsBinding | undefined>(undefined);
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Host hand-off: a mini app container (MMApplication) that doesn't render the
|
|
9
|
-
* mini app's kit containers gives them `binding`, unless one passes its own.
|
|
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 };
|
package/Application/KitsHost.ts
DELETED
|
@@ -1,183 +0,0 @@
|
|
|
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
|
-
/** What the kit does without a host: every service is inert. */
|
|
14
|
-
const DefaultKitsBinding: ResolvedKitsBinding = {
|
|
15
|
-
dismiss: () => {},
|
|
16
|
-
trackEvent: () => {},
|
|
17
|
-
getLanguage: () => NO_REQUEST,
|
|
18
|
-
vibrateLight: () => {},
|
|
19
|
-
checkFavorite: () => NO_REQUEST,
|
|
20
|
-
toggleFavorite: () => NO_REQUEST,
|
|
21
|
-
showToolkit: () => NO_REQUEST,
|
|
22
|
-
showHelpCenter: () => NO_REQUEST,
|
|
23
|
-
logError: () => {},
|
|
24
|
-
observeConfig: () => NO_SUBSCRIPTION,
|
|
25
|
-
observeFavorites: () => NO_SUBSCRIPTION,
|
|
26
|
-
getCurrentScreen: () => NO_REQUEST,
|
|
27
|
-
setCurrentScreen: () => {},
|
|
28
|
-
onFocusApp: () => NO_SUBSCRIPTION,
|
|
29
|
-
startScreenTrace: () => NO_REQUEST,
|
|
30
|
-
stopTrace: () => {},
|
|
31
|
-
showToastDebug: () => {},
|
|
32
|
-
showNoticePopup: () => {},
|
|
33
|
-
openWeb: () => {},
|
|
34
|
-
startFeatureCode: () => {},
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
// Resolved bindings delegate to the host, so one installed as the host would loop.
|
|
38
|
-
const resolvedBindings = new WeakSet<KitsBinding>();
|
|
39
|
-
let installed: KitsBinding | undefined;
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* The host app installs its binding here once; a container uses it unless one
|
|
43
|
-
* is passed in or handed off. Until then `binding` is `DefaultKitsBinding`.
|
|
44
|
-
*/
|
|
45
|
-
const KitsHost = {
|
|
46
|
-
get binding(): KitsBinding {
|
|
47
|
-
return installed ?? DefaultKitsBinding;
|
|
48
|
-
},
|
|
49
|
-
/** The last install wins. The kit borrows the binding and never closes it. */
|
|
50
|
-
install(binding: KitsBinding) {
|
|
51
|
-
installed = binding;
|
|
52
|
-
},
|
|
53
|
-
uninstall() {
|
|
54
|
-
installed = undefined;
|
|
55
|
-
},
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* Object that implements `method`, looked up at call time: `binding`, else the
|
|
60
|
-
* installed host binding unless that is `binding` itself, else the default.
|
|
61
|
-
*/
|
|
62
|
-
const getMethodOwner = (
|
|
63
|
-
binding: KitsBinding | undefined,
|
|
64
|
-
method: BindingMethod,
|
|
65
|
-
): KitsBinding => {
|
|
66
|
-
if (typeof binding?.[method] === 'function') {
|
|
67
|
-
return binding;
|
|
68
|
-
}
|
|
69
|
-
const host = KitsHost.binding;
|
|
70
|
-
const isOtherHost = host !== binding && !resolvedBindings.has(host);
|
|
71
|
-
if (isOtherHost && typeof host[method] === 'function') {
|
|
72
|
-
return host;
|
|
73
|
-
}
|
|
74
|
-
return DefaultKitsBinding;
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* Starts a host request whose callback is dropped once the kit cancels it, so a
|
|
79
|
-
* late host answer never reaches an unmounted screen. `cancel` is idempotent.
|
|
80
|
-
*/
|
|
81
|
-
const startRequest = <T>(
|
|
82
|
-
start: (callback: (value: T) => void) => KitsRequest | undefined,
|
|
83
|
-
callback: (value: T) => void,
|
|
84
|
-
): KitsRequest => {
|
|
85
|
-
let isActive = true;
|
|
86
|
-
const request = start(value => {
|
|
87
|
-
if (isActive) {
|
|
88
|
-
callback(value);
|
|
89
|
-
}
|
|
90
|
-
});
|
|
91
|
-
return {
|
|
92
|
-
cancel: () => {
|
|
93
|
-
if (!isActive) {
|
|
94
|
-
return;
|
|
95
|
-
}
|
|
96
|
-
isActive = false;
|
|
97
|
-
request?.cancel();
|
|
98
|
-
},
|
|
99
|
-
};
|
|
100
|
-
};
|
|
101
|
-
|
|
102
|
-
/** Every method of `binding`, each falling back to `KitsHost` when missing. */
|
|
103
|
-
const resolveKitsBinding = (binding?: KitsBinding): ResolvedKitsBinding => {
|
|
104
|
-
/** Owner of `method` for this binding. */
|
|
105
|
-
const owner = (method: BindingMethod) => getMethodOwner(binding, method);
|
|
106
|
-
const resolved: ResolvedKitsBinding = {
|
|
107
|
-
dismiss: (target, data) => owner('dismiss').dismiss?.(target, data),
|
|
108
|
-
trackEvent: (eventName, attributes) => {
|
|
109
|
-
owner('trackEvent').trackEvent?.(eventName, attributes);
|
|
110
|
-
},
|
|
111
|
-
getLanguage: callback => {
|
|
112
|
-
return startRequest(
|
|
113
|
-
cb => owner('getLanguage').getLanguage?.(cb),
|
|
114
|
-
callback,
|
|
115
|
-
);
|
|
116
|
-
},
|
|
117
|
-
vibrateLight: () => owner('vibrateLight').vibrateLight?.(),
|
|
118
|
-
checkFavorite: (appCode, callback) => {
|
|
119
|
-
return startRequest(
|
|
120
|
-
cb => owner('checkFavorite').checkFavorite?.(appCode, cb),
|
|
121
|
-
callback,
|
|
122
|
-
);
|
|
123
|
-
},
|
|
124
|
-
toggleFavorite: (appCode, callback) => {
|
|
125
|
-
return startRequest(
|
|
126
|
-
cb => owner('toggleFavorite').toggleFavorite?.(appCode, cb),
|
|
127
|
-
callback,
|
|
128
|
-
);
|
|
129
|
-
},
|
|
130
|
-
showToolkit: (request, onAction) => {
|
|
131
|
-
return startRequest(
|
|
132
|
-
cb => owner('showToolkit').showToolkit?.(request, cb),
|
|
133
|
-
onAction,
|
|
134
|
-
);
|
|
135
|
-
},
|
|
136
|
-
showHelpCenter: request => {
|
|
137
|
-
return owner('showHelpCenter').showHelpCenter?.(request) ?? NO_REQUEST;
|
|
138
|
-
},
|
|
139
|
-
logError: message => owner('logError').logError?.(message),
|
|
140
|
-
observeConfig: (key, callback) => {
|
|
141
|
-
const host = owner('observeConfig');
|
|
142
|
-
return host.observeConfig?.(key, callback) ?? NO_SUBSCRIPTION;
|
|
143
|
-
},
|
|
144
|
-
observeFavorites: callback => {
|
|
145
|
-
const host = owner('observeFavorites');
|
|
146
|
-
return host.observeFavorites?.(callback) ?? NO_SUBSCRIPTION;
|
|
147
|
-
},
|
|
148
|
-
getCurrentScreen: callback => {
|
|
149
|
-
return startRequest(
|
|
150
|
-
cb => owner('getCurrentScreen').getCurrentScreen?.(cb),
|
|
151
|
-
callback,
|
|
152
|
-
);
|
|
153
|
-
},
|
|
154
|
-
setCurrentScreen: screen => {
|
|
155
|
-
owner('setCurrentScreen').setCurrentScreen?.(screen);
|
|
156
|
-
},
|
|
157
|
-
onFocusApp: listener => {
|
|
158
|
-
return owner('onFocusApp').onFocusApp?.(listener) ?? NO_SUBSCRIPTION;
|
|
159
|
-
},
|
|
160
|
-
startScreenTrace: (kind, screenName, context, callback) => {
|
|
161
|
-
const host = owner('startScreenTrace');
|
|
162
|
-
return startRequest(
|
|
163
|
-
cb => host.startScreenTrace?.(kind, screenName, context, cb),
|
|
164
|
-
callback,
|
|
165
|
-
);
|
|
166
|
-
},
|
|
167
|
-
stopTrace: (traceId, value) => {
|
|
168
|
-
owner('stopTrace').stopTrace?.(traceId, value);
|
|
169
|
-
},
|
|
170
|
-
showToastDebug: toast => owner('showToastDebug').showToastDebug?.(toast),
|
|
171
|
-
showNoticePopup: popup => {
|
|
172
|
-
owner('showNoticePopup').showNoticePopup?.(popup);
|
|
173
|
-
},
|
|
174
|
-
openWeb: request => owner('openWeb').openWeb?.(request),
|
|
175
|
-
startFeatureCode: (featureCode, params) => {
|
|
176
|
-
owner('startFeatureCode').startFeatureCode?.(featureCode, params);
|
|
177
|
-
},
|
|
178
|
-
};
|
|
179
|
-
resolvedBindings.add(resolved);
|
|
180
|
-
return resolved;
|
|
181
|
-
};
|
|
182
|
-
|
|
183
|
-
export { KitsHost, resolveKitsBinding };
|
|
@@ -1,155 +0,0 @@
|
|
|
1
|
-
import { createElement, type ReactElement } from 'react';
|
|
2
|
-
import { act, create } from 'react-test-renderer';
|
|
3
|
-
import { useKitsBinding } from '../hooks';
|
|
4
|
-
import { KitsBindingProvider } from '../KitsBindingProvider';
|
|
5
|
-
import { KitsHost, resolveKitsBinding } from '../KitsHost';
|
|
6
|
-
import type { KitsBinding } from '../types.binding';
|
|
7
|
-
|
|
8
|
-
type ContainerProps = {
|
|
9
|
-
name: string;
|
|
10
|
-
binding?: KitsBinding;
|
|
11
|
-
children?: ReactElement;
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
/** Host binding that records each call as `[method, ...args]`. */
|
|
15
|
-
const createRecordingBinding = (calls: unknown[][]): KitsBinding => {
|
|
16
|
-
return {
|
|
17
|
-
trackEvent: (eventName, attributes) => {
|
|
18
|
-
calls.push(['host.trackEvent', eventName, attributes]);
|
|
19
|
-
},
|
|
20
|
-
vibrateLight: () => {
|
|
21
|
-
calls.push(['host.vibrateLight']);
|
|
22
|
-
},
|
|
23
|
-
};
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
/** Binding whose `trackEvent` records `name`. */
|
|
27
|
-
const createNamedBinding = (name: string, calls: unknown[][]): KitsBinding => {
|
|
28
|
-
return {
|
|
29
|
-
trackEvent: eventName => {
|
|
30
|
-
calls.push([name, eventName]);
|
|
31
|
-
},
|
|
32
|
-
};
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
/** Resolves its binding as a kit container does and tracks `name` on render. */
|
|
36
|
-
const Container = ({ name, binding, children }: ContainerProps) => {
|
|
37
|
-
useKitsBinding(binding).trackEvent(name, {});
|
|
38
|
-
return children ?? null;
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
/** Renders `element` once, synchronously. */
|
|
42
|
-
const render = (element: ReactElement) => {
|
|
43
|
-
act(() => {
|
|
44
|
-
create(element);
|
|
45
|
-
});
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
describe('KitsHost', () => {
|
|
49
|
-
afterEach(() => {
|
|
50
|
-
KitsHost.uninstall();
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
it('does nothing and never throws before a host installs a binding', () => {
|
|
54
|
-
const binding = resolveKitsBinding();
|
|
55
|
-
expect(() => binding.dismiss('current')).not.toThrow();
|
|
56
|
-
expect(() => binding.observeConfig('key', () => {}).remove()).not.toThrow();
|
|
57
|
-
expect(() => binding.getLanguage(() => {}).cancel()).not.toThrow();
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
it('falls back per method to the installed binding at call time', () => {
|
|
61
|
-
const calls: unknown[][] = [];
|
|
62
|
-
const binding = resolveKitsBinding({
|
|
63
|
-
trackEvent: eventName => {
|
|
64
|
-
calls.push(['own.trackEvent', eventName]);
|
|
65
|
-
},
|
|
66
|
-
});
|
|
67
|
-
KitsHost.install(createRecordingBinding(calls));
|
|
68
|
-
|
|
69
|
-
binding.trackEvent('event', {});
|
|
70
|
-
binding.vibrateLight();
|
|
71
|
-
|
|
72
|
-
expect(calls).toEqual([['own.trackEvent', 'event'], ['host.vibrateLight']]);
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
it('uses DefaultKitsBinding when the binding is the installed one', () => {
|
|
76
|
-
const calls: unknown[][] = [];
|
|
77
|
-
const host = createRecordingBinding(calls);
|
|
78
|
-
KitsHost.install(host);
|
|
79
|
-
|
|
80
|
-
expect(() => resolveKitsBinding(host).dismiss('all')).not.toThrow();
|
|
81
|
-
expect(calls).toEqual([]);
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
it('never loops when a resolved binding is installed as the host', () => {
|
|
85
|
-
KitsHost.install(resolveKitsBinding());
|
|
86
|
-
|
|
87
|
-
expect(() => resolveKitsBinding().vibrateLight()).not.toThrow();
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
it('drops a callback that arrives after cancel and cancels once', () => {
|
|
91
|
-
let answer: ((language: string) => void) | undefined;
|
|
92
|
-
const onLanguage = jest.fn();
|
|
93
|
-
const hostCancel = jest.fn();
|
|
94
|
-
const request = resolveKitsBinding({
|
|
95
|
-
getLanguage: callback => {
|
|
96
|
-
answer = callback;
|
|
97
|
-
return { cancel: hostCancel };
|
|
98
|
-
},
|
|
99
|
-
}).getLanguage(onLanguage);
|
|
100
|
-
|
|
101
|
-
request.cancel();
|
|
102
|
-
request.cancel();
|
|
103
|
-
answer?.('en');
|
|
104
|
-
|
|
105
|
-
expect(onLanguage).not.toHaveBeenCalled();
|
|
106
|
-
expect(hostCancel).toHaveBeenCalledTimes(1);
|
|
107
|
-
});
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
describe('useKitsBinding', () => {
|
|
111
|
-
afterEach(() => {
|
|
112
|
-
KitsHost.uninstall();
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
it('never inherits the binding of an enclosing container', () => {
|
|
116
|
-
const calls: unknown[][] = [];
|
|
117
|
-
KitsHost.install(createNamedBinding('host', calls));
|
|
118
|
-
const inner = createElement(Container, { name: 'inner' });
|
|
119
|
-
const outer = createElement(Container, {
|
|
120
|
-
name: 'outer',
|
|
121
|
-
binding: createNamedBinding('A', calls),
|
|
122
|
-
children: inner,
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
render(outer);
|
|
126
|
-
|
|
127
|
-
expect(calls).toEqual([
|
|
128
|
-
['A', 'outer'],
|
|
129
|
-
['host', 'inner'],
|
|
130
|
-
]);
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
it('uses the host hand-off of KitsBindingProvider unless a prop is passed', () => {
|
|
134
|
-
const calls: unknown[][] = [];
|
|
135
|
-
KitsHost.install(createNamedBinding('host', calls));
|
|
136
|
-
const inner = createElement(Container, { name: 'inner' });
|
|
137
|
-
const outer = createElement(Container, {
|
|
138
|
-
name: 'outer',
|
|
139
|
-
binding: createNamedBinding('A', calls),
|
|
140
|
-
children: inner,
|
|
141
|
-
});
|
|
142
|
-
|
|
143
|
-
render(
|
|
144
|
-
createElement(KitsBindingProvider, {
|
|
145
|
-
binding: createNamedBinding('handOff', calls),
|
|
146
|
-
children: outer,
|
|
147
|
-
}),
|
|
148
|
-
);
|
|
149
|
-
|
|
150
|
-
expect(calls).toEqual([
|
|
151
|
-
['A', 'outer'],
|
|
152
|
-
['handOff', 'inner'],
|
|
153
|
-
]);
|
|
154
|
-
});
|
|
155
|
-
});
|
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
import type { ReactNode } from 'react';
|
|
2
|
-
import type { ToolGroup } from './types.header';
|
|
3
|
-
|
|
4
|
-
/** `current` closes only this mini app; `all` goes back to the host home. */
|
|
5
|
-
export type KitsDismissTarget = 'current' | 'all';
|
|
6
|
-
|
|
7
|
-
/** Pending host call. Idempotent; the kit drops late callbacks after cancel. */
|
|
8
|
-
export type KitsRequest = {
|
|
9
|
-
cancel: () => void;
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
/** Host listener the kit removes on unmount. */
|
|
13
|
-
export type KitsSubscription = {
|
|
14
|
-
remove: () => void;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
/** Mini app context as the kit holds it (`MiniAppContext`). */
|
|
18
|
-
export type KitsMiniAppContext = Record<string, unknown>;
|
|
19
|
-
|
|
20
|
-
/** Localized `{ vi, en }` text or a plain string, as in the mini app context. */
|
|
21
|
-
export type KitsLocalizedText = string | { vi?: string; en?: string };
|
|
22
|
-
|
|
23
|
-
/** Mini app shown in the help center sheet, mirroring native. */
|
|
24
|
-
export type KitsHelpCenterRequest = {
|
|
25
|
-
appId?: string;
|
|
26
|
-
code?: string;
|
|
27
|
-
name?: KitsLocalizedText;
|
|
28
|
-
icon?: string;
|
|
29
|
-
description?: KitsLocalizedText;
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
/** Tools of the header "more" sheet; `context` is the calling mini app. */
|
|
33
|
-
export type KitsToolkitRequest = {
|
|
34
|
-
tools: ToolGroup[];
|
|
35
|
-
useSystemTools: boolean;
|
|
36
|
-
context: KitsMiniAppContext;
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
/** Screen the host last recorded as shown, shared across mini apps. */
|
|
40
|
-
export type KitsCurrentScreen = {
|
|
41
|
-
screenName?: string;
|
|
42
|
-
startTime?: number;
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
/** Performance trace of a screen: until loaded, or until interactive. */
|
|
46
|
-
export type KitsScreenTraceKind = 'load' | 'interaction';
|
|
47
|
-
|
|
48
|
-
/** Developer toast with a tracking event, shown only in debug hosts. */
|
|
49
|
-
export type KitsDebugToast = {
|
|
50
|
-
appId?: string;
|
|
51
|
-
message: string;
|
|
52
|
-
type: string;
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
/** Host notice popup with a single dismiss action. */
|
|
56
|
-
export type KitsNoticePopup = {
|
|
57
|
-
title: string;
|
|
58
|
-
message: string;
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
/** Web page the host opens in its in-app browser. */
|
|
62
|
-
export type KitsOpenWebRequest = {
|
|
63
|
-
url: string;
|
|
64
|
-
title?: string;
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* Host services the kit calls, mirroring native `KitsBinding`. A method left out
|
|
69
|
-
* falls back to the one installed in `KitsHost`, then to `DefaultKitsBinding`.
|
|
70
|
-
* Callbacks fire only on success; containers borrow the binding and never close it.
|
|
71
|
-
*/
|
|
72
|
-
export interface KitsBinding {
|
|
73
|
-
dismiss?(target: KitsDismissTarget, data?: unknown): void;
|
|
74
|
-
trackEvent?(eventName: string, attributes: Record<string, unknown>): void;
|
|
75
|
-
getLanguage?(callback: (language: string) => void): KitsRequest;
|
|
76
|
-
vibrateLight?(): void;
|
|
77
|
-
checkFavorite?(
|
|
78
|
-
appCode: string | undefined,
|
|
79
|
-
callback: (isFavorite: boolean) => void,
|
|
80
|
-
): KitsRequest;
|
|
81
|
-
/** `callback` gets whether the app is a favorite afterwards. */
|
|
82
|
-
toggleFavorite?(
|
|
83
|
-
appCode: string | undefined,
|
|
84
|
-
callback: (isFavorite: boolean) => void,
|
|
85
|
-
): KitsRequest;
|
|
86
|
-
showToolkit?(
|
|
87
|
-
request: KitsToolkitRequest,
|
|
88
|
-
onAction: (actionKey: string) => void,
|
|
89
|
-
): KitsRequest;
|
|
90
|
-
/** The request stays open while the sheet may still emit events. */
|
|
91
|
-
showHelpCenter?(request: KitsHelpCenterRequest): KitsRequest;
|
|
92
|
-
logError?(message: string): void;
|
|
93
|
-
/** RN only: host config by key, e.g. `font_scale_config`. */
|
|
94
|
-
observeConfig?(
|
|
95
|
-
key: string,
|
|
96
|
-
callback: (value: unknown) => void,
|
|
97
|
-
): KitsSubscription;
|
|
98
|
-
/** RN only: app codes on the home favorites after each home sync. */
|
|
99
|
-
observeFavorites?(callback: (appCodes: string[]) => void): KitsSubscription;
|
|
100
|
-
/** RN only. */
|
|
101
|
-
getCurrentScreen?(
|
|
102
|
-
callback: (screen: KitsCurrentScreen | undefined) => void,
|
|
103
|
-
): KitsRequest;
|
|
104
|
-
/** RN only. */
|
|
105
|
-
setCurrentScreen?(screen: KitsCurrentScreen): void;
|
|
106
|
-
/** RN only: the mini app comes back to the foreground. */
|
|
107
|
-
onFocusApp?(listener: () => void): KitsSubscription;
|
|
108
|
-
/** RN only: `callback` gets the trace id to pass to `stopTrace`. */
|
|
109
|
-
startScreenTrace?(
|
|
110
|
-
kind: KitsScreenTraceKind,
|
|
111
|
-
screenName: string,
|
|
112
|
-
context: KitsMiniAppContext,
|
|
113
|
-
callback: (traceId: string) => void,
|
|
114
|
-
): KitsRequest;
|
|
115
|
-
/** RN only: `value` is the measured duration in seconds. */
|
|
116
|
-
stopTrace?(traceId: string, value: number): void;
|
|
117
|
-
/** RN only. */
|
|
118
|
-
showToastDebug?(toast: KitsDebugToast): void;
|
|
119
|
-
/** RN only. */
|
|
120
|
-
showNoticePopup?(popup: KitsNoticePopup): void;
|
|
121
|
-
/** RN only. */
|
|
122
|
-
openWeb?(request: KitsOpenWebRequest): void;
|
|
123
|
-
/** RN only. */
|
|
124
|
-
startFeatureCode?(featureCode: string, params: Record<string, unknown>): void;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
/** A binding with every method present, as containers resolve it. */
|
|
128
|
-
export type ResolvedKitsBinding = Required<KitsBinding>;
|
|
129
|
-
|
|
130
|
-
/** Props of `KitsBindingProvider`. */
|
|
131
|
-
export type KitsBindingProviderProps = {
|
|
132
|
-
binding: KitsBinding;
|
|
133
|
-
children: ReactNode;
|
|
134
|
-
};
|