@hero-design/rn 8.64.7-alpha.1 → 8.64.8-alpha.0

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
@@ -15616,10 +15616,6 @@ var PinInput = /*#__PURE__*/forwardRef(function (_ref2, ref) {
15616
15616
  });
15617
15617
  var trimmedValue = normalizeValue(value, length);
15618
15618
  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
15619
  var focus = useCallback(function () {
15624
15620
  if (inputRef !== null && inputRef !== void 0 && inputRef.current) {
15625
15621
  inputRef.current.focus();
@@ -15633,22 +15629,13 @@ var PinInput = /*#__PURE__*/forwardRef(function (_ref2, ref) {
15633
15629
  }
15634
15630
  }, []);
15635
15631
  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
15632
  // Prevent user from entering more than the length
15645
15633
  var trimmedPin = normalizeValue(text, length);
15646
15634
  onChangeText === null || onChangeText === void 0 || onChangeText(trimmedPin);
15647
15635
  if (trimmedPin.length === length) {
15648
15636
  onFulfill === null || onFulfill === void 0 || onFulfill(trimmedPin);
15649
- setHasFulfilled(true);
15650
15637
  }
15651
- }, [length, onChangeText, onFulfill, hasFulfilled]);
15638
+ }, [length, onChangeText, onFulfill]);
15652
15639
  useEffect(function () {
15653
15640
  // Must run after animations for keyboard to automatically open
15654
15641
  if (autoFocus) {
package/lib/index.js CHANGED
@@ -15646,10 +15646,6 @@ var PinInput = /*#__PURE__*/React.forwardRef(function (_ref2, ref) {
15646
15646
  });
15647
15647
  var trimmedValue = normalizeValue(value, length);
15648
15648
  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
15649
  var focus = React.useCallback(function () {
15654
15650
  if (inputRef !== null && inputRef !== void 0 && inputRef.current) {
15655
15651
  inputRef.current.focus();
@@ -15663,22 +15659,13 @@ var PinInput = /*#__PURE__*/React.forwardRef(function (_ref2, ref) {
15663
15659
  }
15664
15660
  }, []);
15665
15661
  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
15662
  // Prevent user from entering more than the length
15675
15663
  var trimmedPin = normalizeValue(text, length);
15676
15664
  onChangeText === null || onChangeText === void 0 || onChangeText(trimmedPin);
15677
15665
  if (trimmedPin.length === length) {
15678
15666
  onFulfill === null || onFulfill === void 0 || onFulfill(trimmedPin);
15679
- setHasFulfilled(true);
15680
15667
  }
15681
- }, [length, onChangeText, onFulfill, hasFulfilled]);
15668
+ }, [length, onChangeText, onFulfill]);
15682
15669
  React.useEffect(function () {
15683
15670
  // Must run after animations for keyboard to automatically open
15684
15671
  if (autoFocus) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hero-design/rn",
3
- "version": "8.64.7-alpha.1",
3
+ "version": "8.64.8-alpha.0",
4
4
  "license": "MIT",
5
5
  "main": "lib/index.js",
6
6
  "module": "es/index.js",
@@ -93,5 +93,6 @@
93
93
  "ts-jest": "^29.1.1",
94
94
  "typescript": "4.8.4"
95
95
  },
96
- "prettier": "prettier-config-hd"
96
+ "prettier": "prettier-config-hd",
97
+ "react-native": "src/index.ts"
97
98
  }
@@ -150,6 +150,20 @@ 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
+ });
153
167
  });
154
168
 
155
169
  describe('getState', () => {
@@ -130,8 +130,6 @@ const PinInput = forwardRef<PinInputHandler, PinInputProps>(
130
130
  const maskedValueWithExtraSpace =
131
131
  Platform.OS === 'android' && !trimmedValue ? '*' : trimmedValue;
132
132
 
133
- const [hasFulfilled, setHasFulfilled] = useState(false);
134
-
135
133
  const focus = useCallback(() => {
136
134
  if (inputRef?.current) {
137
135
  inputRef.current.focus();
@@ -148,19 +146,6 @@ const PinInput = forwardRef<PinInputHandler, PinInputProps>(
148
146
 
149
147
  const changeText = useCallback(
150
148
  (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
149
  // Prevent user from entering more than the length
165
150
  const trimmedPin = normalizeValue(text, length);
166
151
 
@@ -168,10 +153,9 @@ const PinInput = forwardRef<PinInputHandler, PinInputProps>(
168
153
 
169
154
  if (trimmedPin.length === length) {
170
155
  onFulfill?.(trimmedPin);
171
- setHasFulfilled(true);
172
156
  }
173
157
  },
174
- [length, onChangeText, onFulfill, hasFulfilled]
158
+ [length, onChangeText, onFulfill]
175
159
  );
176
160
 
177
161
  useEffect(() => {