@momo-kits/foundation 0.162.2-test.5 → 0.162.2-test.7
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.
|
@@ -29,7 +29,7 @@ import { HeaderBackground } from './Components/HeaderBackground';
|
|
|
29
29
|
|
|
30
30
|
const Stack = createStackNavigator();
|
|
31
31
|
|
|
32
|
-
//
|
|
32
|
+
// Observer storage key the host app writes FontScaleConfig to. Lowercased natively.
|
|
33
33
|
const FONT_SCALE_OBSERVER_KEY = 'font_scale_config';
|
|
34
34
|
|
|
35
35
|
const NavigationContainer: React.FC<NavigationContainerProps> = ({
|
|
@@ -48,7 +48,7 @@ const NavigationContainer: React.FC<NavigationContainerProps> = ({
|
|
|
48
48
|
}) => {
|
|
49
49
|
const context = useContext<any>(MiniAppContext);
|
|
50
50
|
const [currentContext, setCurrentContext] = useState<any>({});
|
|
51
|
-
// FontScaleConfig host
|
|
51
|
+
// FontScaleConfig the host writes to observer storage (single source of truth when present).
|
|
52
52
|
const [observerFontScaleConfig, setObserverFontScaleConfig] = useState<
|
|
53
53
|
FontScaleConfig | undefined
|
|
54
54
|
>(undefined);
|
|
@@ -64,13 +64,9 @@ const NavigationContainer: React.FC<NavigationContainerProps> = ({
|
|
|
64
64
|
|
|
65
65
|
useEffect(() => {
|
|
66
66
|
if (!maxApi) return;
|
|
67
|
-
//
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
(data: FontScaleConfig) => {
|
|
71
|
-
if (data) setObserverFontScaleConfig(data);
|
|
72
|
-
},
|
|
73
|
-
);
|
|
67
|
+
// The initial value is seeded by the host into MiniAppContext (mergedContext.fontScaleConfig)
|
|
68
|
+
// before the miniapp mounts, so the first frame is already scaled (no flash). Here we only
|
|
69
|
+
// subscribe to later host writes so a rate change applies live while the miniapp is open.
|
|
74
70
|
const sub = maxApi.observer?.(
|
|
75
71
|
FONT_SCALE_OBSERVER_KEY,
|
|
76
72
|
(data: FontScaleConfig) => {
|
|
@@ -6,7 +6,7 @@ const ScaleSizeProvider: FC<ScaleSizeProviderProps> = ({
|
|
|
6
6
|
fontScaleConfig,
|
|
7
7
|
children,
|
|
8
8
|
}) => {
|
|
9
|
-
//
|
|
9
|
+
// Inherit the config from an upper layer (e.g. app root) when the host doesn't set it via MiniAppContext.
|
|
10
10
|
const parent = useContext(ScaleSizeContext);
|
|
11
11
|
return (
|
|
12
12
|
<ScaleSizeContext.Provider value={fontScaleConfig ?? parent}>
|
package/Context/index.ts
CHANGED
|
@@ -9,7 +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
|
-
// Single source of truth:
|
|
12
|
+
// Single source of truth: holds both the OS flag and the user-adjusted rate.
|
|
13
13
|
export type FontScaleConfig = {
|
|
14
14
|
useOSFontScale?: boolean;
|
|
15
15
|
userScaleRate?: number;
|
package/Text/utils.ts
CHANGED
|
@@ -14,10 +14,10 @@ const useScaleSize = (size: number, userScaleRate?: number) => {
|
|
|
14
14
|
const { width } = useWindowDimensions();
|
|
15
15
|
const deviceScale = width / DEFAULT_SCREEN_SIZE;
|
|
16
16
|
|
|
17
|
-
//
|
|
17
|
+
// user-adjusted rate: param override > config > 1 (no scaling)
|
|
18
18
|
const customRate = userScaleRate ?? ctxRate ?? 1;
|
|
19
|
-
// useOSFontScale
|
|
20
|
-
//
|
|
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
21
|
const appliedRate = useOSFontScale ? fontScale : customRate;
|
|
22
22
|
|
|
23
23
|
let fontSizeDeviceScale = size;
|