@momo-kits/foundation 0.162.2-test.5 → 0.162.2-test.8

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
- // Key observer storage host app ghi FontScaleConfig. Native lowercase key.
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,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
- // FontScaleConfig host ghi xuống observer storage (single source of truth khi có).
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
- >(undefined);
55
+ >(context?.fontScaleConfig);
55
56
 
56
57
  const mergedContext = {
57
58
  ...context,
@@ -63,15 +64,10 @@ const NavigationContainer: React.FC<NavigationContainerProps> = ({
63
64
  };
64
65
 
65
66
  useEffect(() => {
66
- if (!maxApi) return;
67
- // getDataObserver = snapshot lúc mount; observer = subscribe các lần host ghi sau đó.
68
- maxApi.getDataObserver?.(
69
- FONT_SCALE_OBSERVER_KEY,
70
- (data: FontScaleConfig) => {
71
- if (data) setObserverFontScaleConfig(data);
72
- },
73
- );
74
- 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?.(
75
71
  FONT_SCALE_OBSERVER_KEY,
76
72
  (data: FontScaleConfig) => {
77
73
  setObserverFontScaleConfig(data ?? undefined);
@@ -86,7 +82,7 @@ const NavigationContainer: React.FC<NavigationContainerProps> = ({
86
82
  <SafeAreaProvider>
87
83
  <MiniAppContext.Provider value={mergedContext}>
88
84
  <ScaleSizeProvider
89
- fontScaleConfig={observerFontScaleConfig ?? mergedContext?.fontScaleConfig}
85
+ fontScaleConfig={observerFontScaleConfig}
90
86
  >
91
87
  <Navigation
92
88
  screen={screen}
@@ -6,7 +6,7 @@ const ScaleSizeProvider: FC<ScaleSizeProviderProps> = ({
6
6
  fontScaleConfig,
7
7
  children,
8
8
  }) => {
9
- // Kế thừa config từ tầng trên (vd app root) khi host không set qua MiniAppContext.
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: chứa cả flag OS lẫn rate user tự chỉnh.
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
- // rate user tự chỉnh: param override > config > 1 (không scale)
17
+ // user-adjusted rate: param override > config > 1 (no scaling)
18
18
  const customRate = userScaleRate ?? ctxRate ?? 1;
19
- // useOSFontScale bật -> lấy scale OS đè lên, ignore custom rate;
20
- // tắt -> dùng custom rate. Cap cứng MAX_FONT_SCALE (150%) cả hai.
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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@momo-kits/foundation",
3
- "version": "0.162.2-test.5",
3
+ "version": "0.162.2-test.8",
4
4
  "description": "React Native Component Kits",
5
5
  "main": "index.ts",
6
6
  "scripts": {},