@momo-kits/foundation 0.169.16-beta.9 → 0.169.17-beta.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.
|
@@ -78,7 +78,7 @@ export const TabLabel: React.FC<{
|
|
|
78
78
|
<MiniAppContext.Provider
|
|
79
79
|
value={{
|
|
80
80
|
...context,
|
|
81
|
-
fontScale: { useOSScaleRate: false,
|
|
81
|
+
fontScale: { useOSScaleRate: false, appScaleRate: 1 },
|
|
82
82
|
}}
|
|
83
83
|
>
|
|
84
84
|
<Text numberOfLines={1} typography={typography} color={color}>
|
package/Text/utils.ts
CHANGED
|
@@ -5,24 +5,50 @@ import { MiniAppContext } from '../Context';
|
|
|
5
5
|
const DEFAULT_SCREEN_SIZE = 375;
|
|
6
6
|
const MAX_FONT_SCALE = 1.5;
|
|
7
7
|
const MAX_DEVICE_SCALE = 5;
|
|
8
|
+
const APP_SCALE_LEVELS = [1, 1.2, 1.3, 1.4];
|
|
8
9
|
|
|
9
10
|
type MiniAppScale = {
|
|
10
11
|
scaleSizeMaxRate?: number;
|
|
11
|
-
fontScale?: {
|
|
12
|
+
fontScale?: {
|
|
13
|
+
useOSScaleRate?: boolean;
|
|
14
|
+
appScaleRate?: number;
|
|
15
|
+
/** @deprecated Use `appScaleRate`. Still sent by the host. */
|
|
16
|
+
userScaleRate?: number;
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Snaps a host scale rate to the nearest app scale level (1, 1.2, 1.3, 1.4),
|
|
22
|
+
* ties going lower, so legacy rates (1.1, 1.6) resolve like the host does.
|
|
23
|
+
*/
|
|
24
|
+
const toAppScaleRate = (rate?: number) => {
|
|
25
|
+
if (!rate) {
|
|
26
|
+
return APP_SCALE_LEVELS[0];
|
|
27
|
+
}
|
|
28
|
+
const percent = Math.round(rate * 100);
|
|
29
|
+
const distance = (level: number) =>
|
|
30
|
+
Math.abs(Math.round(level * 100) - percent);
|
|
31
|
+
return APP_SCALE_LEVELS.reduce((best, level) =>
|
|
32
|
+
distance(level) < distance(best) ? level : best,
|
|
33
|
+
);
|
|
12
34
|
};
|
|
13
35
|
|
|
14
36
|
/**
|
|
15
37
|
* Scales `size` by screen width (+5 max) and OS font scale (max `scaleRate`,
|
|
16
38
|
* else the ScaleSizeProvider rate, else 1.5), taking the larger, or by the mini
|
|
17
|
-
* app `fontScale.
|
|
39
|
+
* app `fontScale.appScaleRate`; a provider rate caps both at `size × rate`.
|
|
18
40
|
*/
|
|
19
41
|
const useScaleSize = (size: number, scaleRate?: number) => {
|
|
20
42
|
const { width } = useWindowDimensions();
|
|
21
43
|
const context = useContext<MiniAppScale | undefined>(MiniAppContext);
|
|
22
44
|
const scaleSizeMaxRate = context?.scaleSizeMaxRate;
|
|
23
45
|
const maxSize = scaleSizeMaxRate ? size * scaleSizeMaxRate : Infinity;
|
|
24
|
-
|
|
25
|
-
|
|
46
|
+
const appScale = context?.fontScale;
|
|
47
|
+
if (appScale?.useOSScaleRate === false) {
|
|
48
|
+
const rate = toAppScaleRate(
|
|
49
|
+
appScale.appScaleRate ?? appScale.userScaleRate,
|
|
50
|
+
);
|
|
51
|
+
return Math.min(size * rate, maxSize);
|
|
26
52
|
}
|
|
27
53
|
const fontScale = PixelRatio.getFontScale();
|
|
28
54
|
const deviceScale = width / DEFAULT_SCREEN_SIZE;
|