@hero-design/rn 8.64.8-alpha.0 → 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/CHANGELOG.md +6 -0
- package/es/index.js +60 -0
- package/lib/index.js +61 -0
- package/package.json +3 -1
- package/rollup.config.js +1 -0
- package/src/components/PinInput/__tests__/index.spec.tsx +0 -14
- package/src/components/PinInput/index.tsx +23 -0
- package/stats/8.64.7/rn-stats.html +4842 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# @hero-design/rn
|
|
2
2
|
|
|
3
|
+
## 8.64.7
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#3336](https://github.com/Thinkei/hero-design/pull/3336) [`34f5cb207ed68fcb4d2882e0175c7c085963332d`](https://github.com/Thinkei/hero-design/commit/34f5cb207ed68fcb4d2882e0175c7c085963332d) Thanks [@vinhphan-eh](https://github.com/vinhphan-eh)! - [PinInput] Add value validation logic
|
|
8
|
+
|
|
3
9
|
## 8.64.6
|
|
4
10
|
|
|
5
11
|
### Patch Changes
|
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");
|
|
@@ -15648,6 +15679,35 @@ var PinInput = /*#__PURE__*/forwardRef(function (_ref2, ref) {
|
|
|
15648
15679
|
blur: blur
|
|
15649
15680
|
};
|
|
15650
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]);
|
|
15651
15711
|
return /*#__PURE__*/React__default.createElement(StyledWrapper$5, {
|
|
15652
15712
|
style: style,
|
|
15653
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");
|
|
@@ -15678,6 +15710,35 @@ var PinInput = /*#__PURE__*/React.forwardRef(function (_ref2, ref) {
|
|
|
15678
15710
|
blur: blur
|
|
15679
15711
|
};
|
|
15680
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]);
|
|
15681
15742
|
return /*#__PURE__*/React__default["default"].createElement(StyledWrapper$5, {
|
|
15682
15743
|
style: style,
|
|
15683
15744
|
testID: testID
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hero-design/rn",
|
|
3
|
-
"version": "8.64.8-alpha.
|
|
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",
|
package/rollup.config.js
CHANGED
|
@@ -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 {
|
|
@@ -170,6 +171,28 @@ const PinInput = forwardRef<PinInputHandler, PinInputProps>(
|
|
|
170
171
|
blur,
|
|
171
172
|
}));
|
|
172
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
|
+
|
|
173
196
|
return (
|
|
174
197
|
<StyledWrapper style={style} testID={testID}>
|
|
175
198
|
<StyledPinWrapper>
|