@momo-kits/foundation 0.163.1-beta.2 → 0.163.1-sp.1
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/NavigationContainer.tsx +16 -12
- package/Application/ScaleSizeProvider.tsx +1 -0
- package/Application/StackScreen.tsx +1 -0
- package/Application/WidgetContainer.tsx +9 -6
- package/Context/index.ts +1 -0
- package/IconButton/index.tsx +28 -6
- package/IconButton/styles.ts +15 -7
- package/Layout/Screen.tsx +22 -2
- package/Text/utils.ts +6 -3
- package/package.json +1 -1
|
@@ -16,7 +16,6 @@ import { DeviceEventEmitter } from 'react-native';
|
|
|
16
16
|
import StackScreen from './StackScreen';
|
|
17
17
|
import ModalScreen from './ModalScreen';
|
|
18
18
|
import Navigator from './Navigator';
|
|
19
|
-
import ScaleSizeProvider from './ScaleSizeProvider';
|
|
20
19
|
import { getModalOptions, getStackOptions } from './utils';
|
|
21
20
|
import { NavigationContainerProps } from './types';
|
|
22
21
|
import { ApplicationContext, MiniAppContext } from '../Context';
|
|
@@ -46,6 +45,13 @@ const NavigationContainer: React.FC<NavigationContainerProps> = ({
|
|
|
46
45
|
const context = useContext<any>(MiniAppContext);
|
|
47
46
|
const [currentContext, setCurrentContext] = useState<any>({});
|
|
48
47
|
|
|
48
|
+
useEffect(() => {
|
|
49
|
+
const sub = maxApi?.observer?.('font_scale_config', (data: any) => {
|
|
50
|
+
setCurrentContext((prev: any) => ({ ...prev, fontScale: data }));
|
|
51
|
+
});
|
|
52
|
+
return () => sub?.remove?.();
|
|
53
|
+
}, [maxApi]);
|
|
54
|
+
|
|
49
55
|
const mergedContext = {
|
|
50
56
|
...context,
|
|
51
57
|
...currentContext,
|
|
@@ -58,17 +64,15 @@ const NavigationContainer: React.FC<NavigationContainerProps> = ({
|
|
|
58
64
|
return (
|
|
59
65
|
<SafeAreaProvider>
|
|
60
66
|
<MiniAppContext.Provider value={mergedContext}>
|
|
61
|
-
<
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
/>
|
|
71
|
-
</ScaleSizeProvider>
|
|
67
|
+
<Navigation
|
|
68
|
+
screen={screen}
|
|
69
|
+
theme={theme}
|
|
70
|
+
options={options}
|
|
71
|
+
maxApi={maxApi}
|
|
72
|
+
setCurrentContext={setCurrentContext}
|
|
73
|
+
initialParams={initialParams}
|
|
74
|
+
localize={localize}
|
|
75
|
+
/>
|
|
72
76
|
</MiniAppContext.Provider>
|
|
73
77
|
</SafeAreaProvider>
|
|
74
78
|
);
|
|
@@ -2,6 +2,7 @@ import React, { FC } from 'react';
|
|
|
2
2
|
import { ScaleSizeContext } from '../Context';
|
|
3
3
|
import { ScaleSizeProviderProps } from './types';
|
|
4
4
|
|
|
5
|
+
/** @deprecated Max font scale is fixed at 1.5; this provider no longer affects scaling. */
|
|
5
6
|
const ScaleSizeProvider: FC<ScaleSizeProviderProps> = ({
|
|
6
7
|
scaleSizeMaxRate,
|
|
7
8
|
children,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { useContext, useRef, useState } from 'react';
|
|
1
|
+
import React, { useContext, useEffect, useRef, useState } from 'react';
|
|
2
2
|
import { SafeAreaProvider } from 'react-native-safe-area-context';
|
|
3
3
|
import Navigator from './Navigator';
|
|
4
4
|
import ScaleSizeProvider from './ScaleSizeProvider';
|
|
@@ -44,6 +44,13 @@ const WidgetContainer: React.FC<WidgetContainerProps> = ({
|
|
|
44
44
|
const navigator = useRef(new Navigator(navigationRef, isReady, true));
|
|
45
45
|
const [currentContext, setCurrentContext] = useState({});
|
|
46
46
|
|
|
47
|
+
useEffect(() => {
|
|
48
|
+
const sub = maxApi?.observer?.('font_scale_config', (data: any) => {
|
|
49
|
+
setCurrentContext((prev: any) => ({ ...prev, fontScale: data }));
|
|
50
|
+
});
|
|
51
|
+
return () => sub?.remove?.();
|
|
52
|
+
}, [maxApi]);
|
|
53
|
+
|
|
47
54
|
let headerBackground = context?.designConfig?.headerBar;
|
|
48
55
|
let headerGradient = theme.colors?.gradient;
|
|
49
56
|
|
|
@@ -74,12 +81,9 @@ const WidgetContainer: React.FC<WidgetContainerProps> = ({
|
|
|
74
81
|
};
|
|
75
82
|
|
|
76
83
|
return (
|
|
77
|
-
<View style={{ height: height ?? '100%', minHeight:1 }}>
|
|
84
|
+
<View style={{ height: height ?? '100%', minHeight: 1 }}>
|
|
78
85
|
<SafeAreaProvider>
|
|
79
86
|
<MiniAppContext.Provider value={mergedContext}>
|
|
80
|
-
<ScaleSizeProvider
|
|
81
|
-
scaleSizeMaxRate={mergedContext?.scaleSizeMaxRate}
|
|
82
|
-
>
|
|
83
87
|
<ApplicationContext.Provider
|
|
84
88
|
value={{
|
|
85
89
|
navigator: navigator.current,
|
|
@@ -157,7 +161,6 @@ const WidgetContainer: React.FC<WidgetContainerProps> = ({
|
|
|
157
161
|
</ReactNavigationContainer>
|
|
158
162
|
</NavigationIndependentTree>
|
|
159
163
|
</ApplicationContext.Provider>
|
|
160
|
-
</ScaleSizeProvider>
|
|
161
164
|
</MiniAppContext.Provider>
|
|
162
165
|
</SafeAreaProvider>
|
|
163
166
|
</View>
|
package/Context/index.ts
CHANGED
|
@@ -9,6 +9,7 @@ const MiniAppContext = (Platform as any).MiniAppContext ?? Context;
|
|
|
9
9
|
const ScreenContext = (Platform as any).ScreenContext ?? Context;
|
|
10
10
|
const ComponentContext = (Platform as any).ComponentContext ?? Context;
|
|
11
11
|
const SkeletonContext = createContext({ loading: false });
|
|
12
|
+
/** @deprecated Max font scale is fixed at 1.5; this context is no longer read. */
|
|
12
13
|
const ScaleSizeContext = createContext<{ scaleSizeMaxRate?: number }>({
|
|
13
14
|
scaleSizeMaxRate: undefined,
|
|
14
15
|
});
|
package/IconButton/index.tsx
CHANGED
|
@@ -28,7 +28,12 @@ export interface IconButtonProps extends TouchableOpacityProps {
|
|
|
28
28
|
/**
|
|
29
29
|
* Optional. Defines the size of the IconButton.
|
|
30
30
|
*/
|
|
31
|
-
size?: 'large' | 'small';
|
|
31
|
+
size?: 'large' | 'medium' | 'small';
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Optional. Defines the shape of the IconButton.
|
|
35
|
+
*/
|
|
36
|
+
shape?: 'circle' | 'square';
|
|
32
37
|
|
|
33
38
|
/**
|
|
34
39
|
* Optional. Params auto tracking component.
|
|
@@ -40,6 +45,7 @@ const IconButton: React.FC<IconButtonProps> = ({
|
|
|
40
45
|
type = 'primary',
|
|
41
46
|
icon,
|
|
42
47
|
size,
|
|
48
|
+
shape = 'circle',
|
|
43
49
|
params,
|
|
44
50
|
...rest
|
|
45
51
|
}) => {
|
|
@@ -52,10 +58,21 @@ const IconButton: React.FC<IconButtonProps> = ({
|
|
|
52
58
|
* get size icon button
|
|
53
59
|
*/
|
|
54
60
|
const getSizeStyle = () => {
|
|
55
|
-
|
|
56
|
-
|
|
61
|
+
switch (size) {
|
|
62
|
+
case 'small':
|
|
63
|
+
return styles.small;
|
|
64
|
+
case 'medium':
|
|
65
|
+
return styles.medium;
|
|
66
|
+
default:
|
|
67
|
+
return styles.large;
|
|
57
68
|
}
|
|
58
|
-
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* get shape icon button
|
|
73
|
+
*/
|
|
74
|
+
const getShapeStyle = () => {
|
|
75
|
+
return shape === 'square' ? styles.square : styles.circle;
|
|
59
76
|
};
|
|
60
77
|
|
|
61
78
|
/**
|
|
@@ -117,8 +134,13 @@ const IconButton: React.FC<IconButtonProps> = ({
|
|
|
117
134
|
};
|
|
118
135
|
|
|
119
136
|
const activeOpacity = type === 'disabled' ? 0.75 : 0.5;
|
|
120
|
-
const buttonStyle = StyleSheet.flatten([
|
|
121
|
-
|
|
137
|
+
const buttonStyle = StyleSheet.flatten([
|
|
138
|
+
getTypeStyle(),
|
|
139
|
+
styles.base,
|
|
140
|
+
getSizeStyle(),
|
|
141
|
+
getShapeStyle(),
|
|
142
|
+
]);
|
|
143
|
+
const iconSize = size === 'small' || size === 'medium' ? 16 : 24;
|
|
122
144
|
|
|
123
145
|
return (
|
|
124
146
|
<ComponentContext.Provider
|
package/IconButton/styles.ts
CHANGED
|
@@ -2,19 +2,27 @@ import { StyleSheet } from 'react-native';
|
|
|
2
2
|
import { Radius, Colors } from '../Consts';
|
|
3
3
|
|
|
4
4
|
export default StyleSheet.create({
|
|
5
|
+
base: {
|
|
6
|
+
justifyContent: 'center',
|
|
7
|
+
alignItems: 'center',
|
|
8
|
+
},
|
|
5
9
|
large: {
|
|
6
10
|
width: 48,
|
|
7
11
|
height: 48,
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
12
|
+
},
|
|
13
|
+
medium: {
|
|
14
|
+
width: 36,
|
|
15
|
+
height: 36,
|
|
11
16
|
},
|
|
12
17
|
small: {
|
|
13
|
-
width:
|
|
14
|
-
height:
|
|
18
|
+
width: 28,
|
|
19
|
+
height: 28,
|
|
20
|
+
},
|
|
21
|
+
circle: {
|
|
15
22
|
borderRadius: Radius.XL,
|
|
16
|
-
|
|
17
|
-
|
|
23
|
+
},
|
|
24
|
+
square: {
|
|
25
|
+
borderRadius: Radius.S,
|
|
18
26
|
},
|
|
19
27
|
debugBaseLine: { borderWidth: 1, borderColor: Colors.green_06 },
|
|
20
28
|
});
|
package/Layout/Screen.tsx
CHANGED
|
@@ -166,6 +166,13 @@ export interface ScreenProps extends ViewProps {
|
|
|
166
166
|
trackingParams?: ScreenTrackingParams;
|
|
167
167
|
}
|
|
168
168
|
|
|
169
|
+
/**
|
|
170
|
+
* Scroll distance (px) over which the animated search header collapses from its
|
|
171
|
+
* expanded to its docked state — the input range consumed by `HeaderExtendHeader`
|
|
172
|
+
* and the settle threshold in `handleScrollEnd`.
|
|
173
|
+
*/
|
|
174
|
+
const SEARCH_HEADER_COLLAPSE_DISTANCE = 100;
|
|
175
|
+
|
|
169
176
|
const Screen = forwardRef(
|
|
170
177
|
(
|
|
171
178
|
{
|
|
@@ -195,7 +202,7 @@ const Screen = forwardRef(
|
|
|
195
202
|
ref: any,
|
|
196
203
|
) => {
|
|
197
204
|
const screenRef = useRef<View | ScrollView>(null);
|
|
198
|
-
const { width: widthDevice } = useWindowDimensions();
|
|
205
|
+
const { width: widthDevice, height: heightDevice } = useWindowDimensions();
|
|
199
206
|
const { theme } = useContext(ApplicationContext);
|
|
200
207
|
const screen: any = useContext(ScreenContext);
|
|
201
208
|
const insets = useSafeAreaInsets();
|
|
@@ -235,7 +242,9 @@ const Screen = forwardRef(
|
|
|
235
242
|
}, [customAnimatedValue, internalShared]);
|
|
236
243
|
|
|
237
244
|
const currentTint = useRef<string | undefined>(undefined);
|
|
238
|
-
const isTab =
|
|
245
|
+
const isTab =
|
|
246
|
+
navigation?.instance?.getState?.()?.type === 'tab' ||
|
|
247
|
+
!!screen?.bottomTab;
|
|
239
248
|
|
|
240
249
|
let handleScroll;
|
|
241
250
|
let Component: any = View;
|
|
@@ -656,6 +665,17 @@ const Screen = forwardRef(
|
|
|
656
665
|
]}
|
|
657
666
|
contentContainerStyle={[
|
|
658
667
|
scrollable && !Footer && !isTab && { paddingBottom: bottomInset },
|
|
668
|
+
// The animated search header collapses as the body scrolls. When the
|
|
669
|
+
// body is short (e.g. no search history) the ScrollView is barely
|
|
670
|
+
// scrollable, so overscroll bounce feeds the scroll-driven animation
|
|
671
|
+
// and the input jitters on its way up to the header. A ScrollView
|
|
672
|
+
// frame can never exceed the window, so forcing the content to be at
|
|
673
|
+
// least one screen plus the collapse distance guarantees the animation
|
|
674
|
+
// always has room to complete smoothly, independent of body content.
|
|
675
|
+
scrollable &&
|
|
676
|
+
inputSearchProps && {
|
|
677
|
+
minHeight: heightDevice + SEARCH_HEADER_COLLAPSE_DISTANCE,
|
|
678
|
+
},
|
|
659
679
|
scrollViewProps?.contentContainerStyle,
|
|
660
680
|
]}
|
|
661
681
|
>
|
package/Text/utils.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Dimensions, PixelRatio, useWindowDimensions } from 'react-native';
|
|
2
2
|
import { useContext } from 'react';
|
|
3
|
-
import {
|
|
3
|
+
import { MiniAppContext } from '../Context';
|
|
4
4
|
|
|
5
5
|
const deviceWidth = Dimensions.get('window').width;
|
|
6
6
|
const DEFAULT_SCREEN_SIZE = 375;
|
|
@@ -8,12 +8,15 @@ const MAX_FONT_SCALE = 1.5;
|
|
|
8
8
|
const MAX_DEVICE_SCALE = 5;
|
|
9
9
|
|
|
10
10
|
const useScaleSize = (size: number, scaleRate?: number) => {
|
|
11
|
-
const
|
|
11
|
+
const context = useContext<any>(MiniAppContext);
|
|
12
|
+
if (context?.fontScale?.useOSScaleRate === false) {
|
|
13
|
+
return size * (context.fontScale.userScaleRate ?? 1);
|
|
14
|
+
}
|
|
12
15
|
const fontScale = PixelRatio.getFontScale();
|
|
13
16
|
const { width } = useWindowDimensions();
|
|
14
17
|
const deviceScale = width / DEFAULT_SCREEN_SIZE;
|
|
15
18
|
|
|
16
|
-
const maxScaleRate = scaleRate ??
|
|
19
|
+
const maxScaleRate = scaleRate ?? MAX_FONT_SCALE;
|
|
17
20
|
|
|
18
21
|
let fontSizeDeviceScale = size;
|
|
19
22
|
let fontSizeOSScale = size;
|