@momo-kits/foundation 0.169.16-beta.21 → 0.169.16-beta.22

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/Icon/index.tsx CHANGED
@@ -6,10 +6,12 @@ import { ApplicationContext, MiniAppContext } from '../Context';
6
6
  import { Image } from '../Image';
7
7
  import { StyleSheet } from 'react-native';
8
8
  import { Colors } from '../Consts';
9
+ import { getIconSource, IconNewSources } from './utils';
9
10
 
10
11
  /**
11
12
  * Tinted icon from the bundled icon map (unknown names fall back to
12
- * `ic_warning`) or from a URL. `color={null}` keeps the image's own colors.
13
+ * `ic_warning`) or from a URL; the new icon set wins over the old one.
14
+ * `color={null}` keeps the image's own colors.
13
15
  */
14
16
  const Icon: React.FC<IconProps> = ({
15
17
  source = 'ic_back',
@@ -23,14 +25,6 @@ const Icon: React.FC<IconProps> = ({
23
25
 
24
26
  const showBaseLineDebug = context?.features?.showBaseLineDebug ?? false;
25
27
 
26
- const getIconSource = (): any => {
27
- if (source && !source.includes('http')) {
28
- let icon: { [key: string]: { uri: string } } = IconSources;
29
- return icon[source] ?? icon.ic_warning;
30
- }
31
- return { uri: source };
32
- };
33
-
34
28
  const tintColor = color ?? theme.colors.text.default;
35
29
  const tintColorProps = color !== null && { tintColor };
36
30
 
@@ -38,7 +32,7 @@ const Icon: React.FC<IconProps> = ({
38
32
  <Image
39
33
  {...props}
40
34
  loading={false}
41
- source={getIconSource()}
35
+ source={getIconSource(source, size)}
42
36
  style={[
43
37
  style,
44
38
  { width: size, height: size },
@@ -54,4 +48,4 @@ const styles = StyleSheet.create({
54
48
  debugBaseLine: { borderWidth: 1, borderColor: Colors.green_06 },
55
49
  });
56
50
 
57
- export { Icon, IconSources, IconBankSources };
51
+ export { Icon, IconSources, IconBankSources, IconNewSources };
package/Icon/utils.ts ADDED
@@ -0,0 +1,43 @@
1
+ import IconSources from '../Assets/icon.json';
2
+ import IconNewSources from '../Assets/icon_new.json';
3
+ import IconDeprecated from '../Assets/icon_deprecated.json';
4
+
5
+ type IconMap = { [key: string]: { uri: string } };
6
+
7
+ const OLD_ICONS: IconMap = IconSources;
8
+ const NEW_ICONS: IconMap = IconNewSources;
9
+ const DEPRECATED_ICONS: { [key: string]: string } = IconDeprecated;
10
+ const FALLBACK_ICON = 'ic_warning';
11
+
12
+ const warnedKeys = new Set<string>();
13
+
14
+ /**
15
+ * Warns once per key in dev when a deprecated icon name is used, pointing to
16
+ * its replacement in the new icon set.
17
+ */
18
+ const warnDeprecatedIcon = (source: string) => {
19
+ const replacement = DEPRECATED_ICONS[source];
20
+ if (!__DEV__ || !replacement || warnedKeys.has(source)) {
21
+ return;
22
+ }
23
+ warnedKeys.add(source);
24
+ console.warn(
25
+ `[@momo-kits] Icon "${source}" is deprecated, use "${replacement}" instead.`,
26
+ );
27
+ };
28
+
29
+ /**
30
+ * Resolves an icon name or URL to an image source. Lookup order: new set at
31
+ * the requested size, new set, old set, then `ic_warning`.
32
+ */
33
+ const getIconSource = (source: string, size?: number): { uri: string } => {
34
+ if (!source || source.includes('http')) {
35
+ return { uri: source };
36
+ }
37
+ warnDeprecatedIcon(source);
38
+ const sizedIcon = NEW_ICONS[`${size}_${source}`];
39
+ const icon = sizedIcon ?? NEW_ICONS[source] ?? OLD_ICONS[source];
40
+ return icon ?? OLD_ICONS[FALLBACK_ICON];
41
+ };
42
+
43
+ export { getIconSource, IconNewSources };
@@ -45,7 +45,7 @@ const ErrorView: FC<ErrorViewProps> = ({
45
45
  color={messageColor}
46
46
  typography={'description_default_regular'}
47
47
  >
48
- {errorMessage || hintTextDefault}
48
+ {errorMessage ?? hintTextDefault}
49
49
  </Text>
50
50
  </View>
51
51
  );
@@ -53,8 +53,8 @@ type InputMoneyViewProps = Pick<
53
53
  };
54
54
 
55
55
  /**
56
- * Presentational body of InputMoney: bordered field, currency suffix (shown
57
- * once there is a value) and the clear/trailing icons.
56
+ * Presentational body of InputMoney: bordered field, currency suffix (kept
57
+ * after a placeholder that ends with it) and the clear/trailing icons.
58
58
  */
59
59
  export const InputMoneyView = ({
60
60
  size,
@@ -101,8 +101,13 @@ export const InputMoneyView = ({
101
101
  fontSize: scaledFontSize,
102
102
  fontFamily: inputFontFamily,
103
103
  };
104
- const hasValue = displayValue.length > 0;
104
+ const hasCurrencyInPlaceholder = placeholder.endsWith(currency);
105
+ const shouldShowCurrency = !!displayValue || hasCurrencyInPlaceholder;
105
106
  const shouldShowClearIcon = !!(showClearIcon && focused && displayValue);
107
+ let inputPlaceholder = placeholder;
108
+ if (hasCurrencyInPlaceholder) {
109
+ inputPlaceholder = placeholder.slice(0, -currency.length);
110
+ }
106
111
  return (
107
112
  <View
108
113
  style={[
@@ -143,15 +148,18 @@ export const InputMoneyView = ({
143
148
  onChangeText={onChangeText}
144
149
  onFocus={onFocus}
145
150
  onBlur={onBlur}
146
- placeholder={placeholder}
151
+ placeholder={inputPlaceholder}
147
152
  selectionColor={theme.colors.primary}
148
153
  placeholderTextColor={placeholderColor}
149
154
  keyboardType={'numeric'}
150
155
  maxLength={undefined}
151
156
  />
152
- {hasValue && (
157
+ {shouldShowCurrency && (
153
158
  <Text
154
- style={[textStyle, { color: textColor }]}
159
+ style={[
160
+ textStyle,
161
+ { color: displayValue ? textColor : placeholderColor },
162
+ ]}
155
163
  allowFontScaling={false}
156
164
  >
157
165
  {currency}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@momo-kits/foundation",
3
- "version": "0.169.16-beta.21",
3
+ "version": "0.169.16-beta.22",
4
4
  "description": "React Native Component Kits",
5
5
  "main": "index.ts",
6
6
  "scripts": {},