@momo-kits/foundation 0.169.16-beta.6 → 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 +18 -22
- 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 +77 -83
- package/Application/hooks.ts +1 -16
- package/Application/index.ts +0 -4
- package/Application/types.ts +3 -14
- 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 -182
- package/Application/__tests__/KitsHost.test.ts +0 -76
- package/Application/types.binding.ts +0 -134
package/Input/Input.tsx
CHANGED
|
@@ -6,10 +6,10 @@ import React, {
|
|
|
6
6
|
useState,
|
|
7
7
|
} from 'react';
|
|
8
8
|
import {
|
|
9
|
+
TextInput,
|
|
9
10
|
TextInputFocusEvent,
|
|
10
11
|
TouchableOpacity,
|
|
11
12
|
View,
|
|
12
|
-
type TextInputInstance,
|
|
13
13
|
} from 'react-native';
|
|
14
14
|
import { useComponentId } from '../Application';
|
|
15
15
|
import { Icon } from '../Icon';
|
|
@@ -81,7 +81,7 @@ const Input = forwardRef(
|
|
|
81
81
|
const [isFocused, setIsFocused] = useState(false);
|
|
82
82
|
const [internalText, setInternalText] = useState(defaultValue || '');
|
|
83
83
|
const hasValue = value !== undefined ? !!value : !!internalText;
|
|
84
|
-
const inputRef = useRef<
|
|
84
|
+
const inputRef = useRef<TextInput | null>(null);
|
|
85
85
|
const componentName = 'Input';
|
|
86
86
|
|
|
87
87
|
const showBaseLineDebug = context?.features?.showBaseLineDebug ?? false;
|
package/Input/InputMoney.tsx
CHANGED
|
@@ -7,12 +7,7 @@ import React, {
|
|
|
7
7
|
useRef,
|
|
8
8
|
useState,
|
|
9
9
|
} from 'react';
|
|
10
|
-
import {
|
|
11
|
-
Platform,
|
|
12
|
-
TextInputFocusEvent,
|
|
13
|
-
View,
|
|
14
|
-
type TextInputInstance,
|
|
15
|
-
} from 'react-native';
|
|
10
|
+
import { Platform, TextInput, TextInputFocusEvent, View } from 'react-native';
|
|
16
11
|
import { useComponentId } from '../Application';
|
|
17
12
|
import { ComponentContext, MiniAppContext } from '../Context';
|
|
18
13
|
import { ErrorView } from './ErrorView';
|
|
@@ -61,7 +56,7 @@ const InputMoney = forwardRef(
|
|
|
61
56
|
const [displayValue, setDisplayValue] = useState('');
|
|
62
57
|
const [numericValue, setNumericValue] = useState('');
|
|
63
58
|
const [lastDisplayValue, setLastDisplayValue] = useState('');
|
|
64
|
-
const inputRef = useRef<
|
|
59
|
+
const inputRef = useRef<TextInput>(null);
|
|
65
60
|
const caretDigitsAfter = useRef<number | undefined>(undefined);
|
|
66
61
|
const lastRawText = useRef('');
|
|
67
62
|
const [caretSelection, setCaretSelection] = useState<{
|
package/Input/InputMoneyView.tsx
CHANGED
|
@@ -2,11 +2,11 @@ import React, { RefObject, useContext } from 'react';
|
|
|
2
2
|
import {
|
|
3
3
|
Pressable,
|
|
4
4
|
Text,
|
|
5
|
+
TextInput,
|
|
5
6
|
TextInputFocusEvent,
|
|
6
7
|
TextInputProps,
|
|
7
8
|
TouchableOpacity,
|
|
8
9
|
View,
|
|
9
|
-
type TextInputInstance,
|
|
10
10
|
} from 'react-native';
|
|
11
11
|
import { ApplicationContext } from '../Context';
|
|
12
12
|
import { Icon } from '../Icon';
|
|
@@ -43,7 +43,7 @@ type InputMoneyViewProps = Pick<
|
|
|
43
43
|
componentId: string;
|
|
44
44
|
displayValue: string;
|
|
45
45
|
caretSelection?: { start: number; end: number };
|
|
46
|
-
inputRef: RefObject<
|
|
46
|
+
inputRef: RefObject<TextInput | null>;
|
|
47
47
|
focusAtEnd: () => void;
|
|
48
48
|
onClearText: () => void;
|
|
49
49
|
onChangeText: (text: string) => void;
|
package/Input/InputOTP.tsx
CHANGED
|
@@ -9,10 +9,10 @@ import React, {
|
|
|
9
9
|
} from 'react';
|
|
10
10
|
import {
|
|
11
11
|
PixelRatio,
|
|
12
|
+
TextInput,
|
|
12
13
|
TextInputFocusEvent,
|
|
13
14
|
TouchableOpacity,
|
|
14
15
|
View,
|
|
15
|
-
type TextInputInstance,
|
|
16
16
|
} from 'react-native';
|
|
17
17
|
import Animated, {
|
|
18
18
|
cancelAnimation,
|
|
@@ -116,7 +116,7 @@ const InputOTP = forwardRef(
|
|
|
116
116
|
) => {
|
|
117
117
|
const [value, setValue] = useState('');
|
|
118
118
|
const [isFocused, setIsFocused] = useState(false);
|
|
119
|
-
const inputRef = useRef<
|
|
119
|
+
const inputRef = useRef<TextInput | null>(null);
|
|
120
120
|
const { theme } = useContext(ApplicationContext);
|
|
121
121
|
const context = useContext<any>(MiniAppContext);
|
|
122
122
|
|
|
@@ -7,10 +7,10 @@ import React, {
|
|
|
7
7
|
} from 'react';
|
|
8
8
|
import {
|
|
9
9
|
StyleSheet,
|
|
10
|
+
TextInput,
|
|
10
11
|
TextInputFocusEvent,
|
|
11
12
|
TouchableOpacity,
|
|
12
13
|
View,
|
|
13
|
-
type TextInputInstance,
|
|
14
14
|
} from 'react-native';
|
|
15
15
|
import { useComponentId } from '../Application';
|
|
16
16
|
import {
|
|
@@ -76,7 +76,7 @@ const InputPhoneNumber = forwardRef(
|
|
|
76
76
|
const [isFocused, setIsFocused] = useState(false);
|
|
77
77
|
const [internalText, setInternalText] = useState(defaultValue || '');
|
|
78
78
|
const hasValue = value !== undefined ? !!value : !!internalText;
|
|
79
|
-
const inputRef = useRef<
|
|
79
|
+
const inputRef = useRef<TextInput | null>(null);
|
|
80
80
|
const componentName = 'InputPhoneNumber';
|
|
81
81
|
|
|
82
82
|
const showBaseLineDebug = context?.features?.showBaseLineDebug ?? false;
|
package/Input/InputSearch.tsx
CHANGED
|
@@ -7,10 +7,10 @@ import React, {
|
|
|
7
7
|
useState,
|
|
8
8
|
} from 'react';
|
|
9
9
|
import {
|
|
10
|
+
TextInput,
|
|
10
11
|
TextInputFocusEvent,
|
|
11
12
|
TouchableOpacity,
|
|
12
13
|
View,
|
|
13
|
-
type TextInputInstance,
|
|
14
14
|
} from 'react-native';
|
|
15
15
|
import { useComponentId } from '../Application';
|
|
16
16
|
import { HeaderBarMetrics } from '../Application/headerLayout';
|
|
@@ -76,7 +76,7 @@ const InputSearch: ForwardRefRenderFunction<InputRef, InputSearchProps> = (
|
|
|
76
76
|
const [internalText, setInternalText] = useState(defaultValue || '');
|
|
77
77
|
const currentValue = value !== undefined ? value : internalText;
|
|
78
78
|
const hasValue = !!currentValue;
|
|
79
|
-
const inputRef = useRef<
|
|
79
|
+
const inputRef = useRef<TextInput | null>(null);
|
|
80
80
|
|
|
81
81
|
const componentName = 'InputSearch';
|
|
82
82
|
|
package/Input/InputTextArea.tsx
CHANGED
|
@@ -7,10 +7,10 @@ import React, {
|
|
|
7
7
|
useState,
|
|
8
8
|
} from 'react';
|
|
9
9
|
import {
|
|
10
|
+
TextInput,
|
|
10
11
|
TextInputFocusEvent,
|
|
11
12
|
TouchableOpacity,
|
|
12
13
|
View,
|
|
13
|
-
type TextInputInstance,
|
|
14
14
|
} from 'react-native';
|
|
15
15
|
import { setAutomationID, useComponentId } from '../Application';
|
|
16
16
|
import { ApplicationContext, MiniAppContext } from '../Context';
|
|
@@ -70,7 +70,7 @@ const InputTextArea = forwardRef(
|
|
|
70
70
|
const inputFontFamily = exportFontFamily('regular');
|
|
71
71
|
const [isFocused, setIsFocused] = useState(false);
|
|
72
72
|
const [inputValue, setInputValue] = useState(defaultValue ?? '');
|
|
73
|
-
const inputRef = useRef<
|
|
73
|
+
const inputRef = useRef<TextInput | null>(null);
|
|
74
74
|
|
|
75
75
|
useEffect(() => {
|
|
76
76
|
setInputValue(value ?? '');
|
|
@@ -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
|
-
/** Binding of the nearest enclosing container or provider, if any. */
|
|
5
|
-
const KitsBindingContext = createContext<KitsBinding | undefined>(undefined);
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Gives every container in its subtree `binding` unless one passes its own, so a
|
|
9
|
-
* host can wrap a mini app without the mini app passing anything.
|
|
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,182 +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
|
-
const NO_OP_BINDING: ResolvedKitsBinding = {
|
|
14
|
-
dismiss: () => {},
|
|
15
|
-
trackEvent: () => {},
|
|
16
|
-
getLanguage: () => NO_REQUEST,
|
|
17
|
-
vibrateLight: () => {},
|
|
18
|
-
checkFavorite: () => NO_REQUEST,
|
|
19
|
-
toggleFavorite: () => NO_REQUEST,
|
|
20
|
-
showToolkit: () => NO_REQUEST,
|
|
21
|
-
showHelpCenter: () => NO_REQUEST,
|
|
22
|
-
logError: () => {},
|
|
23
|
-
observeConfig: () => NO_SUBSCRIPTION,
|
|
24
|
-
observeFavorites: () => NO_SUBSCRIPTION,
|
|
25
|
-
getCurrentScreen: () => NO_REQUEST,
|
|
26
|
-
setCurrentScreen: () => {},
|
|
27
|
-
onFocusApp: () => NO_SUBSCRIPTION,
|
|
28
|
-
startScreenTrace: () => NO_REQUEST,
|
|
29
|
-
stopTrace: () => {},
|
|
30
|
-
showToastDebug: () => {},
|
|
31
|
-
showNoticePopup: () => {},
|
|
32
|
-
openWeb: () => {},
|
|
33
|
-
startFeatureCode: () => {},
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
// Resolved bindings delegate to the host, so one installed as the host would loop.
|
|
37
|
-
const resolvedBindings = new WeakSet<KitsBinding>();
|
|
38
|
-
let installed: KitsBinding | undefined;
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* The host app installs its binding here once; containers use it unless a caller
|
|
42
|
-
* passes or provides another. Until then `binding` does nothing, never throws.
|
|
43
|
-
*/
|
|
44
|
-
const KitsHost = {
|
|
45
|
-
get binding(): KitsBinding {
|
|
46
|
-
return installed ?? NO_OP_BINDING;
|
|
47
|
-
},
|
|
48
|
-
/** The last install wins. The kit borrows the binding and never closes it. */
|
|
49
|
-
install(binding: KitsBinding) {
|
|
50
|
-
installed = binding;
|
|
51
|
-
},
|
|
52
|
-
uninstall() {
|
|
53
|
-
installed = undefined;
|
|
54
|
-
},
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* Object that implements `method`, looked up at call time: `binding`, else the
|
|
59
|
-
* installed host binding unless that is `binding` itself, else the no-op.
|
|
60
|
-
*/
|
|
61
|
-
const getMethodOwner = (
|
|
62
|
-
binding: KitsBinding | undefined,
|
|
63
|
-
method: BindingMethod,
|
|
64
|
-
): KitsBinding => {
|
|
65
|
-
if (typeof binding?.[method] === 'function') {
|
|
66
|
-
return binding;
|
|
67
|
-
}
|
|
68
|
-
const host = KitsHost.binding;
|
|
69
|
-
const isOtherHost = host !== binding && !resolvedBindings.has(host);
|
|
70
|
-
if (isOtherHost && typeof host[method] === 'function') {
|
|
71
|
-
return host;
|
|
72
|
-
}
|
|
73
|
-
return NO_OP_BINDING;
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* Starts a host request whose callback is dropped once the kit cancels it, so a
|
|
78
|
-
* late host answer never reaches an unmounted screen. `cancel` is idempotent.
|
|
79
|
-
*/
|
|
80
|
-
const startRequest = <T>(
|
|
81
|
-
start: (callback: (value: T) => void) => KitsRequest | undefined,
|
|
82
|
-
callback: (value: T) => void,
|
|
83
|
-
): KitsRequest => {
|
|
84
|
-
let isActive = true;
|
|
85
|
-
const request = start(value => {
|
|
86
|
-
if (isActive) {
|
|
87
|
-
callback(value);
|
|
88
|
-
}
|
|
89
|
-
});
|
|
90
|
-
return {
|
|
91
|
-
cancel: () => {
|
|
92
|
-
if (!isActive) {
|
|
93
|
-
return;
|
|
94
|
-
}
|
|
95
|
-
isActive = false;
|
|
96
|
-
request?.cancel();
|
|
97
|
-
},
|
|
98
|
-
};
|
|
99
|
-
};
|
|
100
|
-
|
|
101
|
-
/** Every method of `binding`, each falling back to `KitsHost` when missing. */
|
|
102
|
-
const resolveKitsBinding = (binding?: KitsBinding): ResolvedKitsBinding => {
|
|
103
|
-
/** Owner of `method` for this binding. */
|
|
104
|
-
const owner = (method: BindingMethod) => getMethodOwner(binding, method);
|
|
105
|
-
const resolved: ResolvedKitsBinding = {
|
|
106
|
-
dismiss: (target, data) => owner('dismiss').dismiss?.(target, data),
|
|
107
|
-
trackEvent: (eventName, attributes) => {
|
|
108
|
-
owner('trackEvent').trackEvent?.(eventName, attributes);
|
|
109
|
-
},
|
|
110
|
-
getLanguage: callback => {
|
|
111
|
-
return startRequest(
|
|
112
|
-
cb => owner('getLanguage').getLanguage?.(cb),
|
|
113
|
-
callback,
|
|
114
|
-
);
|
|
115
|
-
},
|
|
116
|
-
vibrateLight: () => owner('vibrateLight').vibrateLight?.(),
|
|
117
|
-
checkFavorite: (appCode, callback) => {
|
|
118
|
-
return startRequest(
|
|
119
|
-
cb => owner('checkFavorite').checkFavorite?.(appCode, cb),
|
|
120
|
-
callback,
|
|
121
|
-
);
|
|
122
|
-
},
|
|
123
|
-
toggleFavorite: (appCode, callback) => {
|
|
124
|
-
return startRequest(
|
|
125
|
-
cb => owner('toggleFavorite').toggleFavorite?.(appCode, cb),
|
|
126
|
-
callback,
|
|
127
|
-
);
|
|
128
|
-
},
|
|
129
|
-
showToolkit: (request, onAction) => {
|
|
130
|
-
return startRequest(
|
|
131
|
-
cb => owner('showToolkit').showToolkit?.(request, cb),
|
|
132
|
-
onAction,
|
|
133
|
-
);
|
|
134
|
-
},
|
|
135
|
-
showHelpCenter: request => {
|
|
136
|
-
return owner('showHelpCenter').showHelpCenter?.(request) ?? NO_REQUEST;
|
|
137
|
-
},
|
|
138
|
-
logError: message => owner('logError').logError?.(message),
|
|
139
|
-
observeConfig: (key, callback) => {
|
|
140
|
-
const host = owner('observeConfig');
|
|
141
|
-
return host.observeConfig?.(key, callback) ?? NO_SUBSCRIPTION;
|
|
142
|
-
},
|
|
143
|
-
observeFavorites: callback => {
|
|
144
|
-
const host = owner('observeFavorites');
|
|
145
|
-
return host.observeFavorites?.(callback) ?? NO_SUBSCRIPTION;
|
|
146
|
-
},
|
|
147
|
-
getCurrentScreen: callback => {
|
|
148
|
-
return startRequest(
|
|
149
|
-
cb => owner('getCurrentScreen').getCurrentScreen?.(cb),
|
|
150
|
-
callback,
|
|
151
|
-
);
|
|
152
|
-
},
|
|
153
|
-
setCurrentScreen: screen => {
|
|
154
|
-
owner('setCurrentScreen').setCurrentScreen?.(screen);
|
|
155
|
-
},
|
|
156
|
-
onFocusApp: listener => {
|
|
157
|
-
return owner('onFocusApp').onFocusApp?.(listener) ?? NO_SUBSCRIPTION;
|
|
158
|
-
},
|
|
159
|
-
startScreenTrace: (kind, screenName, context, callback) => {
|
|
160
|
-
const host = owner('startScreenTrace');
|
|
161
|
-
return startRequest(
|
|
162
|
-
cb => host.startScreenTrace?.(kind, screenName, context, cb),
|
|
163
|
-
callback,
|
|
164
|
-
);
|
|
165
|
-
},
|
|
166
|
-
stopTrace: (traceId, value) => {
|
|
167
|
-
owner('stopTrace').stopTrace?.(traceId, value);
|
|
168
|
-
},
|
|
169
|
-
showToastDebug: toast => owner('showToastDebug').showToastDebug?.(toast),
|
|
170
|
-
showNoticePopup: popup => {
|
|
171
|
-
owner('showNoticePopup').showNoticePopup?.(popup);
|
|
172
|
-
},
|
|
173
|
-
openWeb: request => owner('openWeb').openWeb?.(request),
|
|
174
|
-
startFeatureCode: (featureCode, params) => {
|
|
175
|
-
owner('startFeatureCode').startFeatureCode?.(featureCode, params);
|
|
176
|
-
},
|
|
177
|
-
};
|
|
178
|
-
resolvedBindings.add(resolved);
|
|
179
|
-
return resolved;
|
|
180
|
-
};
|
|
181
|
-
|
|
182
|
-
export { KitsHost, resolveKitsBinding };
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import { KitsHost, resolveKitsBinding } from '../KitsHost';
|
|
2
|
-
import type { KitsBinding } from '../types.binding';
|
|
3
|
-
|
|
4
|
-
/** Host binding that records each call as `[method, ...args]`. */
|
|
5
|
-
const createRecordingBinding = (calls: unknown[][]): KitsBinding => {
|
|
6
|
-
return {
|
|
7
|
-
trackEvent: (eventName, attributes) => {
|
|
8
|
-
calls.push(['host.trackEvent', eventName, attributes]);
|
|
9
|
-
},
|
|
10
|
-
vibrateLight: () => {
|
|
11
|
-
calls.push(['host.vibrateLight']);
|
|
12
|
-
},
|
|
13
|
-
};
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
describe('KitsHost', () => {
|
|
17
|
-
afterEach(() => {
|
|
18
|
-
KitsHost.uninstall();
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
it('does nothing and never throws before a host installs a binding', () => {
|
|
22
|
-
const binding = resolveKitsBinding();
|
|
23
|
-
expect(() => binding.dismiss('current')).not.toThrow();
|
|
24
|
-
expect(() => binding.observeConfig('key', () => {}).remove()).not.toThrow();
|
|
25
|
-
expect(() => binding.getLanguage(() => {}).cancel()).not.toThrow();
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
it('falls back per method to the installed binding at call time', () => {
|
|
29
|
-
const calls: unknown[][] = [];
|
|
30
|
-
const binding = resolveKitsBinding({
|
|
31
|
-
trackEvent: eventName => {
|
|
32
|
-
calls.push(['own.trackEvent', eventName]);
|
|
33
|
-
},
|
|
34
|
-
});
|
|
35
|
-
KitsHost.install(createRecordingBinding(calls));
|
|
36
|
-
|
|
37
|
-
binding.trackEvent('event', {});
|
|
38
|
-
binding.vibrateLight();
|
|
39
|
-
|
|
40
|
-
expect(calls).toEqual([['own.trackEvent', 'event'], ['host.vibrateLight']]);
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
it('uses the no-op when the binding is the installed one', () => {
|
|
44
|
-
const calls: unknown[][] = [];
|
|
45
|
-
const host = createRecordingBinding(calls);
|
|
46
|
-
KitsHost.install(host);
|
|
47
|
-
|
|
48
|
-
expect(() => resolveKitsBinding(host).dismiss('all')).not.toThrow();
|
|
49
|
-
expect(calls).toEqual([]);
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
it('never loops when a resolved binding is installed as the host', () => {
|
|
53
|
-
KitsHost.install(resolveKitsBinding());
|
|
54
|
-
|
|
55
|
-
expect(() => resolveKitsBinding().vibrateLight()).not.toThrow();
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
it('drops a callback that arrives after cancel and cancels once', () => {
|
|
59
|
-
let answer: ((language: string) => void) | undefined;
|
|
60
|
-
const onLanguage = jest.fn();
|
|
61
|
-
const hostCancel = jest.fn();
|
|
62
|
-
const request = resolveKitsBinding({
|
|
63
|
-
getLanguage: callback => {
|
|
64
|
-
answer = callback;
|
|
65
|
-
return { cancel: hostCancel };
|
|
66
|
-
},
|
|
67
|
-
}).getLanguage(onLanguage);
|
|
68
|
-
|
|
69
|
-
request.cancel();
|
|
70
|
-
request.cancel();
|
|
71
|
-
answer?.('en');
|
|
72
|
-
|
|
73
|
-
expect(onLanguage).not.toHaveBeenCalled();
|
|
74
|
-
expect(hostCancel).toHaveBeenCalledTimes(1);
|
|
75
|
-
});
|
|
76
|
-
});
|