@momo-kits/foundation 0.162.2-test.7 → 0.162.2-test.9
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 +8 -8
- package/Text/utils.ts +11 -5
- package/package.json +1 -1
|
@@ -48,10 +48,11 @@ const NavigationContainer: React.FC<NavigationContainerProps> = ({
|
|
|
48
48
|
}) => {
|
|
49
49
|
const context = useContext<any>(MiniAppContext);
|
|
50
50
|
const [currentContext, setCurrentContext] = useState<any>({});
|
|
51
|
-
//
|
|
51
|
+
// Default = the host-seeded fontScaleConfig from MiniAppContext, so the first frame is already
|
|
52
|
+
// scaled (no flash). The observer below overwrites it on later host writes (live rate changes).
|
|
52
53
|
const [observerFontScaleConfig, setObserverFontScaleConfig] = useState<
|
|
53
54
|
FontScaleConfig | undefined
|
|
54
|
-
>(
|
|
55
|
+
>(context?.fontScaleConfig);
|
|
55
56
|
|
|
56
57
|
const mergedContext = {
|
|
57
58
|
...context,
|
|
@@ -63,11 +64,10 @@ const NavigationContainer: React.FC<NavigationContainerProps> = ({
|
|
|
63
64
|
};
|
|
64
65
|
|
|
65
66
|
useEffect(() => {
|
|
66
|
-
|
|
67
|
-
//
|
|
68
|
-
//
|
|
69
|
-
|
|
70
|
-
const sub = maxApi.observer?.(
|
|
67
|
+
// The initial value is seeded by the host into MiniAppContext and used as this state's default
|
|
68
|
+
// above, so the first frame is already scaled (no flash). Here we only subscribe to later host
|
|
69
|
+
// writes so a rate change applies live while the miniapp is open.
|
|
70
|
+
const sub = maxApi?.observer?.(
|
|
71
71
|
FONT_SCALE_OBSERVER_KEY,
|
|
72
72
|
(data: FontScaleConfig) => {
|
|
73
73
|
setObserverFontScaleConfig(data ?? undefined);
|
|
@@ -82,7 +82,7 @@ const NavigationContainer: React.FC<NavigationContainerProps> = ({
|
|
|
82
82
|
<SafeAreaProvider>
|
|
83
83
|
<MiniAppContext.Provider value={mergedContext}>
|
|
84
84
|
<ScaleSizeProvider
|
|
85
|
-
fontScaleConfig={observerFontScaleConfig
|
|
85
|
+
fontScaleConfig={observerFontScaleConfig}
|
|
86
86
|
>
|
|
87
87
|
<Navigation
|
|
88
88
|
screen={screen}
|
package/Text/utils.ts
CHANGED
|
@@ -16,10 +16,16 @@ const useScaleSize = (size: number, userScaleRate?: number) => {
|
|
|
16
16
|
|
|
17
17
|
// user-adjusted rate: param override > config > 1 (no scaling)
|
|
18
18
|
const customRate = userScaleRate ?? ctxRate ?? 1;
|
|
19
|
-
// useOSFontScale on -> apply the OS scale, ignore the custom rate;
|
|
20
|
-
// off -> use the custom rate. Both hard-capped at MAX_FONT_SCALE (150%).
|
|
21
|
-
const appliedRate = useOSFontScale ? fontScale : customRate;
|
|
22
19
|
|
|
20
|
+
// useOSFontScale off -> the user has full control via customRate; skip device-width scaling
|
|
21
|
+
// entirely and apply only the custom rate (capped at MAX_FONT_SCALE).
|
|
22
|
+
if (!useOSFontScale) {
|
|
23
|
+
return customRate > 1
|
|
24
|
+
? Math.min(customRate * size, size * MAX_FONT_SCALE)
|
|
25
|
+
: size;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// useOSFontScale on -> device-width scale + OS font scale, take the larger.
|
|
23
29
|
let fontSizeDeviceScale = size;
|
|
24
30
|
let fontSizeOSScale = size;
|
|
25
31
|
|
|
@@ -30,9 +36,9 @@ const useScaleSize = (size: number, userScaleRate?: number) => {
|
|
|
30
36
|
);
|
|
31
37
|
}
|
|
32
38
|
|
|
33
|
-
if (
|
|
39
|
+
if (fontScale > 1) {
|
|
34
40
|
fontSizeOSScale = Math.min(
|
|
35
|
-
|
|
41
|
+
fontScale * fontSizeOSScale,
|
|
36
42
|
fontSizeOSScale * MAX_FONT_SCALE,
|
|
37
43
|
);
|
|
38
44
|
}
|