@hero-design/rn 8.64.7 → 8.64.8-alpha.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.
package/es/index.js CHANGED
@@ -6,6 +6,7 @@ import { createIconSet } from 'react-native-vector-icons';
6
6
  import { useSafeAreaInsets } from 'react-native-safe-area-context';
7
7
  import { MonthYearPickerViewIOS, MonthYearPickerDialogueAndroid } from '@hero-design/react-native-month-year-picker';
8
8
  import DateTimePicker from '@react-native-community/datetimepicker';
9
+ import Clipboard from '@react-native-clipboard/clipboard';
9
10
  import RnSlider from '@react-native-community/slider';
10
11
  import { RectButton, GestureHandlerRootView, Swipeable as Swipeable$1 } from 'react-native-gesture-handler';
11
12
  import LinearGradient from 'react-native-linear-gradient';
@@ -371,6 +372,36 @@ function _typeof(o) {
371
372
  return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
372
373
  }, _typeof(o);
373
374
  }
375
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
376
+ try {
377
+ var info = gen[key](arg);
378
+ var value = info.value;
379
+ } catch (error) {
380
+ reject(error);
381
+ return;
382
+ }
383
+ if (info.done) {
384
+ resolve(value);
385
+ } else {
386
+ Promise.resolve(value).then(_next, _throw);
387
+ }
388
+ }
389
+ function _asyncToGenerator(fn) {
390
+ return function () {
391
+ var self = this,
392
+ args = arguments;
393
+ return new Promise(function (resolve, reject) {
394
+ var gen = fn.apply(self, args);
395
+ function _next(value) {
396
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
397
+ }
398
+ function _throw(err) {
399
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
400
+ }
401
+ _next(undefined);
402
+ });
403
+ };
404
+ }
374
405
  function _classCallCheck(instance, Constructor) {
375
406
  if (!(instance instanceof Constructor)) {
376
407
  throw new TypeError("Cannot call a class as a function");
@@ -15616,10 +15647,6 @@ var PinInput = /*#__PURE__*/forwardRef(function (_ref2, ref) {
15616
15647
  });
15617
15648
  var trimmedValue = normalizeValue(value, length);
15618
15649
  var maskedValueWithExtraSpace = Platform.OS === 'android' && !trimmedValue ? '*' : trimmedValue;
15619
- var _useState3 = useState(false),
15620
- _useState4 = _slicedToArray(_useState3, 2),
15621
- hasFulfilled = _useState4[0],
15622
- setHasFulfilled = _useState4[1];
15623
15650
  var focus = useCallback(function () {
15624
15651
  if (inputRef !== null && inputRef !== void 0 && inputRef.current) {
15625
15652
  inputRef.current.focus();
@@ -15633,22 +15660,13 @@ var PinInput = /*#__PURE__*/forwardRef(function (_ref2, ref) {
15633
15660
  }
15634
15661
  }, []);
15635
15662
  var changeText = useCallback(function (text) {
15636
- // If the input is already fulfilled and the user tries to remove characters
15637
- if (hasFulfilled && text.length < length) {
15638
- setHasFulfilled(false);
15639
- }
15640
- // If the input is already fulfilled and the user tries to add more characters
15641
- if (hasFulfilled && ((text === null || text === void 0 ? void 0 : text.match(/\d/g)) || []).join('').length > length) {
15642
- return;
15643
- }
15644
15663
  // Prevent user from entering more than the length
15645
15664
  var trimmedPin = normalizeValue(text, length);
15646
15665
  onChangeText === null || onChangeText === void 0 || onChangeText(trimmedPin);
15647
15666
  if (trimmedPin.length === length) {
15648
15667
  onFulfill === null || onFulfill === void 0 || onFulfill(trimmedPin);
15649
- setHasFulfilled(true);
15650
15668
  }
15651
- }, [length, onChangeText, onFulfill, hasFulfilled]);
15669
+ }, [length, onChangeText, onFulfill]);
15652
15670
  useEffect(function () {
15653
15671
  // Must run after animations for keyboard to automatically open
15654
15672
  if (autoFocus) {
@@ -15661,6 +15679,35 @@ var PinInput = /*#__PURE__*/forwardRef(function (_ref2, ref) {
15661
15679
  blur: blur
15662
15680
  };
15663
15681
  });
15682
+ useEffect(function () {
15683
+ var autoFillInterval = setInterval( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
15684
+ var clipboardContent, canAutoFill, isValidClipboardContent;
15685
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
15686
+ while (1) switch (_context.prev = _context.next) {
15687
+ case 0:
15688
+ if (!(Platform.OS === 'android')) {
15689
+ _context.next = 7;
15690
+ break;
15691
+ }
15692
+ _context.next = 3;
15693
+ return Clipboard.getString();
15694
+ case 3:
15695
+ clipboardContent = _context.sent;
15696
+ canAutoFill = autoComplete === 'one-time-code' || textContentType === 'oneTimeCode';
15697
+ isValidClipboardContent = clipboardContent && clipboardContent.match(/^\d+$/) || normalizeValue(clipboardContent, length) !== trimmedValue;
15698
+ if (canAutoFill && isValidClipboardContent) {
15699
+ onChangeText === null || onChangeText === void 0 || onChangeText(clipboardContent);
15700
+ }
15701
+ case 7:
15702
+ case "end":
15703
+ return _context.stop();
15704
+ }
15705
+ }, _callee);
15706
+ })), 1000);
15707
+ return function () {
15708
+ clearInterval(autoFillInterval);
15709
+ };
15710
+ }, [autoComplete, textContentType, onChangeText, trimmedValue, length]);
15664
15711
  return /*#__PURE__*/React__default.createElement(StyledWrapper$5, {
15665
15712
  style: style,
15666
15713
  testID: testID
package/lib/index.js CHANGED
@@ -8,6 +8,7 @@ var reactNativeVectorIcons = require('react-native-vector-icons');
8
8
  var reactNativeSafeAreaContext = require('react-native-safe-area-context');
9
9
  var reactNativeMonthYearPicker = require('@hero-design/react-native-month-year-picker');
10
10
  var DateTimePicker = require('@react-native-community/datetimepicker');
11
+ var Clipboard = require('@react-native-clipboard/clipboard');
11
12
  var RnSlider = require('@react-native-community/slider');
12
13
  var reactNativeGestureHandler = require('react-native-gesture-handler');
13
14
  var LinearGradient = require('react-native-linear-gradient');
@@ -39,6 +40,7 @@ var reactNative__namespace = /*#__PURE__*/_interopNamespace(reactNative);
39
40
  var React__namespace = /*#__PURE__*/_interopNamespace(React);
40
41
  var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
41
42
  var DateTimePicker__default = /*#__PURE__*/_interopDefaultLegacy(DateTimePicker);
43
+ var Clipboard__default = /*#__PURE__*/_interopDefaultLegacy(Clipboard);
42
44
  var RnSlider__default = /*#__PURE__*/_interopDefaultLegacy(RnSlider);
43
45
  var LinearGradient__default = /*#__PURE__*/_interopDefaultLegacy(LinearGradient);
44
46
  var PagerView__default = /*#__PURE__*/_interopDefaultLegacy(PagerView);
@@ -401,6 +403,36 @@ function _typeof(o) {
401
403
  return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
402
404
  }, _typeof(o);
403
405
  }
406
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
407
+ try {
408
+ var info = gen[key](arg);
409
+ var value = info.value;
410
+ } catch (error) {
411
+ reject(error);
412
+ return;
413
+ }
414
+ if (info.done) {
415
+ resolve(value);
416
+ } else {
417
+ Promise.resolve(value).then(_next, _throw);
418
+ }
419
+ }
420
+ function _asyncToGenerator(fn) {
421
+ return function () {
422
+ var self = this,
423
+ args = arguments;
424
+ return new Promise(function (resolve, reject) {
425
+ var gen = fn.apply(self, args);
426
+ function _next(value) {
427
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
428
+ }
429
+ function _throw(err) {
430
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
431
+ }
432
+ _next(undefined);
433
+ });
434
+ };
435
+ }
404
436
  function _classCallCheck(instance, Constructor) {
405
437
  if (!(instance instanceof Constructor)) {
406
438
  throw new TypeError("Cannot call a class as a function");
@@ -15646,10 +15678,6 @@ var PinInput = /*#__PURE__*/React.forwardRef(function (_ref2, ref) {
15646
15678
  });
15647
15679
  var trimmedValue = normalizeValue(value, length);
15648
15680
  var maskedValueWithExtraSpace = reactNative.Platform.OS === 'android' && !trimmedValue ? '*' : trimmedValue;
15649
- var _useState3 = React.useState(false),
15650
- _useState4 = _slicedToArray(_useState3, 2),
15651
- hasFulfilled = _useState4[0],
15652
- setHasFulfilled = _useState4[1];
15653
15681
  var focus = React.useCallback(function () {
15654
15682
  if (inputRef !== null && inputRef !== void 0 && inputRef.current) {
15655
15683
  inputRef.current.focus();
@@ -15663,22 +15691,13 @@ var PinInput = /*#__PURE__*/React.forwardRef(function (_ref2, ref) {
15663
15691
  }
15664
15692
  }, []);
15665
15693
  var changeText = React.useCallback(function (text) {
15666
- // If the input is already fulfilled and the user tries to remove characters
15667
- if (hasFulfilled && text.length < length) {
15668
- setHasFulfilled(false);
15669
- }
15670
- // If the input is already fulfilled and the user tries to add more characters
15671
- if (hasFulfilled && ((text === null || text === void 0 ? void 0 : text.match(/\d/g)) || []).join('').length > length) {
15672
- return;
15673
- }
15674
15694
  // Prevent user from entering more than the length
15675
15695
  var trimmedPin = normalizeValue(text, length);
15676
15696
  onChangeText === null || onChangeText === void 0 || onChangeText(trimmedPin);
15677
15697
  if (trimmedPin.length === length) {
15678
15698
  onFulfill === null || onFulfill === void 0 || onFulfill(trimmedPin);
15679
- setHasFulfilled(true);
15680
15699
  }
15681
- }, [length, onChangeText, onFulfill, hasFulfilled]);
15700
+ }, [length, onChangeText, onFulfill]);
15682
15701
  React.useEffect(function () {
15683
15702
  // Must run after animations for keyboard to automatically open
15684
15703
  if (autoFocus) {
@@ -15691,6 +15710,35 @@ var PinInput = /*#__PURE__*/React.forwardRef(function (_ref2, ref) {
15691
15710
  blur: blur
15692
15711
  };
15693
15712
  });
15713
+ React.useEffect(function () {
15714
+ var autoFillInterval = setInterval( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
15715
+ var clipboardContent, canAutoFill, isValidClipboardContent;
15716
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
15717
+ while (1) switch (_context.prev = _context.next) {
15718
+ case 0:
15719
+ if (!(reactNative.Platform.OS === 'android')) {
15720
+ _context.next = 7;
15721
+ break;
15722
+ }
15723
+ _context.next = 3;
15724
+ return Clipboard__default["default"].getString();
15725
+ case 3:
15726
+ clipboardContent = _context.sent;
15727
+ canAutoFill = autoComplete === 'one-time-code' || textContentType === 'oneTimeCode';
15728
+ isValidClipboardContent = clipboardContent && clipboardContent.match(/^\d+$/) || normalizeValue(clipboardContent, length) !== trimmedValue;
15729
+ if (canAutoFill && isValidClipboardContent) {
15730
+ onChangeText === null || onChangeText === void 0 || onChangeText(clipboardContent);
15731
+ }
15732
+ case 7:
15733
+ case "end":
15734
+ return _context.stop();
15735
+ }
15736
+ }, _callee);
15737
+ })), 1000);
15738
+ return function () {
15739
+ clearInterval(autoFillInterval);
15740
+ };
15741
+ }, [autoComplete, textContentType, onChangeText, trimmedValue, length]);
15694
15742
  return /*#__PURE__*/React__default["default"].createElement(StyledWrapper$5, {
15695
15743
  style: style,
15696
15744
  testID: testID
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hero-design/rn",
3
- "version": "8.64.7",
3
+ "version": "8.64.8-alpha.1",
4
4
  "license": "MIT",
5
5
  "main": "lib/index.js",
6
6
  "module": "es/index.js",
@@ -29,6 +29,7 @@
29
29
  },
30
30
  "peerDependencies": {
31
31
  "@hero-design/react-native-month-year-picker": "^8.42.10",
32
+ "@react-native-clipboard/clipboard": "^1.13.2",
32
33
  "@react-native-community/datetimepicker": "^3.5.2 || ^7.6.1",
33
34
  "@react-native-community/slider": "^4.5.1",
34
35
  "react": "18.2.0",
@@ -52,6 +53,7 @@
52
53
  "@eslint/js": "^9.8.0",
53
54
  "@hero-design/eslint-plugin": "9.2.0",
54
55
  "@hero-design/react-native-month-year-picker": "^8.42.10",
56
+ "@react-native-clipboard/clipboard": "^1.14.2",
55
57
  "@react-native-community/datetimepicker": "7.6.1",
56
58
  "@react-native-community/slider": "^4.5.1",
57
59
  "@rollup/plugin-babel": "^5.3.1",
@@ -93,5 +95,6 @@
93
95
  "ts-jest": "^29.1.1",
94
96
  "typescript": "4.8.4"
95
97
  },
96
- "prettier": "prettier-config-hd"
98
+ "prettier": "prettier-config-hd",
99
+ "react-native": "src/index.ts"
97
100
  }
package/rollup.config.js CHANGED
@@ -40,6 +40,7 @@ export default {
40
40
  'react-native-vector-icons',
41
41
  'react-native-linear-gradient',
42
42
  '@hero-design/react-native-month-year-picker',
43
+ '@react-native-clipboard/clipboard',
43
44
  ],
44
45
  plugins: [
45
46
  replace({
@@ -150,20 +150,6 @@ describe('behaviors', () => {
150
150
  }
151
151
  }
152
152
  );
153
- it('does not allow typing when the max length is reached', () => {
154
- const onChangeText = jest.fn();
155
- const onFulfill = jest.fn();
156
- const { getByTestId } = renderWithTheme(
157
- <PinInput value="" onChangeText={onChangeText} onFulfill={onFulfill} />
158
- );
159
-
160
- const pinInput = getByTestId('pin-hidden-input');
161
- fireEvent.changeText(pinInput, '1234');
162
- fireEvent.changeText(pinInput, '56789');
163
-
164
- expect(onChangeText).toHaveBeenCalledTimes(1);
165
- expect(onFulfill).toHaveBeenCalledTimes(1);
166
- });
167
153
  });
168
154
 
169
155
  describe('getState', () => {
@@ -9,6 +9,7 @@ import React, {
9
9
  } from 'react';
10
10
  import { InteractionManager, Platform, TextInput } from 'react-native';
11
11
  import type { StyleProp, ViewStyle } from 'react-native';
12
+ import Clipboard from '@react-native-clipboard/clipboard';
12
13
  import Icon from '../Icon';
13
14
  import PinCell from './PinCell';
14
15
  import {
@@ -130,8 +131,6 @@ const PinInput = forwardRef<PinInputHandler, PinInputProps>(
130
131
  const maskedValueWithExtraSpace =
131
132
  Platform.OS === 'android' && !trimmedValue ? '*' : trimmedValue;
132
133
 
133
- const [hasFulfilled, setHasFulfilled] = useState(false);
134
-
135
134
  const focus = useCallback(() => {
136
135
  if (inputRef?.current) {
137
136
  inputRef.current.focus();
@@ -148,19 +147,6 @@ const PinInput = forwardRef<PinInputHandler, PinInputProps>(
148
147
 
149
148
  const changeText = useCallback(
150
149
  (text: string) => {
151
- // If the input is already fulfilled and the user tries to remove characters
152
- if (hasFulfilled && text.length < length) {
153
- setHasFulfilled(false);
154
- }
155
-
156
- // If the input is already fulfilled and the user tries to add more characters
157
- if (
158
- hasFulfilled &&
159
- (text?.match(/\d/g) || []).join('').length > length
160
- ) {
161
- return;
162
- }
163
-
164
150
  // Prevent user from entering more than the length
165
151
  const trimmedPin = normalizeValue(text, length);
166
152
 
@@ -168,10 +154,9 @@ const PinInput = forwardRef<PinInputHandler, PinInputProps>(
168
154
 
169
155
  if (trimmedPin.length === length) {
170
156
  onFulfill?.(trimmedPin);
171
- setHasFulfilled(true);
172
157
  }
173
158
  },
174
- [length, onChangeText, onFulfill, hasFulfilled]
159
+ [length, onChangeText, onFulfill]
175
160
  );
176
161
 
177
162
  useEffect(() => {
@@ -186,6 +171,28 @@ const PinInput = forwardRef<PinInputHandler, PinInputProps>(
186
171
  blur,
187
172
  }));
188
173
 
174
+ useEffect(() => {
175
+ const autoFillInterval = setInterval(async () => {
176
+ if (Platform.OS === 'android') {
177
+ const clipboardContent = await Clipboard.getString();
178
+ const canAutoFill =
179
+ autoComplete === 'one-time-code' ||
180
+ textContentType === 'oneTimeCode';
181
+ const isValidClipboardContent =
182
+ (clipboardContent && clipboardContent.match(/^\d+$/)) ||
183
+ normalizeValue(clipboardContent, length) !== trimmedValue;
184
+
185
+ if (canAutoFill && isValidClipboardContent) {
186
+ onChangeText?.(clipboardContent);
187
+ }
188
+ }
189
+ }, 1000);
190
+
191
+ return () => {
192
+ clearInterval(autoFillInterval);
193
+ };
194
+ }, [autoComplete, textContentType, onChangeText, trimmedValue, length]);
195
+
189
196
  return (
190
197
  <StyledWrapper style={style} testID={testID}>
191
198
  <StyledPinWrapper>
@@ -1,5 +0,0 @@
1
- 
2
- src/index.ts → lib/index.js, es/index.js...
3
- (!) Plugin replace: @rollup/plugin-replace: 'preventAssignment' currently defaults to false. It is recommended to set this option to `true`, as the next major version will default this option to `true`.
4
- (!) Plugin node-resolve: preferring built-in module 'events' over local alternative at '/home/runner/work/hero-design/hero-design/node_modules/events/events.js', pass 'preferBuiltins: false' to disable this behavior or 'preferBuiltins: true' to disable this warning
5
- created lib/index.js, es/index.js in 1m 3.5s