@momo-kits/foundation 0.162.2-beta.2 → 0.162.2-beta.21

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.
@@ -19,7 +19,7 @@ import Navigator from './Navigator';
19
19
  import ScaleSizeProvider from './ScaleSizeProvider';
20
20
  import { getModalOptions, getStackOptions } from './utils';
21
21
  import { NavigationContainerProps } from './types';
22
- import { ApplicationContext, FontScaleConfig, MiniAppContext } from '../Context';
22
+ import { ApplicationContext, MiniAppContext } from '../Context';
23
23
  import Localize from './Localize';
24
24
  import { Colors, defaultTheme } from '../Consts';
25
25
  import { HeaderLeft } from './Components/HeaderLeft';
@@ -29,8 +29,6 @@ import { HeaderBackground } from './Components/HeaderBackground';
29
29
 
30
30
  const Stack = createStackNavigator();
31
31
 
32
- const FONT_SCALE_OBSERVER_KEY = 'font_scale_config';
33
-
34
32
  const NavigationContainer: React.FC<NavigationContainerProps> = ({
35
33
  screen,
36
34
  theme = defaultTheme,
@@ -47,9 +45,13 @@ const NavigationContainer: React.FC<NavigationContainerProps> = ({
47
45
  }) => {
48
46
  const context = useContext<any>(MiniAppContext);
49
47
  const [currentContext, setCurrentContext] = useState<any>({});
50
- const [observerFontScaleConfig, setObserverFontScaleConfig] = useState<
51
- FontScaleConfig | undefined
52
- >(context?.fontScaleConfig);
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]);
53
55
 
54
56
  const mergedContext = {
55
57
  ...context,
@@ -60,24 +62,10 @@ const NavigationContainer: React.FC<NavigationContainerProps> = ({
60
62
  },
61
63
  };
62
64
 
63
- useEffect(() => {
64
- const sub = maxApi?.observer?.(
65
- FONT_SCALE_OBSERVER_KEY,
66
- (data: FontScaleConfig) => {
67
- setObserverFontScaleConfig(data ?? undefined);
68
- },
69
- );
70
- return () => {
71
- sub?.remove?.();
72
- };
73
- }, [maxApi]);
74
-
75
65
  return (
76
66
  <SafeAreaProvider>
77
67
  <MiniAppContext.Provider value={mergedContext}>
78
- <ScaleSizeProvider
79
- fontScaleConfig={observerFontScaleConfig}
80
- >
68
+ <ScaleSizeProvider scaleSizeMaxRate={mergedContext?.scaleSizeMaxRate}>
81
69
  <Navigation
82
70
  screen={screen}
83
71
  theme={theme}
@@ -1,15 +1,14 @@
1
- import React, { FC, useContext } from 'react';
1
+ 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
- fontScaleConfig,
7
+ scaleSizeMaxRate,
7
8
  children,
8
9
  }) => {
9
- // Inherit the config from an upper layer (e.g. app root) when the host doesn't set it via MiniAppContext.
10
- const parent = useContext(ScaleSizeContext);
11
10
  return (
12
- <ScaleSizeContext.Provider value={fontScaleConfig ?? parent}>
11
+ <ScaleSizeContext.Provider value={{ scaleSizeMaxRate }}>
13
12
  {children}
14
13
  </ScaleSizeContext.Provider>
15
14
  );
@@ -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
 
@@ -78,7 +85,7 @@ const WidgetContainer: React.FC<WidgetContainerProps> = ({
78
85
  <SafeAreaProvider>
79
86
  <MiniAppContext.Provider value={mergedContext}>
80
87
  <ScaleSizeProvider
81
- fontScaleConfig={mergedContext?.fontScaleConfig}
88
+ scaleSizeMaxRate={mergedContext?.scaleSizeMaxRate}
82
89
  >
83
90
  <ApplicationContext.Provider
84
91
  value={{
@@ -10,7 +10,6 @@ import {
10
10
  import type { SharedValue } from 'react-native-reanimated';
11
11
  import { PopupNotifyProps } from '../Popup/types';
12
12
  import { InputRef, InputSearchProps } from '../Input';
13
- import { FontScaleConfig } from '../Context';
14
13
  import Navigation from './Navigation';
15
14
 
16
15
  export type NavigationProps = {
@@ -110,7 +109,7 @@ export type Theme = {
110
109
  };
111
110
 
112
111
  export type ScaleSizeProviderProps = {
113
- fontScaleConfig?: FontScaleConfig;
112
+ scaleSizeMaxRate?: number;
114
113
  children: ViewProps['children'];
115
114
  };
116
115
 
package/Context/index.ts CHANGED
@@ -9,12 +9,10 @@ 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: holds both the OS flag and the user-adjusted rate.
13
- export type FontScaleConfig = {
14
- useOSFontScale?: boolean;
15
- userScaleRate?: number;
16
- };
17
- const ScaleSizeContext = createContext<FontScaleConfig>({});
12
+ /** @deprecated Max font scale is fixed at 1.5; this context is no longer read. */
13
+ const ScaleSizeContext = createContext<{ scaleSizeMaxRate?: number }>({
14
+ scaleSizeMaxRate: undefined,
15
+ });
18
16
  const TrackingScopeContext = createContext<{ scopeName?: string }>({
19
17
  scopeName: undefined,
20
18
  });
package/Input/Input.tsx CHANGED
@@ -77,7 +77,8 @@ const Input = forwardRef(
77
77
  const scaledFontSize = useScaleSize(14);
78
78
  const scaleHeight = useScaleSize(size === 'small' ? 48 : 56);
79
79
  const [focused, setFocused] = useState(false);
80
- const haveValue = !!value || !!defaultValue;
80
+ const [internalText, setInternalText] = useState(defaultValue || '');
81
+ const haveValue = value !== undefined ? !!value : !!internalText;
81
82
  const inputRef = useRef<TextInput | null>(null);
82
83
  const componentName = 'Input';
83
84
 
@@ -95,6 +96,9 @@ const Input = forwardRef(
95
96
  };
96
97
 
97
98
  const _onChangeText = (text: string) => {
99
+ if (value === undefined) {
100
+ setInternalText(text);
101
+ }
98
102
  onChangeText?.(text);
99
103
  };
100
104
 
@@ -109,6 +113,13 @@ const Input = forwardRef(
109
113
  };
110
114
 
111
115
  const _setText = (text: string) => {
116
+ if (__DEV__ && value !== undefined) {
117
+ console.error(
118
+ `${componentName}: calling ref.setText() on a controlled input (\`value\` is provided) is an anti-pattern. ` +
119
+ 'It creates two sources of truth: setText will be overridden by React on the next render. ' +
120
+ 'Update the state behind `value` instead.',
121
+ );
122
+ }
112
123
  inputRef?.current?.setNativeProps({ text });
113
124
  _onChangeText(text);
114
125
  };
@@ -69,7 +69,8 @@ const InputPhoneNumber = forwardRef(
69
69
  const context = useContext<any>(MiniAppContext);
70
70
  const scaleHeight = useScaleSize(size === 'small' ? 48 : 56);
71
71
  const [focused, setFocused] = useState(false);
72
- const haveValue = !!value || !!defaultValue;
72
+ const [internalText, setInternalText] = useState(defaultValue || '');
73
+ const haveValue = value !== undefined ? !!value : !!internalText;
73
74
  const inputRef = useRef<TextInput | null>(null);
74
75
  const componentName = 'InputPhoneNumber';
75
76
 
@@ -86,6 +87,9 @@ const InputPhoneNumber = forwardRef(
86
87
  };
87
88
 
88
89
  const _onChangeText = (text: string) => {
90
+ if (value === undefined) {
91
+ setInternalText(text);
92
+ }
89
93
  onChangeText?.(text);
90
94
  };
91
95
 
@@ -100,6 +104,13 @@ const InputPhoneNumber = forwardRef(
100
104
  };
101
105
 
102
106
  const _setText = (text: string) => {
107
+ if (__DEV__ && value !== undefined) {
108
+ console.error(
109
+ `${componentName}: calling ref.setText() on a controlled input (\`value\` is provided) is an anti-pattern. ` +
110
+ 'It creates two sources of truth: setText will be overridden by React on the next render. ' +
111
+ 'Update the state behind `value` instead.',
112
+ );
113
+ }
103
114
  inputRef?.current?.setNativeProps({ text });
104
115
  _onChangeText(text);
105
116
  };
package/Layout/Screen.tsx CHANGED
@@ -650,7 +650,14 @@ const Screen = forwardRef(
650
650
  onScroll={handleScroll}
651
651
  onScrollEndDrag={handleScrollEnd}
652
652
  scrollEventThrottle={16}
653
- style={Styles.flex}
653
+ style={[
654
+ Styles.flex,
655
+ !scrollable && !Footer && !isTab && { paddingBottom: bottomInset },
656
+ ]}
657
+ contentContainerStyle={[
658
+ scrollable && !Footer && !isTab && { paddingBottom: bottomInset },
659
+ scrollViewProps?.contentContainerStyle,
660
+ ]}
654
661
  >
655
662
  {renderAnimatedHeader()}
656
663
 
package/Text/utils.ts CHANGED
@@ -1,24 +1,22 @@
1
1
  import { Dimensions, PixelRatio, useWindowDimensions } from 'react-native';
2
2
  import { useContext } from 'react';
3
- import { ScaleSizeContext } from '../Context';
3
+ import { MiniAppContext } from '../Context';
4
4
 
5
5
  const deviceWidth = Dimensions.get('window').width;
6
6
  const DEFAULT_SCREEN_SIZE = 375;
7
7
  const MAX_FONT_SCALE = 1.5;
8
8
  const MAX_DEVICE_SCALE = 5;
9
9
 
10
- const useScaleSize = (size: number, userScaleRate?: number) => {
11
- const { useOSFontScale = true, userScaleRate: ctxRate } =
12
- useContext(ScaleSizeContext);
10
+ const useScaleSize = (size: number, scaleRate?: number) => {
11
+ const context = useContext<any>(MiniAppContext);
12
+ if (context?.fontScale?.useOSScaleRate === false) {
13
+ return size * (context.fontScale.userScaleRate ?? 1);
14
+ }
13
15
  const fontScale = PixelRatio.getFontScale();
14
16
  const { width } = useWindowDimensions();
15
17
  const deviceScale = width / DEFAULT_SCREEN_SIZE;
16
18
 
17
- const customRate = userScaleRate ?? ctxRate ?? 1;
18
-
19
- if (!useOSFontScale) {
20
- return customRate > 1 ? customRate * size : size;
21
- }
19
+ const maxScaleRate = scaleRate ?? MAX_FONT_SCALE;
22
20
 
23
21
  let fontSizeDeviceScale = size;
24
22
  let fontSizeOSScale = size;
@@ -32,8 +30,8 @@ const useScaleSize = (size: number, userScaleRate?: number) => {
32
30
 
33
31
  if (fontScale > 1) {
34
32
  fontSizeOSScale = Math.min(
35
- fontScale * fontSizeOSScale,
36
- fontSizeOSScale * MAX_FONT_SCALE,
33
+ fontSizeOSScale * fontScale,
34
+ fontSizeOSScale * maxScaleRate,
37
35
  );
38
36
  }
39
37
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@momo-kits/foundation",
3
- "version": "0.162.2-beta.2",
3
+ "version": "0.162.2-beta.21",
4
4
  "description": "React Native Component Kits",
5
5
  "main": "index.ts",
6
6
  "scripts": {},
@@ -8,7 +8,7 @@
8
8
  "@momo-kits/foundation"
9
9
  ],
10
10
  "dependencies": {
11
- "react-native-fast-image": "git+https://oauth2:TGi6oBj-LdzsKpLXQSoH@gitlab.mservice.com.vn/momo-platform/public/react-native-fast-image.git#v8.11.0",
11
+ "react-native-fast-image": "git+https://oauth2:k_r5y_gV6sX9-TqQxgcd@gitlab.mservice.com.vn/momo-platform/public/react-native-fast-image.git#v8.11.0",
12
12
  "@react-navigation/bottom-tabs": "7.4.2",
13
13
  "@react-navigation/core": "7.12.1",
14
14
  "@react-navigation/elements": "2.5.2",
@@ -16,7 +16,7 @@
16
16
  "@react-navigation/routers": "7.4.1",
17
17
  "@react-navigation/stack": "7.4.2",
18
18
  "react-native-gesture-handler": "2.27.1",
19
- "react-native-linear-gradient": "git+https://oauth2:TGi6oBj-LdzsKpLXQSoH@gitlab.mservice.com.vn/momo-platform/public/react-native-linear-gradient#v3.0.0",
19
+ "react-native-linear-gradient": "git+https://oauth2:k_r5y_gV6sX9-TqQxgcd@gitlab.mservice.com.vn/momo-platform/public/react-native-linear-gradient#v3.0.0",
20
20
  "react-native-reanimated": "4.2.2",
21
21
  "react-native-safe-area-context": "5.5.2",
22
22
  "@shopify/flash-list": "2.1.0",