Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setup the compose focus manager on screen focus #23181

Merged
merged 2 commits into from
Jul 24, 2023
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
28 changes: 17 additions & 11 deletions src/pages/home/report/ReportActionCompose.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,19 +241,13 @@ class ReportActionCompose extends React.Component {
}

componentDidMount() {
// This callback is used in the contextMenuActions to manage giving focus back to the compose input.
// TODO: we should clean up this convoluted code and instead move focus management to something like ReportFooter.js or another higher up component
ReportActionComposeFocusManager.onComposerFocus(() => {
if (!this.willBlurTextInputOnTapOutside || !this.props.isFocused) {
return;
}

this.focus(false);
});

this.unsubscribeNavigationBlur = this.props.navigation.addListener('blur', () => KeyDownListener.removeKeyDownPressListner(this.focusComposerOnKeyPress));
this.unsubscribeNavigationFocus = this.props.navigation.addListener('focus', () => KeyDownListener.addKeyDownPressListner(this.focusComposerOnKeyPress));
this.unsubscribeNavigationFocus = this.props.navigation.addListener('focus', () => {
KeyDownListener.addKeyDownPressListner(this.focusComposerOnKeyPress);
this.setUpComposeFocusManager();
});
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Calling this.setUpComposeFocusManager() in focus listener as we are already using it. focus is triggered on screen focus only, not on mount. If we later migrate to functional component, we can use useFocusEffect only.

Btw, do you think we should clear the listener on screen blur? I don't see any reason we want to focus the composer while the report screen is not focused.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think so. It's redundant.

KeyDownListener.addKeyDownPressListner(this.focusComposerOnKeyPress);
this.setUpComposeFocusManager();

this.updateComment(this.comment);

Expand Down Expand Up @@ -312,6 +306,18 @@ class ReportActionCompose extends React.Component {
this.calculateMentionSuggestion();
}

setUpComposeFocusManager() {
// This callback is used in the contextMenuActions to manage giving focus back to the compose input.
// TODO: we should clean up this convoluted code and instead move focus management to something like ReportFooter.js or another higher up component
ReportActionComposeFocusManager.onComposerFocus(() => {
if (!this.willBlurTextInputOnTapOutside || !this.props.isFocused) {
return;
}

this.focus(false);
});
}

getDefaultSuggestionsValues() {
return {
suggestedEmojis: [],
Expand Down