Skip to content
This repository has been archived by the owner on Feb 25, 2020. It is now read-only.

Commit

Permalink
fix: add clearTimeout to keyboard manager (#275)
Browse files Browse the repository at this point in the history
  • Loading branch information
wojtus7 authored and osdnk committed Oct 24, 2019
1 parent 1339364 commit f33e839
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/views/KeyboardManager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,21 @@ export default class KeyboardManager extends React.Component<Props> {
// When a gesture didn't change the tab, we can restore the focused input with this
private previouslyFocusedTextInput: number | null = null;
private startTimestamp: number = 0;
private keyboardTimeout: NodeJS.Timeout | undefined;

clearKeyboardTimeout = () => {
if (this.keyboardTimeout !== undefined) {
clearTimeout(this.keyboardTimeout);
this.keyboardTimeout = undefined;
}
};

componentWillUnmount = () => {
this.clearKeyboardTimeout();
};

private handlePageChangeStart = () => {
this.clearKeyboardTimeout();
const input = TextInput.State.currentlyFocusedField();

// When a page change begins, blur the currently focused input
Expand All @@ -29,13 +42,15 @@ export default class KeyboardManager extends React.Component<Props> {
};

private handlePageChangeConfirm = () => {
this.clearKeyboardTimeout();
Keyboard.dismiss();

// Cleanup the ID on successful page change
this.previouslyFocusedTextInput = null;
};

private handlePageChangeCancel = () => {
this.clearKeyboardTimeout();
// The page didn't change, we should restore the focus of text input
const input = this.previouslyFocusedTextInput;

Expand All @@ -48,7 +63,7 @@ export default class KeyboardManager extends React.Component<Props> {
// That's why when the interaction is shorter than 100ms we add delay so it won't hide once again.
// Subtracting timestamps makes us sure the delay is executed only when needed.
if (Date.now() - this.startTimestamp < 100) {
setTimeout(() => {
this.keyboardTimeout = setTimeout(() => {
TextInput.State.focusTextInput(input);
this.previouslyFocusedTextInput = null;
}, 100);
Expand Down

0 comments on commit f33e839

Please sign in to comment.