-
Notifications
You must be signed in to change notification settings - Fork 3.1k
/
Copy pathindex.website.ts
30 lines (26 loc) · 1.02 KB
/
index.website.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
import Onyx from 'react-native-onyx';
import * as Browser from '@libs/Browser';
import ReportActionComposeFocusManager from '@libs/ReportActionComposeFocusManager';
import ONYXKEYS from '@src/ONYXKEYS';
function inputFocusChange(focus: boolean) {
Onyx.set(ONYXKEYS.INPUT_FOCUSED, focus);
}
let refSave: HTMLElement | undefined;
function composerFocusKeepFocusOn(ref: HTMLElement, isFocused: boolean, modal: {willAlertModalBecomeVisible: boolean; isVisible: boolean}, onyxFocused: boolean) {
if (isFocused && !onyxFocused) {
inputFocusChange(true);
ref.focus();
}
if (isFocused) {
refSave = ref;
}
if (!isFocused && !onyxFocused && !modal.willAlertModalBecomeVisible && !modal.isVisible && refSave) {
if (!ReportActionComposeFocusManager.isFocused()) {
refSave.focus();
} else {
refSave = undefined;
}
}
}
const callback = (method: () => void) => !Browser.isMobile() && method();
export {composerFocusKeepFocusOn, inputFocusChange, callback};