Skip to content
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions src/libs/willBlurTextInputOnTapOutside/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default () => true;
1 change: 1 addition & 0 deletions src/libs/willBlurTextInputOnTapOutside/index.native.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default () => false;
18 changes: 11 additions & 7 deletions src/pages/home/report/ReportActionCompose.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import ReportTypingIndicator from './ReportTypingIndicator';
import AttachmentModal from '../../../components/AttachmentModal';
import compose from '../../../libs/compose';
import PopoverMenu from '../../../components/PopoverMenu';
import willBlurTextInputOnTapOutside from '../../../libs/willBlurTextInputOnTapOutside';
import CONST from '../../../CONST';
import canFocusInputOnScreenFocus from '../../../libs/canFocusInputOnScreenFocus';
import Permissions from '../../../libs/Permissions';
import Navigation from '../../../libs/Navigation/Navigation';
import ROUTES from '../../../ROUTES';
Expand Down Expand Up @@ -134,12 +134,14 @@ class ReportActionCompose extends React.Component {
this.getInputPlaceholder = this.getInputPlaceholder.bind(this);
this.getIOUOptions = this.getIOUOptions.bind(this);
this.addAttachment = this.addAttachment.bind(this);

this.comment = props.comment;
this.shouldFocusInputOnScreenFocus = canFocusInputOnScreenFocus();

// React Native will retain focus on an input for native devices but web/mWeb behave differently so we have some focus management
// code that will refocus the compose input after a user closes a modal or some other actions, see usage of ReportActionComposeFocusManager
this.willBlurTextInputOnTapOutside = willBlurTextInputOnTapOutside();

this.state = {
isFocused: this.shouldFocusInputOnScreenFocus && !this.props.modal.isVisible && !this.props.modal.willAlertModalBecomeVisible,
isFocused: this.willBlurTextInputOnTapOutside && !this.props.modal.isVisible && !this.props.modal.willAlertModalBecomeVisible,
isFullComposerAvailable: props.isComposerFullSize,
textInputShouldClear: false,
isCommentEmpty: props.comment.length === 0,
Expand All @@ -157,8 +159,10 @@ 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.shouldFocusInputOnScreenFocus || !this.props.isFocused) {
if (!this.willBlurTextInputOnTapOutside || !this.props.isFocused) {
return;
}

Expand All @@ -177,7 +181,7 @@ class ReportActionCompose extends React.Component {
// We want to focus or refocus the input when a modal has been closed and the underlying screen is focused.
// We avoid doing this on native platforms since the software keyboard popping
// open creates a jarring and broken UX.
if (this.shouldFocusInputOnScreenFocus && this.props.isFocused
if (this.willBlurTextInputOnTapOutside && this.props.isFocused
&& prevProps.modal.isVisible && !this.props.modal.isVisible) {
this.focus();
}
Expand Down Expand Up @@ -661,7 +665,7 @@ class ReportActionCompose extends React.Component {
disabled={this.props.disabled}
>
<Composer
autoFocus={!this.props.modal.isVisible && (this.shouldFocusInputOnScreenFocus || this.isEmptyChat())}
autoFocus={!this.props.modal.isVisible && (this.willBlurTextInputOnTapOutside || this.isEmptyChat())}

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.

Coming from #17187:
This was overlooked while replacing all shouldFocusInputOnScreenFocus occurrences. Actually no changes needed here. Native and mWeb should be consistent in autofocus behavior.

multiline
ref={this.setTextInputRef}
textAlignVertical="top"
Expand Down