-
Notifications
You must be signed in to change notification settings - Fork 2.9k
/
focusComposerWithDelay.ts
34 lines (31 loc) · 1.06 KB
/
focusComposerWithDelay.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import {TextInput} from 'react-native';
import * as EmojiPickerAction from './actions/EmojiPickerAction';
import ComposerFocusManager from './ComposerFocusManager';
type FocusComposerWithDelay = (shouldDelay?: boolean) => void;
/**
* Create a function that focuses the composer.
*/
function focusComposerWithDelay(textInput: TextInput | null): FocusComposerWithDelay {
/**
* Focus the text input
* @param [shouldDelay] Impose delay before focusing the text input
*/
return (shouldDelay = false) => {
// There could be other animations running while we trigger manual focus.
// This prevents focus from making those animations janky.
if (!textInput || EmojiPickerAction.isEmojiPickerVisible()) {
return;
}
if (!shouldDelay) {
textInput.focus();
return;
}
ComposerFocusManager.isReadyToFocus().then(() => {
if (!textInput) {
return;
}
textInput.focus();
});
};
}
export default focusComposerWithDelay;