Skip to content

Commit

Permalink
Restore pasting from keyboard on iOS
Browse files Browse the repository at this point in the history
  • Loading branch information
Damian Sznajder committed Dec 19, 2019
1 parent 4d071da commit 8f1802f
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
5 changes: 2 additions & 3 deletions src/OtpInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ const OtpInput = forwardRef<TextInput, Props>(
(
{
focusStyles,
handleKeyPress,
handleTextChange,
inputContainerStyles,
inputStyles,
inputValue,
placeholder,
selectTextOnFocus,
inputValue,
handleKeyPress,
...rest
},
ref,
Expand All @@ -50,7 +50,6 @@ const OtpInput = forwardRef<TextInput, Props>(
return (
<View style={[inputContainerStyles, focused && focusStyles]}>
<TextInput
maxLength={1}
onBlur={() => setFocused(false)}
onChangeText={handleTextChange}
onFocus={() => setFocused(true)}
Expand Down
1 change: 0 additions & 1 deletion src/__tests__/__snapshots__/OtpInput.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ exports[`<OtpInput /> render 1`] = `
>
<TextInput
allowFontScaling={true}
maxLength={1}
onBlur={[Function]}
onFocus={[Function]}
rejectResponderTermination={true}
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/__snapshots__/index.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ exports[`<OtpInputs /> render 1`] = `
clearTextOnFocus={false}
firstInput={true}
keyboardType="phone-pad"
maxLength={1}
maxLength={4}
numberOfInputs={4}
onBlur={[Function]}
onChangeText={[Function]}
Expand Down
10 changes: 10 additions & 0 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,12 @@ const OtpInputs = forwardRef<OtpInputsRef, Props>(
handleClearInput(index);
}

if (text.length > 1) {
handleClearInput(index);
Keyboard.dismiss();
return fillInputs(text);
}

if (text) {
handleInputTextChange({ text, index });
}
Expand Down Expand Up @@ -286,6 +292,10 @@ const OtpInputs = forwardRef<OtpInputsRef, Props>(
handleKeyPress={(keyPressEvent: NativeSyntheticEvent<TextInputKeyPressEventData>) =>
handleKeyPress(keyPressEvent, inputIndex)
}
maxLength={Platform.select({
android: 1,
ios: index === 0 ? numberOfInputs : 1,
})}
autoCapitalize={autoCapitalize}
clearTextOnFocus={clearTextOnFocus}
firstInput={index === 0}
Expand Down

0 comments on commit 8f1802f

Please sign in to comment.