@momo-kits/foundation 0.162.3-fontscale.1 → 0.162.3-fontscale.2
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.
|
@@ -46,6 +46,13 @@ const NavigationContainer: React.FC<NavigationContainerProps> = ({
|
|
|
46
46
|
const context = useContext<any>(MiniAppContext);
|
|
47
47
|
const [currentContext, setCurrentContext] = useState<any>({});
|
|
48
48
|
|
|
49
|
+
useEffect(() => {
|
|
50
|
+
const sub = maxApi?.observer?.('font_scale_config', (data: any) => {
|
|
51
|
+
setCurrentContext((prev: any) => ({ ...prev, fontScale: data }));
|
|
52
|
+
});
|
|
53
|
+
return () => sub?.remove?.();
|
|
54
|
+
}, [maxApi]);
|
|
55
|
+
|
|
49
56
|
const mergedContext = {
|
|
50
57
|
...context,
|
|
51
58
|
...currentContext,
|
|
@@ -117,12 +124,6 @@ const Navigation: React.FC<any> = ({
|
|
|
117
124
|
},
|
|
118
125
|
);
|
|
119
126
|
|
|
120
|
-
// TEMP: verify FontScale MaxApi end-to-end — remove after test
|
|
121
|
-
// @ts-ignore getFontScale added in newer @momo-platform/api
|
|
122
|
-
maxApi?.getFontScale?.((scale: any) =>
|
|
123
|
-
console.log('[FontScale][momo-kit] getFontScale ->', scale),
|
|
124
|
-
);
|
|
125
|
-
|
|
126
127
|
return () => {
|
|
127
128
|
subscription?.remove?.();
|
|
128
129
|
};
|
|
@@ -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
|
|
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/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;
|