@momo-kits/foundation 0.162.1-beta.3 → 0.162.2-beta.15
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.
|
@@ -19,7 +19,7 @@ import Navigator from './Navigator';
|
|
|
19
19
|
import ScaleSizeProvider from './ScaleSizeProvider';
|
|
20
20
|
import { getModalOptions, getStackOptions } from './utils';
|
|
21
21
|
import { NavigationContainerProps } from './types';
|
|
22
|
-
import { ApplicationContext,
|
|
22
|
+
import { ApplicationContext, MiniAppContext } from '../Context';
|
|
23
23
|
import Localize from './Localize';
|
|
24
24
|
import { Colors, defaultTheme } from '../Consts';
|
|
25
25
|
import { HeaderLeft } from './Components/HeaderLeft';
|
|
@@ -29,29 +29,6 @@ import { HeaderBackground } from './Components/HeaderBackground';
|
|
|
29
29
|
|
|
30
30
|
const Stack = createStackNavigator();
|
|
31
31
|
|
|
32
|
-
const FONT_SCALE_OBSERVER_KEY = 'font_scale_config';
|
|
33
|
-
|
|
34
|
-
// AI-GENERATED START: parse the font_scale_config first-frame seed read straight from async storage (string | {response} | object)
|
|
35
|
-
const parseSeedFontScaleConfig = (raw: any): FontScaleConfig | undefined => {
|
|
36
|
-
let data = raw;
|
|
37
|
-
if (typeof data === 'string') {
|
|
38
|
-
try {
|
|
39
|
-
data = JSON.parse(data);
|
|
40
|
-
} catch {
|
|
41
|
-
return undefined;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
data = data?.response ?? data;
|
|
45
|
-
if (!data || (data.useOSFontScale === undefined && data.userScaleRate === undefined)) {
|
|
46
|
-
return undefined;
|
|
47
|
-
}
|
|
48
|
-
return {
|
|
49
|
-
useOSFontScale: data.useOSFontScale,
|
|
50
|
-
userScaleRate: data.userScaleRate,
|
|
51
|
-
};
|
|
52
|
-
};
|
|
53
|
-
// AI-GENERATED END: parse the font_scale_config first-frame seed read straight from async storage (string | {response} | object)
|
|
54
|
-
|
|
55
32
|
const NavigationContainer: React.FC<NavigationContainerProps> = ({
|
|
56
33
|
screen,
|
|
57
34
|
theme = defaultTheme,
|
|
@@ -68,11 +45,6 @@ const NavigationContainer: React.FC<NavigationContainerProps> = ({
|
|
|
68
45
|
}) => {
|
|
69
46
|
const context = useContext<any>(MiniAppContext);
|
|
70
47
|
const [currentContext, setCurrentContext] = useState<any>({});
|
|
71
|
-
// AI-GENERATED START: self-seed first-frame font scale by reading font_scale_config straight from async storage
|
|
72
|
-
const [observerFontScaleConfig, setObserverFontScaleConfig] = useState<
|
|
73
|
-
FontScaleConfig | undefined
|
|
74
|
-
>(() => parseSeedFontScaleConfig(maxApi?.getItem?.(FONT_SCALE_OBSERVER_KEY)) ?? context?.fontScaleConfig);
|
|
75
|
-
// AI-GENERATED END: self-seed first-frame font scale by reading font_scale_config straight from async storage
|
|
76
48
|
|
|
77
49
|
const mergedContext = {
|
|
78
50
|
...context,
|
|
@@ -83,24 +55,10 @@ const NavigationContainer: React.FC<NavigationContainerProps> = ({
|
|
|
83
55
|
},
|
|
84
56
|
};
|
|
85
57
|
|
|
86
|
-
useEffect(() => {
|
|
87
|
-
const sub = maxApi?.observer?.(
|
|
88
|
-
FONT_SCALE_OBSERVER_KEY,
|
|
89
|
-
(data: FontScaleConfig) => {
|
|
90
|
-
setObserverFontScaleConfig(data ?? undefined);
|
|
91
|
-
},
|
|
92
|
-
);
|
|
93
|
-
return () => {
|
|
94
|
-
sub?.remove?.();
|
|
95
|
-
};
|
|
96
|
-
}, [maxApi]);
|
|
97
|
-
|
|
98
58
|
return (
|
|
99
59
|
<SafeAreaProvider>
|
|
100
60
|
<MiniAppContext.Provider value={mergedContext}>
|
|
101
|
-
<ScaleSizeProvider
|
|
102
|
-
fontScaleConfig={observerFontScaleConfig}
|
|
103
|
-
>
|
|
61
|
+
<ScaleSizeProvider scaleSizeMaxRate={mergedContext?.scaleSizeMaxRate}>
|
|
104
62
|
<Navigation
|
|
105
63
|
screen={screen}
|
|
106
64
|
theme={theme}
|
|
@@ -1,15 +1,13 @@
|
|
|
1
|
-
import React, { FC
|
|
1
|
+
import React, { FC } from 'react';
|
|
2
2
|
import { ScaleSizeContext } from '../Context';
|
|
3
3
|
import { ScaleSizeProviderProps } from './types';
|
|
4
4
|
|
|
5
5
|
const ScaleSizeProvider: FC<ScaleSizeProviderProps> = ({
|
|
6
|
-
|
|
6
|
+
scaleSizeMaxRate,
|
|
7
7
|
children,
|
|
8
8
|
}) => {
|
|
9
|
-
// Inherit the config from an upper layer (e.g. app root) when the host doesn't set it via MiniAppContext.
|
|
10
|
-
const parent = useContext(ScaleSizeContext);
|
|
11
9
|
return (
|
|
12
|
-
<ScaleSizeContext.Provider value={
|
|
10
|
+
<ScaleSizeContext.Provider value={{ scaleSizeMaxRate }}>
|
|
13
11
|
{children}
|
|
14
12
|
</ScaleSizeContext.Provider>
|
|
15
13
|
);
|
|
@@ -78,7 +78,7 @@ const WidgetContainer: React.FC<WidgetContainerProps> = ({
|
|
|
78
78
|
<SafeAreaProvider>
|
|
79
79
|
<MiniAppContext.Provider value={mergedContext}>
|
|
80
80
|
<ScaleSizeProvider
|
|
81
|
-
|
|
81
|
+
scaleSizeMaxRate={mergedContext?.scaleSizeMaxRate}
|
|
82
82
|
>
|
|
83
83
|
<ApplicationContext.Provider
|
|
84
84
|
value={{
|
package/Application/types.ts
CHANGED
|
@@ -10,7 +10,6 @@ import {
|
|
|
10
10
|
import type { SharedValue } from 'react-native-reanimated';
|
|
11
11
|
import { PopupNotifyProps } from '../Popup/types';
|
|
12
12
|
import { InputRef, InputSearchProps } from '../Input';
|
|
13
|
-
import { FontScaleConfig } from '../Context';
|
|
14
13
|
import Navigation from './Navigation';
|
|
15
14
|
|
|
16
15
|
export type NavigationProps = {
|
|
@@ -110,7 +109,7 @@ export type Theme = {
|
|
|
110
109
|
};
|
|
111
110
|
|
|
112
111
|
export type ScaleSizeProviderProps = {
|
|
113
|
-
|
|
112
|
+
scaleSizeMaxRate?: number;
|
|
114
113
|
children: ViewProps['children'];
|
|
115
114
|
};
|
|
116
115
|
|
package/Context/index.ts
CHANGED
|
@@ -9,12 +9,9 @@ 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
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
userScaleRate?: number;
|
|
16
|
-
};
|
|
17
|
-
const ScaleSizeContext = createContext<FontScaleConfig>({});
|
|
12
|
+
const ScaleSizeContext = createContext<{ scaleSizeMaxRate?: number }>({
|
|
13
|
+
scaleSizeMaxRate: undefined,
|
|
14
|
+
});
|
|
18
15
|
const TrackingScopeContext = createContext<{ scopeName?: string }>({
|
|
19
16
|
scopeName: undefined,
|
|
20
17
|
});
|
package/Layout/Screen.tsx
CHANGED
|
@@ -650,14 +650,7 @@ const Screen = forwardRef(
|
|
|
650
650
|
onScroll={handleScroll}
|
|
651
651
|
onScrollEndDrag={handleScrollEnd}
|
|
652
652
|
scrollEventThrottle={16}
|
|
653
|
-
style={
|
|
654
|
-
Styles.flex,
|
|
655
|
-
!scrollable && !Footer && !isTab && { paddingBottom: bottomInset },
|
|
656
|
-
]}
|
|
657
|
-
contentContainerStyle={[
|
|
658
|
-
scrollable && !Footer && !isTab && { paddingBottom: bottomInset },
|
|
659
|
-
scrollViewProps?.contentContainerStyle,
|
|
660
|
-
]}
|
|
653
|
+
style={Styles.flex}
|
|
661
654
|
>
|
|
662
655
|
{renderAnimatedHeader()}
|
|
663
656
|
|
package/Text/utils.ts
CHANGED
|
@@ -7,18 +7,13 @@ const DEFAULT_SCREEN_SIZE = 375;
|
|
|
7
7
|
const MAX_FONT_SCALE = 1.5;
|
|
8
8
|
const MAX_DEVICE_SCALE = 5;
|
|
9
9
|
|
|
10
|
-
const useScaleSize = (size: number,
|
|
11
|
-
const {
|
|
12
|
-
useContext(ScaleSizeContext);
|
|
10
|
+
const useScaleSize = (size: number, scaleRate?: number) => {
|
|
11
|
+
const { scaleSizeMaxRate = MAX_FONT_SCALE } = useContext(ScaleSizeContext);
|
|
13
12
|
const fontScale = PixelRatio.getFontScale();
|
|
14
13
|
const { width } = useWindowDimensions();
|
|
15
14
|
const deviceScale = width / DEFAULT_SCREEN_SIZE;
|
|
16
15
|
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
if (!useOSFontScale) {
|
|
20
|
-
return customRate > 1 ? customRate * size : size;
|
|
21
|
-
}
|
|
16
|
+
const maxScaleRate = scaleRate ?? scaleSizeMaxRate;
|
|
22
17
|
|
|
23
18
|
let fontSizeDeviceScale = size;
|
|
24
19
|
let fontSizeOSScale = size;
|
|
@@ -32,8 +27,8 @@ const useScaleSize = (size: number, userScaleRate?: number) => {
|
|
|
32
27
|
|
|
33
28
|
if (fontScale > 1) {
|
|
34
29
|
fontSizeOSScale = Math.min(
|
|
35
|
-
|
|
36
|
-
fontSizeOSScale *
|
|
30
|
+
fontSizeOSScale * fontScale,
|
|
31
|
+
fontSizeOSScale * maxScaleRate,
|
|
37
32
|
);
|
|
38
33
|
}
|
|
39
34
|
|