Skip to content

Commit

Permalink
added desktop file and updated focus manager
Browse files Browse the repository at this point in the history
Signed-off-by: Ayaz Alavi <ayaz.alavi@gmail.com>
  • Loading branch information
ayazalavi committed Oct 9, 2023
1 parent 83dfeb6 commit 2cc1e12
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 4 deletions.
30 changes: 30 additions & 0 deletions src/libs/actions/InputFocus/index.desktop.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import Onyx from 'react-native-onyx';
import ONYXKEYS from '../../../ONYXKEYS';
import * as Browser from '../../Browser';

Check failure on line 3 in src/libs/actions/InputFocus/index.desktop.ts

View workflow job for this annotation

GitHub Actions / lint

'Browser' is defined but never used
import ReportActionComposeFocusManager from '../../ReportActionComposeFocusManager';

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) => method();

export {composerFocusKeepFocusOn, inputFocusChange, callback};
13 changes: 9 additions & 4 deletions src/libs/actions/InputFocus/index.website.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Onyx from 'react-native-onyx';
import ONYXKEYS from '../../../ONYXKEYS';
import * as Browser from '../../Browser';
import ReportActionComposeFocusManager from '../../ReportActionComposeFocusManager';

function inputFocusChange(focus: boolean) {
if (Browser.isMobile()) {
Expand All @@ -10,19 +11,23 @@ function inputFocusChange(focus: boolean) {
}

let refSave: HTMLElement | undefined;
function composerFocusKeepFocusOn(ref: HTMLElement, isFocused: boolean, modal: {willAlertModalBecomeVisible: boolean; isVisible: boolean}, onyxFocused: boolean) {
function composerFocusKeepFocusOn(ref: HTMLElement, isFocused: boolean, modal: { willAlertModalBecomeVisible: boolean; isVisible: boolean }, onyxFocused: boolean) {
if (Browser.isMobile()) {
return;
}
if (isFocused && !onyxFocused) {
inputFocusChange(true);
ref.focus();
}
}
if (isFocused) {
refSave = ref;
}
if (!isFocused && !onyxFocused && !modal.willAlertModalBecomeVisible && !modal.isVisible && refSave) {
refSave.focus();
if (!isFocused && !onyxFocused && !modal.willAlertModalBecomeVisible && !modal.isVisible && refSave) {
if (!ReportActionComposeFocusManager.isFocused()) {
refSave.focus();
} else {
refSave = undefined;
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,7 @@ function ComposerWithSuggestions({
if (!suggestionsRef.current) {
return false;
}
InputFocus.inputFocusChange(false)
return suggestionsRef.current.setShouldBlockSuggestionCalc(false);
}, [suggestionsRef]);

Expand Down

0 comments on commit 2cc1e12

Please sign in to comment.