@momo-kits/foundation 0.169.16 → 0.169.17-beta.1

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.
@@ -78,7 +78,7 @@ export const TabLabel: React.FC<{
78
78
  <MiniAppContext.Provider
79
79
  value={{
80
80
  ...context,
81
- fontScale: { useOSScaleRate: false, userScaleRate: 1 },
81
+ fontScale: { useOSScaleRate: false, appScaleRate: 1 },
82
82
  }}
83
83
  >
84
84
  <Text numberOfLines={1} typography={typography} color={color}>
@@ -6,6 +6,7 @@ import React, {
6
6
  useState,
7
7
  } from 'react';
8
8
  import {
9
+ StyleSheet,
9
10
  TextInput,
10
11
  TextInputFocusEvent,
11
12
  TouchableOpacity,
@@ -17,11 +18,12 @@ import {
17
18
  ComponentContext,
18
19
  MiniAppContext,
19
20
  } from '../Context';
21
+ import { Colors, Spacing, Styles } from '../Consts';
20
22
  import { Icon } from '../Icon';
21
- import { useScaleSize, exportFontFamily } from '../Text';
23
+ import { Image } from '../Image';
24
+ import { useScaleSize, Text, exportFontFamily } from '../Text';
22
25
  import { Typography } from '../Text/types';
23
26
  import { CLEAR_ICON_SIZE } from './constants';
24
- import { CountryCodeView } from './CountryCodeView';
25
27
  import { ErrorView } from './ErrorView';
26
28
  import { InputPhoneNumberProps } from './index';
27
29
  import { RenderTrailing } from './RenderTrailing';
@@ -34,13 +36,11 @@ const LARGE_FONT_SIZE = 18;
34
36
  const SMALL_DIVIDER_HEIGHT = 24;
35
37
  const LARGE_DIVIDER_HEIGHT = 32;
36
38
  const FOCUSED_BORDER_WIDTH = 1.5;
37
- const DEFAULT_COUNTRY_CODE = '+84';
38
- const DEFAULT_COUNTRY_FLAG =
39
- 'https://static.momocdn.net/app/img/icon/ic-qrcode-package/ic_vn_flag.png';
39
+ const FLAG_SIZE = 24;
40
40
 
41
41
  /**
42
- * Phone number input behind a country flag and dial code (Vietnam `+84` by
43
- * default), number pad by default, plus clear and trailing icons.
42
+ * Vietnamese phone number input with a fixed flag and `+84` prefix, number pad
43
+ * by default, plus clear and trailing icons.
44
44
  */
45
45
  const InputPhoneNumber = forwardRef(
46
46
  (
@@ -66,9 +66,6 @@ const InputPhoneNumber = forwardRef(
66
66
  editable = true,
67
67
  showClearIcon = true,
68
68
  defaultValue,
69
- countryCode = DEFAULT_COUNTRY_CODE,
70
- countryFlag = DEFAULT_COUNTRY_FLAG,
71
- onPressLeadingIcon,
72
69
  ...props
73
70
  }: InputPhoneNumberProps,
74
71
  ref,
@@ -185,16 +182,29 @@ const InputPhoneNumber = forwardRef(
185
182
  ]}
186
183
  >
187
184
  <View style={styles.inputView}>
188
- <CountryCodeView
189
- countryCode={countryCode}
190
- countryFlag={countryFlag}
191
- typography={typography}
192
- textColor={textColor}
193
- dividerHeight={dividerHeight}
194
- componentId={componentId}
195
- isDisabled={disabled || !editable}
196
- onPress={onPressLeadingIcon}
197
- />
185
+ <View style={[styles.leadingIconContainer, Styles.row]}>
186
+ <Image
187
+ source={{
188
+ uri: 'https://static.momocdn.net/app/img/icon/ic-qrcode-package/ic_vn_flag.png',
189
+ }}
190
+ style={innerStyle.iconFlag}
191
+ resizeMode="contain"
192
+ accessibilityLabel={`${componentId}|leading-icon`}
193
+ />
194
+ <View style={{ width: Spacing.XS }} />
195
+ <Text typography={typography} color={textColor}>
196
+ {'+84'}
197
+ </Text>
198
+ <View
199
+ style={[
200
+ styles.phoneNumberDivider,
201
+ {
202
+ height: dividerHeight,
203
+ backgroundColor: Colors.black_04,
204
+ },
205
+ ]}
206
+ />
207
+ </View>
198
208
  <SystemTextInput
199
209
  {...props}
200
210
  accessibilityLabel={`${componentId}`}
@@ -292,4 +302,12 @@ const InputPhoneNumber = forwardRef(
292
302
  },
293
303
  );
294
304
 
305
+ const innerStyle = StyleSheet.create({
306
+ iconFlag: {
307
+ width: FLAG_SIZE,
308
+ height: FLAG_SIZE,
309
+ marginHorizontal: Spacing.XXS,
310
+ },
311
+ });
312
+
295
313
  export default InputPhoneNumber;
package/Input/index.tsx CHANGED
@@ -351,22 +351,9 @@ export interface InputDropDownProps extends TouchableOpacityProps {
351
351
 
352
352
  export interface InputPhoneNumberProps extends InputProps {
353
353
  /**
354
- * Optional. Dial code shown verbatim before the number.
355
- * Defaults to `+84` if not provided.
354
+ * Optional. Currently unused: the displayed prefix is always `+84`.
356
355
  */
357
356
  countryCode?: string;
358
-
359
- /**
360
- * Optional. URL of the flag image shown before the dial code.
361
- * Defaults to the Vietnam flag if not provided.
362
- */
363
- countryFlag?: string;
364
-
365
- /**
366
- * Optional. Called when the flag or dial code is pressed (e.g. to pick a country),
367
- * which then reads as a button. Ignored while `disabled` or `editable={false}`.
368
- */
369
- onPressLeadingIcon?: () => void;
370
357
  }
371
358
 
372
359
  export type InputRef = {
package/Text/utils.ts CHANGED
@@ -5,24 +5,50 @@ import { MiniAppContext } from '../Context';
5
5
  const DEFAULT_SCREEN_SIZE = 375;
6
6
  const MAX_FONT_SCALE = 1.5;
7
7
  const MAX_DEVICE_SCALE = 5;
8
+ const APP_SCALE_LEVELS = [1, 1.2, 1.3, 1.4];
8
9
 
9
10
  type MiniAppScale = {
10
11
  scaleSizeMaxRate?: number;
11
- fontScale?: { useOSScaleRate?: boolean; userScaleRate?: number };
12
+ fontScale?: {
13
+ useOSScaleRate?: boolean;
14
+ appScaleRate?: number;
15
+ /** @deprecated Use `appScaleRate`. Still sent by the host. */
16
+ userScaleRate?: number;
17
+ };
18
+ };
19
+
20
+ /**
21
+ * Snaps a host scale rate to the nearest app scale level (1, 1.2, 1.3, 1.4),
22
+ * ties going lower, so legacy rates (1.1, 1.6) resolve like the host does.
23
+ */
24
+ const toAppScaleRate = (rate?: number) => {
25
+ if (!rate) {
26
+ return APP_SCALE_LEVELS[0];
27
+ }
28
+ const percent = Math.round(rate * 100);
29
+ const distance = (level: number) =>
30
+ Math.abs(Math.round(level * 100) - percent);
31
+ return APP_SCALE_LEVELS.reduce((best, level) =>
32
+ distance(level) < distance(best) ? level : best,
33
+ );
12
34
  };
13
35
 
14
36
  /**
15
37
  * Scales `size` by screen width (+5 max) and OS font scale (max `scaleRate`,
16
38
  * else the ScaleSizeProvider rate, else 1.5), taking the larger, or by the mini
17
- * app `fontScale.userScaleRate`; a provider rate caps both at `size × rate`.
39
+ * app `fontScale.appScaleRate`; a provider rate caps both at `size × rate`.
18
40
  */
19
41
  const useScaleSize = (size: number, scaleRate?: number) => {
20
42
  const { width } = useWindowDimensions();
21
43
  const context = useContext<MiniAppScale | undefined>(MiniAppContext);
22
44
  const scaleSizeMaxRate = context?.scaleSizeMaxRate;
23
45
  const maxSize = scaleSizeMaxRate ? size * scaleSizeMaxRate : Infinity;
24
- if (context?.fontScale?.useOSScaleRate === false) {
25
- return Math.min(size * (context.fontScale.userScaleRate ?? 1), maxSize);
46
+ const appScale = context?.fontScale;
47
+ if (appScale?.useOSScaleRate === false) {
48
+ const rate = toAppScaleRate(
49
+ appScale.appScaleRate ?? appScale.userScaleRate,
50
+ );
51
+ return Math.min(size * rate, maxSize);
26
52
  }
27
53
  const fontScale = PixelRatio.getFontScale();
28
54
  const deviceScale = width / DEFAULT_SCREEN_SIZE;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@momo-kits/foundation",
3
- "version": "0.169.16",
3
+ "version": "0.169.17-beta.1",
4
4
  "description": "React Native Component Kits",
5
5
  "main": "index.ts",
6
6
  "scripts": {},
@@ -1,93 +0,0 @@
1
- import React from 'react';
2
- import { StyleSheet, TouchableOpacity, View } from 'react-native';
3
- import { Colors, Spacing, Styles } from '../Consts';
4
- import { Image } from '../Image';
5
- import { Text } from '../Text';
6
- import { Typography } from '../Text/types';
7
- import styles from './styles';
8
-
9
- const FLAG_SIZE = 24;
10
-
11
- type CountryCodeViewProps = {
12
- countryCode: string;
13
- countryFlag: string;
14
- typography: Typography;
15
- textColor: string;
16
- dividerHeight: number;
17
- componentId: string;
18
- isDisabled: boolean;
19
- onPress?: () => void;
20
- };
21
-
22
- /**
23
- * Flag, dial code and divider ahead of a phone number. Only becomes a button
24
- * when `onPress` is given, so the default render stays a plain view.
25
- */
26
- const CountryCodeView: React.FC<CountryCodeViewProps> = ({
27
- countryCode,
28
- countryFlag,
29
- typography,
30
- textColor,
31
- dividerHeight,
32
- componentId,
33
- isDisabled,
34
- onPress,
35
- }) => {
36
- const content = (
37
- <>
38
- <Image
39
- source={{ uri: countryFlag }}
40
- style={innerStyle.iconFlag}
41
- resizeMode="contain"
42
- accessibilityLabel={`${componentId}|leading-icon`}
43
- />
44
- <View style={{ width: Spacing.XS }} />
45
- <Text typography={typography} color={textColor}>
46
- {countryCode}
47
- </Text>
48
- </>
49
- );
50
-
51
- const renderContent = () => {
52
- if (!onPress) {
53
- return content;
54
- }
55
- return (
56
- <TouchableOpacity
57
- style={Styles.row}
58
- onPress={onPress}
59
- disabled={isDisabled}
60
- accessibilityRole="button"
61
- accessibilityLabel={`${componentId}|leading-icon-touch|${countryCode}`}
62
- accessibilityState={{ disabled: isDisabled }}
63
- >
64
- {content}
65
- </TouchableOpacity>
66
- );
67
- };
68
-
69
- return (
70
- <View style={[styles.leadingIconContainer, Styles.row]}>
71
- {renderContent()}
72
- <View
73
- style={[
74
- styles.phoneNumberDivider,
75
- {
76
- height: dividerHeight,
77
- backgroundColor: Colors.black_04,
78
- },
79
- ]}
80
- />
81
- </View>
82
- );
83
- };
84
-
85
- const innerStyle = StyleSheet.create({
86
- iconFlag: {
87
- width: FLAG_SIZE,
88
- height: FLAG_SIZE,
89
- marginHorizontal: Spacing.XXS,
90
- },
91
- });
92
-
93
- export { CountryCodeView };