@momo-kits/foundation 0.168.1-beta.7 → 0.168.1-beta.9

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.
@@ -37,8 +37,6 @@ import SystemTextInput from './SystemTextInput';
37
37
 
38
38
  const moneyFormatter = new Intl.NumberFormat('vi-VN');
39
39
 
40
- // Finds the common prefix and suffix of `old` and `text`; `size` counts the
41
- // characters removed plus inserted between them.
42
40
  const findEdit = (old: string, text: string) => {
43
41
  let start = 0;
44
42
  while (start < text.length && old[start] === text[start]) {
@@ -129,11 +127,8 @@ const InputMoney = forwardRef(
129
127
  setLastDisplayValue(displayValue);
130
128
  }, [displayValue]);
131
129
 
132
- // The selection only rides along with the render that reformats the text,
133
- // then it is released so the user can move the caret freely.
134
130
  useEffect(() => {
135
131
  if (!caretSelection) return;
136
- // A newer keystroke may already have queued its own selection; keep it.
137
132
  setCaretSelection(current =>
138
133
  current === caretSelection ? undefined : current,
139
134
  );
@@ -143,9 +138,6 @@ const InputMoney = forwardRef(
143
138
  const next = numeric ? moneyFormatter.format(Number(numeric)) : '';
144
139
  setDisplayValue(next);
145
140
 
146
- // Android moves the caret proportionally when the text is replaced, so
147
- // it lands before the typed digit once a separator is added. Send the
148
- // caret together with the text, keeping the same digits after it.
149
141
  const digitsAfter = caretDigitsAfter.current;
150
142
  caretDigitsAfter.current = undefined;
151
143
  if (Platform.OS !== 'android' || digitsAfter === undefined) return;
@@ -187,9 +179,6 @@ const InputMoney = forwardRef(
187
179
  return;
188
180
  }
189
181
  const digits = parseInputText(text);
190
- // When typing outpaces JS (slow devices) native rejects the stale
191
- // formatted text and keeps the raw one, so the edit may apply to either.
192
- // Pick the one that differs from the new text by a single edit.
193
182
  const raw = lastRawText.current;
194
183
  lastRawText.current = text;
195
184
  const formattedEdit = findEdit(lastDisplayValue, text);
@@ -199,7 +188,6 @@ const InputMoney = forwardRef(
199
188
  caretDigitsAfter.current = parseInputText(
200
189
  text.slice(text.length - suffix),
201
190
  ).length;
202
- // Deleting a separator removes the digit before it.
203
191
  if (text.length < old.length && digits === numericValue) {
204
192
  const index = parseInputText(text.slice(0, start)).length - 1;
205
193
  if (index >= 0) {
@@ -210,6 +198,11 @@ const InputMoney = forwardRef(
210
198
  updateNumericValue(digits);
211
199
  };
212
200
 
201
+ const focusAtEnd = () => {
202
+ inputRef.current?.focus();
203
+ inputRef.current?.setSelection(displayValue.length, displayValue.length);
204
+ };
205
+
213
206
  const _onFocus = (e: TextInputFocusEvent) => {
214
207
  setFocused(true);
215
208
  onFocus?.(e);
@@ -279,7 +272,7 @@ const InputMoney = forwardRef(
279
272
  />
280
273
  <Pressable
281
274
  style={[styles.inputView, styles.moneyInputView]}
282
- onPress={() => inputRef.current?.focus()}
275
+ onPress={focusAtEnd}
283
276
  disabled={disabled}
284
277
  >
285
278
  <SystemTextInput
@@ -291,8 +284,6 @@ const InputMoney = forwardRef(
291
284
  disabled: disabled,
292
285
  ...props.accessibilityState,
293
286
  }}
294
- // No width: the input sizes to its text natively, so the
295
- // currency follows it without waiting for JS.
296
287
  style={[textStyle, styles.moneyTextInput, { color: textColor }]}
297
288
  allowFontScaling={false}
298
289
  textBreakStrategy="highQuality"
package/Input/styles.ts CHANGED
@@ -223,9 +223,8 @@ export default StyleSheet.create({
223
223
  },
224
224
  moneyTextInput: {
225
225
  flexShrink: 1,
226
- height: '100%',
227
226
  paddingLeft: 0,
228
227
  paddingRight: Spacing.XXS,
229
- paddingVertical: Spacing.S,
228
+ paddingVertical: 0,
230
229
  },
231
230
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@momo-kits/foundation",
3
- "version": "0.168.1-beta.7",
3
+ "version": "0.168.1-beta.9",
4
4
  "description": "React Native Component Kits",
5
5
  "main": "index.ts",
6
6
  "scripts": {},