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

fix: add clearTimeout to keyboard manager #275

Merged
merged 4 commits into from
Oct 24, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 = () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be private

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