Skip to content
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
Copy Markdown
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
Copy Markdown
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