@momo-kits/foundation 0.169.16-beta.4 → 0.169.16-beta.6
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 +16 -22
- package/Application/BottomTab/Legacy/hooks.ts +1 -1
- package/Application/BottomTab/Legacy/index.tsx +5 -1
- package/Application/BottomTab/TabBarIcon.tsx +1 -1
- package/Application/BottomTab/TabScreen.tsx +12 -22
- package/Application/BottomTab/index.tsx +1 -1
- package/Application/Components/HeaderLeft.tsx +11 -7
- package/Application/Components/HeaderRight.styles.ts +5 -1
- package/Application/Components/HeaderRight.tsx +7 -21
- package/Application/Components/SearchHeader.tsx +2 -2
- package/Application/Components/SwipeBackHaptic.tsx +1 -1
- package/Application/Components/useHeaderRightWidth.ts +2 -2
- package/Application/Components/useToolkitActions.tsx +34 -64
- package/Application/KitsBindingProvider.tsx +22 -0
- package/Application/KitsHost.ts +182 -0
- package/Application/ModalScreen.tsx +4 -4
- package/Application/NavigationContainer.tsx +22 -18
- package/Application/Navigator.ts +7 -2
- package/Application/StackScreen.tracking.ts +22 -12
- package/Application/StackScreen.tsx +26 -34
- package/Application/TooltipPortal.tsx +3 -3
- package/Application/WidgetContainer.tsx +83 -77
- package/Application/__tests__/KitsHost.test.ts +76 -0
- package/Application/headerLayout.ts +6 -13
- package/Application/hooks.ts +16 -1
- package/Application/index.ts +4 -0
- package/Application/navigationOptions.tsx +5 -12
- package/Application/types.binding.ts +134 -0
- package/Application/types.ts +14 -3
- 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 +1 -2
- package/Image/index.tsx +62 -7
- package/Image/styles.ts +2 -0
- package/Image/types.ts +9 -1
- package/Input/Input.tsx +2 -2
- package/Input/InputMoney.tsx +7 -2
- 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 +2 -1
- package/Input/TextTyping.tsx +7 -2
- package/Layout/screenHeader.tsx +15 -17
- package/Pagination/types.ts +6 -2
- package/package.json +28 -26
|
@@ -15,6 +15,8 @@ import { isWhiteListDesignSystem } from './utils';
|
|
|
15
15
|
import { createStackNavigator } from '@react-navigation/stack';
|
|
16
16
|
import ModalScreen from './ModalScreen';
|
|
17
17
|
import { StyleSheet, View } from 'react-native';
|
|
18
|
+
import { useKitsBinding } from './hooks';
|
|
19
|
+
import { KitsBindingContext } from './KitsBindingProvider';
|
|
18
20
|
|
|
19
21
|
const Stack = createStackNavigator();
|
|
20
22
|
|
|
@@ -34,12 +36,13 @@ const WidgetContent: React.FC = ({ route }: any) => {
|
|
|
34
36
|
|
|
35
37
|
/**
|
|
36
38
|
* Root of an embedded widget: its own navigator with the widget screen and the
|
|
37
|
-
* `Modal` route, sized to the widget's content height.
|
|
39
|
+
* `Modal` route, sized to the widget's content height. Without a `binding` it
|
|
40
|
+
* uses the enclosing container's.
|
|
38
41
|
*/
|
|
39
42
|
const WidgetContainer: React.FC<WidgetContainerProps> = ({
|
|
40
43
|
widget,
|
|
41
44
|
theme = defaultTheme,
|
|
42
|
-
|
|
45
|
+
binding,
|
|
43
46
|
localize = new Localize({ vi: {}, en: {} }),
|
|
44
47
|
}) => {
|
|
45
48
|
const [height, setHeight] = useState<any>(undefined);
|
|
@@ -48,13 +51,14 @@ const WidgetContainer: React.FC<WidgetContainerProps> = ({
|
|
|
48
51
|
const isReady = useRef(false);
|
|
49
52
|
const navigator = useRef(new Navigator(navigationRef, isReady, true));
|
|
50
53
|
const [currentContext, setCurrentContext] = useState({});
|
|
54
|
+
const { source, resolved } = useKitsBinding(binding);
|
|
51
55
|
|
|
52
56
|
useEffect(() => {
|
|
53
|
-
const sub =
|
|
57
|
+
const sub = resolved.observeConfig('font_scale_config', data => {
|
|
54
58
|
setCurrentContext((prev: any) => ({ ...prev, fontScale: data }));
|
|
55
59
|
});
|
|
56
|
-
return () => sub
|
|
57
|
-
}, [
|
|
60
|
+
return () => sub.remove();
|
|
61
|
+
}, [resolved]);
|
|
58
62
|
|
|
59
63
|
let headerBackground = context?.designConfig?.headerBar;
|
|
60
64
|
let headerGradient = theme.colors?.gradient;
|
|
@@ -66,7 +70,7 @@ const WidgetContainer: React.FC<WidgetContainerProps> = ({
|
|
|
66
70
|
headerGradient = context?.designConfig?.headerGradient;
|
|
67
71
|
}
|
|
68
72
|
|
|
69
|
-
navigator.current.
|
|
73
|
+
navigator.current.binding = resolved;
|
|
70
74
|
|
|
71
75
|
/** Text for a localization key, or the current-language side of `{ vi, en }`. */
|
|
72
76
|
const translate = (data?: string | { vi: string; en: string }) => {
|
|
@@ -93,84 +97,86 @@ const WidgetContainer: React.FC<WidgetContainerProps> = ({
|
|
|
93
97
|
<View style={[styles.container, { height: height ?? '100%' }]}>
|
|
94
98
|
<SafeAreaProvider>
|
|
95
99
|
<MiniAppContext.Provider value={mergedContext}>
|
|
96
|
-
<
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
...theme.colors,
|
|
104
|
-
gradient: headerGradient,
|
|
105
|
-
},
|
|
106
|
-
assets: {
|
|
107
|
-
...theme.assets,
|
|
108
|
-
headerBackground,
|
|
109
|
-
},
|
|
110
|
-
},
|
|
111
|
-
translate,
|
|
112
|
-
}}
|
|
113
|
-
>
|
|
114
|
-
<NavigationIndependentTree>
|
|
115
|
-
<ReactNavigationContainer
|
|
116
|
-
theme={{
|
|
117
|
-
dark: false,
|
|
100
|
+
<KitsBindingContext.Provider value={source}>
|
|
101
|
+
<ApplicationContext.Provider
|
|
102
|
+
value={{
|
|
103
|
+
navigator: navigator.current,
|
|
104
|
+
theme: {
|
|
105
|
+
...theme,
|
|
106
|
+
font: fontFamily,
|
|
118
107
|
colors: {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
card: theme.colors.background.surface,
|
|
122
|
-
text: theme.colors.text.default,
|
|
123
|
-
border: theme.colors.border.default,
|
|
124
|
-
notification: theme.colors.error.primary,
|
|
108
|
+
...theme.colors,
|
|
109
|
+
gradient: headerGradient,
|
|
125
110
|
},
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
111
|
+
assets: {
|
|
112
|
+
...theme.assets,
|
|
113
|
+
headerBackground,
|
|
114
|
+
},
|
|
115
|
+
},
|
|
116
|
+
translate,
|
|
117
|
+
}}
|
|
118
|
+
>
|
|
119
|
+
<NavigationIndependentTree>
|
|
120
|
+
<ReactNavigationContainer
|
|
121
|
+
theme={{
|
|
122
|
+
dark: false,
|
|
123
|
+
colors: {
|
|
124
|
+
primary: theme.colors.primary,
|
|
125
|
+
background: theme.colors.background.default,
|
|
126
|
+
card: theme.colors.background.surface,
|
|
127
|
+
text: theme.colors.text.default,
|
|
128
|
+
border: theme.colors.border.default,
|
|
129
|
+
notification: theme.colors.error.primary,
|
|
138
130
|
},
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
131
|
+
fonts: {
|
|
132
|
+
regular: {
|
|
133
|
+
fontFamily: navigationFontFamily,
|
|
134
|
+
fontWeight: '400',
|
|
135
|
+
},
|
|
136
|
+
medium: {
|
|
137
|
+
fontFamily: navigationFontFamily,
|
|
138
|
+
fontWeight: '400',
|
|
139
|
+
},
|
|
140
|
+
bold: {
|
|
141
|
+
fontFamily: navigationFontFamily,
|
|
142
|
+
fontWeight: '400',
|
|
143
|
+
},
|
|
144
|
+
heavy: {
|
|
145
|
+
fontFamily: navigationFontFamily,
|
|
146
|
+
fontWeight: '400',
|
|
147
|
+
},
|
|
142
148
|
},
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
isReady.current = true;
|
|
148
|
-
}}
|
|
149
|
-
>
|
|
150
|
-
<Stack.Navigator
|
|
151
|
-
initialRouteName="Stack"
|
|
152
|
-
screenOptions={{
|
|
153
|
-
headerMode: 'screen',
|
|
149
|
+
}}
|
|
150
|
+
ref={navigationRef}
|
|
151
|
+
onReady={() => {
|
|
152
|
+
isReady.current = true;
|
|
154
153
|
}}
|
|
155
154
|
>
|
|
156
|
-
<Stack.
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
options={{
|
|
161
|
-
headerShown: false,
|
|
155
|
+
<Stack.Navigator
|
|
156
|
+
initialRouteName="Stack"
|
|
157
|
+
screenOptions={{
|
|
158
|
+
headerMode: 'screen',
|
|
162
159
|
}}
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
160
|
+
>
|
|
161
|
+
<Stack.Screen
|
|
162
|
+
name="Stack"
|
|
163
|
+
component={WidgetContent}
|
|
164
|
+
initialParams={{ screen: widget, setHeight }}
|
|
165
|
+
options={{
|
|
166
|
+
headerShown: false,
|
|
167
|
+
}}
|
|
168
|
+
/>
|
|
169
|
+
<Stack.Screen
|
|
170
|
+
name="Modal"
|
|
171
|
+
component={ModalScreen}
|
|
172
|
+
options={getModalOptions()}
|
|
173
|
+
initialParams={{ screen: widget }}
|
|
174
|
+
/>
|
|
175
|
+
</Stack.Navigator>
|
|
176
|
+
</ReactNavigationContainer>
|
|
177
|
+
</NavigationIndependentTree>
|
|
178
|
+
</ApplicationContext.Provider>
|
|
179
|
+
</KitsBindingContext.Provider>
|
|
174
180
|
</MiniAppContext.Provider>
|
|
175
181
|
</SafeAreaProvider>
|
|
176
182
|
</View>
|
|
@@ -0,0 +1,76 @@
|
|
|
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
|
+
});
|
|
@@ -98,14 +98,6 @@ const getHeaderLayout = ({
|
|
|
98
98
|
};
|
|
99
99
|
};
|
|
100
100
|
|
|
101
|
-
/**
|
|
102
|
-
* Inset from the React Navigation header row that puts an item `sidePadding` from
|
|
103
|
-
* the window edge: large iOS windows already inset that row by `getHeaderMargin`.
|
|
104
|
-
*/
|
|
105
|
-
const getHeaderRowInset = (width: number) => {
|
|
106
|
-
return HeaderBarMetrics.sidePadding - getHeaderMargin(width);
|
|
107
|
-
};
|
|
108
|
-
|
|
109
101
|
/**
|
|
110
102
|
* Widest a title can be between back and the right cluster of the header row.
|
|
111
103
|
*/
|
|
@@ -143,23 +135,25 @@ const useHeaderFrameOptions = (
|
|
|
143
135
|
contentLayout?: HeaderContentLayout,
|
|
144
136
|
): StackNavigationOptions | undefined => {
|
|
145
137
|
const layout = useHeaderLayout(contentLayout);
|
|
138
|
+
const { width } = useWindowDimensions();
|
|
146
139
|
const isDuo = isIPhoneDuo();
|
|
147
140
|
return useMemo(() => {
|
|
148
141
|
if (!IS_STRETCH_FRAME_ENABLED || contentLayout !== 'stretch' || isDuo) {
|
|
149
142
|
return undefined;
|
|
150
143
|
}
|
|
151
|
-
//
|
|
144
|
+
// the header content row already sits this far in on large iOS windows
|
|
152
145
|
const shift = layout.frameInset - layout.sidePadding;
|
|
146
|
+
const containerShift = Math.max(0, shift - getHeaderMargin(width));
|
|
153
147
|
return {
|
|
154
|
-
headerLeftContainerStyle: { paddingLeft:
|
|
155
|
-
headerRightContainerStyle: { paddingRight:
|
|
148
|
+
headerLeftContainerStyle: { paddingLeft: containerShift },
|
|
149
|
+
headerRightContainerStyle: { paddingRight: containerShift },
|
|
156
150
|
headerTitleContainerStyle: {
|
|
157
151
|
...TITLE_CONTAINER_RESET,
|
|
158
152
|
left: layout.titleGap,
|
|
159
153
|
maxWidth: getTitleBudget(layout),
|
|
160
154
|
},
|
|
161
155
|
};
|
|
162
|
-
}, [contentLayout, isDuo, layout]);
|
|
156
|
+
}, [contentLayout, isDuo, layout, width]);
|
|
163
157
|
};
|
|
164
158
|
|
|
165
159
|
export type { HeaderContentLayout, HeaderLayout };
|
|
@@ -169,7 +163,6 @@ export {
|
|
|
169
163
|
HEADER_FRAME_MAX_WIDTH,
|
|
170
164
|
TITLE_CONTAINER_RESET,
|
|
171
165
|
getHeaderLayout,
|
|
172
|
-
getHeaderRowInset,
|
|
173
166
|
getTitleBudget,
|
|
174
167
|
useHeaderLayout,
|
|
175
168
|
useHeaderFrameOptions,
|
package/Application/hooks.ts
CHANGED
|
@@ -13,6 +13,9 @@ import {
|
|
|
13
13
|
isRNAnimatedValue,
|
|
14
14
|
isSharedValue,
|
|
15
15
|
} from './utils';
|
|
16
|
+
import { KitsBindingContext } from './KitsBindingProvider';
|
|
17
|
+
import { resolveKitsBinding } from './KitsHost';
|
|
18
|
+
import type { KitsBinding } from './types.binding';
|
|
16
19
|
|
|
17
20
|
const FOREGROUND_FLAG_DURATION = 100;
|
|
18
21
|
|
|
@@ -54,7 +57,7 @@ const useAppState = () => {
|
|
|
54
57
|
|
|
55
58
|
useEffect(() => {
|
|
56
59
|
const subscription = AppState.addEventListener('change', nextAppState => {
|
|
57
|
-
const wasInBackground = /inactive|background/.test(appState.current);
|
|
60
|
+
const wasInBackground = /inactive|background/.test(appState.current ?? '');
|
|
58
61
|
const isReturning = wasInBackground && nextAppState === 'active';
|
|
59
62
|
isBackgroundToForeground.current = isReturning;
|
|
60
63
|
appState.current = nextAppState;
|
|
@@ -129,8 +132,20 @@ const useNormalizedSharedValue = (
|
|
|
129
132
|
return fallback;
|
|
130
133
|
};
|
|
131
134
|
|
|
135
|
+
/**
|
|
136
|
+
* Binding of a container: its `binding` prop, else the nearest enclosing one,
|
|
137
|
+
* else `KitsHost`. `source` is what the container passes on to nested ones.
|
|
138
|
+
*/
|
|
139
|
+
const useKitsBinding = (binding?: KitsBinding) => {
|
|
140
|
+
const inherited = useContext(KitsBindingContext);
|
|
141
|
+
const source = binding ?? inherited;
|
|
142
|
+
const resolved = useMemo(() => resolveKitsBinding(source), [source]);
|
|
143
|
+
return { source, resolved };
|
|
144
|
+
};
|
|
145
|
+
|
|
132
146
|
export {
|
|
133
147
|
useComponentId,
|
|
148
|
+
useKitsBinding,
|
|
134
149
|
useAppState,
|
|
135
150
|
useNativeCanGoBack,
|
|
136
151
|
useNormalizedSharedValue,
|
package/Application/index.ts
CHANGED
|
@@ -20,6 +20,8 @@ import Navigation from './Navigation';
|
|
|
20
20
|
import Navigator from './Navigator';
|
|
21
21
|
import ScaleSizeProvider from './ScaleSizeProvider';
|
|
22
22
|
import { useTooltipPortal } from './TooltipPortal';
|
|
23
|
+
import { KitsHost } from './KitsHost';
|
|
24
|
+
import { KitsBindingProvider } from './KitsBindingProvider';
|
|
23
25
|
import {
|
|
24
26
|
getModalLayout,
|
|
25
27
|
useModalLayout,
|
|
@@ -51,6 +53,8 @@ export {
|
|
|
51
53
|
HeaderBarMetrics,
|
|
52
54
|
getHeaderLayout,
|
|
53
55
|
useHeaderLayout,
|
|
56
|
+
KitsHost,
|
|
57
|
+
KitsBindingProvider,
|
|
54
58
|
};
|
|
55
59
|
|
|
56
60
|
export type { ModalLayout, ModalRect, HeaderContentLayout, HeaderLayout };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { Platform } from 'react-native';
|
|
3
3
|
import {
|
|
4
4
|
CardStyleInterpolators,
|
|
5
5
|
type StackCardInterpolatedStyle,
|
|
@@ -13,11 +13,7 @@ import { HeaderBackground } from './Components/HeaderBackground';
|
|
|
13
13
|
import { HeaderLeft } from './Components/HeaderLeft';
|
|
14
14
|
import { HeaderRight } from './Components/HeaderRight';
|
|
15
15
|
import { HeaderTitle, TitleCustom } from './Components/HeaderTitle';
|
|
16
|
-
import {
|
|
17
|
-
getHeaderRowInset,
|
|
18
|
-
HeaderBarMetrics,
|
|
19
|
-
TITLE_CONTAINER_RESET,
|
|
20
|
-
} from './headerLayout';
|
|
16
|
+
import { HeaderBarMetrics, TITLE_CONTAINER_RESET } from './headerLayout';
|
|
21
17
|
import type { HeaderTitleProps, NavigationOptions } from './types';
|
|
22
18
|
|
|
23
19
|
const CARD_SHADOW_OPACITY = 0.3;
|
|
@@ -148,9 +144,8 @@ const exportHeaderTitle = (
|
|
|
148
144
|
};
|
|
149
145
|
|
|
150
146
|
/**
|
|
151
|
-
* React Navigation options from screen params: design system header left,
|
|
152
|
-
*
|
|
153
|
-
* off for screens that own their back flow.
|
|
147
|
+
* React Navigation options from screen params: design system header left,
|
|
148
|
+
* title and right, and swipe back off for screens that own their back flow.
|
|
154
149
|
*/
|
|
155
150
|
const getOptions = (
|
|
156
151
|
params: NavigationOptions,
|
|
@@ -172,11 +167,9 @@ const getOptions = (
|
|
|
172
167
|
};
|
|
173
168
|
if (params.hiddenBack) {
|
|
174
169
|
headerLeft = null;
|
|
175
|
-
// options are static, so the window width is read once when they are built
|
|
176
|
-
const { width } = Dimensions.get('window');
|
|
177
170
|
options.headerTitleContainerStyle = {
|
|
178
171
|
...TITLE_CONTAINER_RESET,
|
|
179
|
-
left:
|
|
172
|
+
left: HeaderBarMetrics.sidePadding,
|
|
180
173
|
};
|
|
181
174
|
}
|
|
182
175
|
options = {
|
|
@@ -0,0 +1,134 @@
|
|
|
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 a no-op.
|
|
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
|
+
};
|
package/Application/types.ts
CHANGED
|
@@ -10,10 +10,12 @@ import type {
|
|
|
10
10
|
} from './types.header';
|
|
11
11
|
import type { LocalizeProps, Theme } from './types.theme';
|
|
12
12
|
import type { HeaderContentLayout } from './headerLayout';
|
|
13
|
+
import type { KitsBinding, ResolvedKitsBinding } from './types.binding';
|
|
13
14
|
|
|
14
15
|
export * from './types.theme';
|
|
15
16
|
export * from './types.header';
|
|
16
17
|
export * from './types.tabs';
|
|
18
|
+
export * from './types.binding';
|
|
17
19
|
|
|
18
20
|
export type NavigationProps = {
|
|
19
21
|
context: any;
|
|
@@ -24,7 +26,8 @@ export type NavigatorProps = {
|
|
|
24
26
|
ref?: any;
|
|
25
27
|
isReady?: any;
|
|
26
28
|
isWidget?: any;
|
|
27
|
-
|
|
29
|
+
/** Host services of this container, resolved through `KitsHost`. */
|
|
30
|
+
binding: ResolvedKitsBinding;
|
|
28
31
|
dismissData?: any;
|
|
29
32
|
push: (params: ScreenParams) => void;
|
|
30
33
|
replace: (params: ScreenParams) => void;
|
|
@@ -59,7 +62,11 @@ export type NavigationContainerProps = {
|
|
|
59
62
|
screen: React.ComponentType<NavigationScreenProps>;
|
|
60
63
|
options?: NavigationOptions;
|
|
61
64
|
theme?: Theme;
|
|
62
|
-
|
|
65
|
+
/**
|
|
66
|
+
* Optional. Host services for this mini app; defaults to the nearest enclosing
|
|
67
|
+
* container or `KitsBindingProvider`, then `KitsHost`. Keep it stable.
|
|
68
|
+
*/
|
|
69
|
+
binding?: KitsBinding;
|
|
63
70
|
initialParams?: any;
|
|
64
71
|
localize: LocalizeProps;
|
|
65
72
|
features?: FeatureFlags;
|
|
@@ -68,7 +75,11 @@ export type NavigationContainerProps = {
|
|
|
68
75
|
export type WidgetContainerProps = {
|
|
69
76
|
widget: React.ComponentType<any>;
|
|
70
77
|
theme?: Theme;
|
|
71
|
-
|
|
78
|
+
/**
|
|
79
|
+
* Optional. Host services for this widget's app; defaults to the enclosing
|
|
80
|
+
* container's (the parent mini app's), then `KitsHost`. Keep it stable.
|
|
81
|
+
*/
|
|
82
|
+
binding?: KitsBinding;
|
|
72
83
|
localize: LocalizeProps;
|
|
73
84
|
};
|
|
74
85
|
|
package/Button/index.tsx
CHANGED
|
@@ -192,10 +192,10 @@ const Button: FC<ButtonProps> = ({
|
|
|
192
192
|
|
|
193
193
|
const sizeStyle = getSizeStyle();
|
|
194
194
|
const typeStyle = getTypeStyle(type, theme, color);
|
|
195
|
-
const containerStyle
|
|
195
|
+
const containerStyle = StyleSheet.flatten([
|
|
196
196
|
full && { width: '100%' },
|
|
197
197
|
loading && { opacity: 0.75 },
|
|
198
|
-
]);
|
|
198
|
+
]) as ViewStyle;
|
|
199
199
|
const buttonStyle = StyleSheet.flatten([sizeStyle, typeStyle]);
|
|
200
200
|
|
|
201
201
|
const animatedStyle = useAnimatedStyle(() => {
|
package/Divider/DashDivider.tsx
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React, { useContext } from 'react';
|
|
2
|
-
import { StyleSheet, View, ViewStyle } from 'react-native';
|
|
2
|
+
import { StyleProp, StyleSheet, View, ViewStyle } from 'react-native';
|
|
3
3
|
import { ApplicationContext } from '../Context';
|
|
4
4
|
import { Spacing } from '../Consts';
|
|
5
5
|
import Svg, { Line } from 'react-native-svg';
|
|
@@ -8,7 +8,7 @@ export interface DashDividerProps {
|
|
|
8
8
|
/**
|
|
9
9
|
* Custom styles for dash divider
|
|
10
10
|
*/
|
|
11
|
-
style?: ViewStyle
|
|
11
|
+
style?: StyleProp<ViewStyle>;
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
/** 1px dashed horizontal line in the default border color. */
|
package/Divider/index.tsx
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React, { useContext } from 'react';
|
|
2
|
-
import { StyleSheet, View, ViewStyle } from 'react-native';
|
|
2
|
+
import { StyleProp, StyleSheet, View, ViewStyle } from 'react-native';
|
|
3
3
|
import { ApplicationContext } from '../Context';
|
|
4
4
|
import { Spacing } from '../Consts';
|
|
5
5
|
import { DashDivider } from './DashDivider';
|
|
@@ -8,7 +8,7 @@ export interface DividerProps {
|
|
|
8
8
|
/**
|
|
9
9
|
* Custom styles for divider
|
|
10
10
|
*/
|
|
11
|
-
style?: ViewStyle
|
|
11
|
+
style?: StyleProp<ViewStyle>;
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* Enable margin vertical 4px
|
|
@@ -34,10 +34,10 @@ const Divider: React.FC<DividerProps> = ({
|
|
|
34
34
|
return (
|
|
35
35
|
<View
|
|
36
36
|
style={[
|
|
37
|
-
style,
|
|
38
37
|
styles.divider,
|
|
39
38
|
useMargin ? styles.margin : styles.noMargin,
|
|
40
39
|
{ backgroundColor: theme.colors.border.default },
|
|
40
|
+
style,
|
|
41
41
|
]}
|
|
42
42
|
/>
|
|
43
43
|
);
|