@momo-kits/foundation 0.162.1-beta.1 → 0.162.1-beta.3
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.
- package/Application/NavigationContainer.tsx +24 -1
- package/Input/Input.tsx +12 -1
- package/Input/InputPhoneNumber.tsx +12 -1
- package/Layout/Screen.tsx +8 -1
- package/package.json +1 -1
|
@@ -31,6 +31,27 @@ const Stack = createStackNavigator();
|
|
|
31
31
|
|
|
32
32
|
const FONT_SCALE_OBSERVER_KEY = 'font_scale_config';
|
|
33
33
|
|
|
34
|
+
// AI-GENERATED START: parse the font_scale_config first-frame seed read straight from async storage (string | {response} | object)
|
|
35
|
+
const parseSeedFontScaleConfig = (raw: any): FontScaleConfig | undefined => {
|
|
36
|
+
let data = raw;
|
|
37
|
+
if (typeof data === 'string') {
|
|
38
|
+
try {
|
|
39
|
+
data = JSON.parse(data);
|
|
40
|
+
} catch {
|
|
41
|
+
return undefined;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
data = data?.response ?? data;
|
|
45
|
+
if (!data || (data.useOSFontScale === undefined && data.userScaleRate === undefined)) {
|
|
46
|
+
return undefined;
|
|
47
|
+
}
|
|
48
|
+
return {
|
|
49
|
+
useOSFontScale: data.useOSFontScale,
|
|
50
|
+
userScaleRate: data.userScaleRate,
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
// AI-GENERATED END: parse the font_scale_config first-frame seed read straight from async storage (string | {response} | object)
|
|
54
|
+
|
|
34
55
|
const NavigationContainer: React.FC<NavigationContainerProps> = ({
|
|
35
56
|
screen,
|
|
36
57
|
theme = defaultTheme,
|
|
@@ -47,9 +68,11 @@ const NavigationContainer: React.FC<NavigationContainerProps> = ({
|
|
|
47
68
|
}) => {
|
|
48
69
|
const context = useContext<any>(MiniAppContext);
|
|
49
70
|
const [currentContext, setCurrentContext] = useState<any>({});
|
|
71
|
+
// AI-GENERATED START: self-seed first-frame font scale by reading font_scale_config straight from async storage
|
|
50
72
|
const [observerFontScaleConfig, setObserverFontScaleConfig] = useState<
|
|
51
73
|
FontScaleConfig | undefined
|
|
52
|
-
>(context?.fontScaleConfig);
|
|
74
|
+
>(() => parseSeedFontScaleConfig(maxApi?.getItem?.(FONT_SCALE_OBSERVER_KEY)) ?? context?.fontScaleConfig);
|
|
75
|
+
// AI-GENERATED END: self-seed first-frame font scale by reading font_scale_config straight from async storage
|
|
53
76
|
|
|
54
77
|
const mergedContext = {
|
|
55
78
|
...context,
|
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
|
|
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
|
|
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={
|
|
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
|
|