From b6623349cc811c2b3290f89dc5686a2eb0e59a64 Mon Sep 17 00:00:00 2001 From: usamaOmaribtmena Date: Tue, 14 Aug 2018 09:10:09 +0300 Subject: [PATCH 1/2] Update ConfirmationCodeInput.js --- example/src/components/ConfirmationCodeInput.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/example/src/components/ConfirmationCodeInput.js b/example/src/components/ConfirmationCodeInput.js index c9876a2..b6adb84 100644 --- a/example/src/components/ConfirmationCodeInput.js +++ b/example/src/components/ConfirmationCodeInput.js @@ -192,9 +192,15 @@ export default class ConfirmationCodeInput extends Component { _onKeyPress(e) { if (e.nativeEvent.key === 'Backspace') { + // Return if duration between previous key press and backspace is less than 20ms + if (Math.abs(this.lastKeyEventTimestamp - e.timeStamp) < 20) return; + const { currentIndex } = this.state; - const nextIndex = currentIndex > 0 ? currentIndex - 1 : 0; + const nextIndex = currentIndex > 0 ? currentIndex - 1 : 0; this._setFocus(nextIndex); + } else { + // Record non-backspace key event time stamp + this.lastKeyEventTimestamp = e.timeStamp; } } @@ -290,4 +296,4 @@ const styles = StyleSheet.create({ textAlign: 'center', padding: 0 } -}); \ No newline at end of file +}); From de5e8f98c0e28e2797329ecee0f33588b378e1e5 Mon Sep 17 00:00:00 2001 From: usamaOmaribtmena Date: Tue, 14 Aug 2018 14:20:27 +0300 Subject: [PATCH 2/2] Update ConfirmationCodeInput.js --- components/ConfirmationCodeInput.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/components/ConfirmationCodeInput.js b/components/ConfirmationCodeInput.js index 239c85a..2199cae 100644 --- a/components/ConfirmationCodeInput.js +++ b/components/ConfirmationCodeInput.js @@ -193,14 +193,20 @@ export default class ConfirmationCodeInput extends Component { } } + _onKeyPress(e) { if (e.nativeEvent.key === 'Backspace') { + // Return if duration between previous key press and backspace is less than 20ms + if (Math.abs(this.lastKeyEventTimestamp - e.timeStamp) < 20) return; + const { currentIndex } = this.state; const nextIndex = currentIndex > 0 ? currentIndex - 1 : 0; this._setFocus(nextIndex); + } else { + // Record non-backspace key event time stamp + this.lastKeyEventTimestamp = e.timeStamp; } } - _onInputCode(character, index) { const { codeLength, onFulfill, compareWithCode, ignoreCase } = this.props; let newCodeArr = _.clone(this.state.codeArr);