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

fix/ copmpser hide on change screen size #18702

Merged
merged 10 commits into from
May 12, 2023
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import toggleReportActionComposeView from '../toggleReportActionComposeView';
import * as Composer from '../actions/Composer';

export default (isSmallScreenWidth = true) => {
toggleReportActionComposeView(true, isSmallScreenWidth);
export default () => {
Composer.setShouldShowComposeInput(true);
};
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {Keyboard} from 'react-native';
import toggleReportActionComposeView from '../toggleReportActionComposeView';
import * as Composer from '../actions/Composer';

export default (isSmallScreenWidth = true) => {
export default () => {
const keyboardDidHideListener = Keyboard.addListener('keyboardDidHide', () => {
toggleReportActionComposeView(true, isSmallScreenWidth);
Composer.setShouldShowComposeInput(true);
keyboardDidHideListener.remove();
});
};
9 changes: 0 additions & 9 deletions src/libs/toggleReportActionComposeView/index.js

This file was deleted.

3 changes: 0 additions & 3 deletions src/libs/toggleReportActionComposeView/index.native.js

This file was deleted.

6 changes: 3 additions & 3 deletions src/pages/home/ReportScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import ReportActionsView from './report/ReportActionsView';
import CONST from '../../CONST';
import ReportActionsSkeletonView from '../../components/ReportActionsSkeletonView';
import reportActionPropTypes from './report/reportActionPropTypes';
import toggleReportActionComposeView from '../../libs/toggleReportActionComposeView';
import {withNetwork} from '../../components/OnyxProvider';
import compose from '../../libs/compose';
import Visibility from '../../libs/Visibility';
Expand All @@ -41,6 +40,7 @@ import EmojiPicker from '../../components/EmojiPicker/EmojiPicker';
import * as EmojiPickerAction from '../../libs/actions/EmojiPickerAction';
import TaskHeaderView from './TaskHeaderView';
import MoneyRequestHeader from '../../components/MoneyRequestHeader';
import * as ComposerActions from '../../libs/actions/Composer';

const propTypes = {
/** Navigation route context info provided by react navigation */
Expand Down Expand Up @@ -147,7 +147,7 @@ class ReportScreen extends React.Component {
});

this.fetchReportIfNeeded();
toggleReportActionComposeView(true);
ComposerActions.setShouldShowComposeInput(true);
Navigation.setIsReportScreenIsReady();
}

Expand All @@ -163,7 +163,7 @@ class ReportScreen extends React.Component {
}

this.fetchReportIfNeeded();
toggleReportActionComposeView(true);
ComposerActions.setShouldShowComposeInput(true);
}

componentWillUnmount() {
Expand Down
15 changes: 11 additions & 4 deletions src/pages/home/report/ReportActionCompose.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import * as User from '../../../libs/actions/User';
import Tooltip from '../../../components/Tooltip';
import EmojiPickerButton from '../../../components/EmojiPicker/EmojiPickerButton';
import * as DeviceCapabilities from '../../../libs/DeviceCapabilities';
import toggleReportActionComposeView from '../../../libs/toggleReportActionComposeView';
import OfflineIndicator from '../../../components/OfflineIndicator';
import ExceededCommentLength from '../../../components/ExceededCommentLength';
import withNavigationFocus from '../../../components/withNavigationFocus';
Expand All @@ -51,6 +50,7 @@ import ArrowKeyFocusManager from '../../../components/ArrowKeyFocusManager';
import OfflineWithFeedback from '../../../components/OfflineWithFeedback';
import KeyboardShortcut from '../../../libs/KeyboardShortcut';
import * as ComposerUtils from '../../../libs/ComposerUtils';
import * as ComposerActions from '../../../libs/actions/Composer';
import * as Welcome from '../../../libs/actions/Welcome';
import Permissions from '../../../libs/Permissions';
import * as TaskUtils from '../../../libs/actions/Task';
Expand Down Expand Up @@ -108,6 +108,9 @@ const propTypes = {
expiresAt: PropTypes.string,
}),

/** Whether the composer input should be shown */
shouldShowComposeInput: PropTypes.bool,
ahmdshrif marked this conversation as resolved.
Show resolved Hide resolved

/** Stores user's preferred skin tone */
preferredSkinTone: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),

Expand Down Expand Up @@ -145,6 +148,7 @@ const defaultProps = {
isComposerFullSize: false,
pendingAction: null,
reports: {},
shouldShowComposeInput: true,
...withCurrentUserPersonalDetailsDefaultProps,
};

Expand Down Expand Up @@ -204,7 +208,7 @@ class ReportActionCompose extends React.Component {
this.shouldFocusInputOnScreenFocus = canFocusInputOnScreenFocus();

this.state = {
isFocused: this.shouldFocusInputOnScreenFocus && !this.props.modal.isVisible && !this.props.modal.willAlertModalBecomeVisible,
isFocused: this.shouldFocusInputOnScreenFocus && !this.props.modal.isVisible && !this.props.modal.willAlertModalBecomeVisible && this.props.shouldShowComposeInput,
isFullComposerAvailable: props.isComposerFullSize,
textInputShouldClear: false,
isCommentEmpty: props.comment.length === 0,
Expand Down Expand Up @@ -270,7 +274,7 @@ class ReportActionCompose extends React.Component {
componentDidUpdate(prevProps) {
const sidebarOpened = !prevProps.isDrawerOpen && this.props.isDrawerOpen;
if (sidebarOpened) {
toggleReportActionComposeView(true);
ComposerActions.setShouldShowComposeInput(true);
}

// We want to focus or refocus the input when a modal has been closed and the underlying screen is focused.
Expand Down Expand Up @@ -1028,7 +1032,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.shouldFocusInputOnScreenFocus || this.isEmptyChat()) && this.props.shouldShowComposeInput}
multiline
ref={this.setTextInputRef}
textAlignVertical="top"
Expand Down Expand Up @@ -1214,5 +1218,8 @@ export default compose(
personalDetails: {
key: ONYXKEYS.PERSONAL_DETAILS,
},
shouldShowComposeInput: {
key: ONYXKEYS.SHOULD_SHOW_COMPOSE_INPUT,
},
}),
)(ReportActionCompose);
10 changes: 5 additions & 5 deletions src/pages/home/report/ReportActionItemMessageEdit.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import * as StyleUtils from '../../../styles/StyleUtils';
import Composer from '../../../components/Composer';
import * as Report from '../../../libs/actions/Report';
import * as ReportScrollManager from '../../../libs/ReportScrollManager';
import toggleReportActionComposeView from '../../../libs/toggleReportActionComposeView';
import openReportActionComposeViewWhenClosingMessageEdit from '../../../libs/openReportActionComposeViewWhenClosingMessageEdit';
import ReportActionComposeFocusManager from '../../../libs/ReportActionComposeFocusManager';
import compose from '../../../libs/compose';
Expand All @@ -32,6 +31,7 @@ import withWindowDimensions, {windowDimensionsPropTypes} from '../../../componen
import withLocalize, {withLocalizePropTypes} from '../../../components/withLocalize';
import withKeyboardState, {keyboardStatePropTypes} from '../../../components/withKeyboardState';
import * as ComposerUtils from '../../../libs/ComposerUtils';
import * as ComposerActions from '../../../libs/actions/Composer';

const propTypes = {
/** All the data of the action */
Expand Down Expand Up @@ -116,7 +116,7 @@ class ReportActionItemMessageEdit extends React.Component {

// Show the main composer when the focused message is deleted from another client
// to prevent the main composer stays hidden until we swtich to another chat.
toggleReportActionComposeView(true, this.props.isSmallScreenWidth);
ComposerActions.setShouldShowComposeInput(true);
}

/**
Expand Down Expand Up @@ -173,7 +173,7 @@ class ReportActionItemMessageEdit extends React.Component {
deleteDraft() {
this.debouncedSaveDraft.cancel();
Report.saveReportActionDraft(this.props.reportID, this.props.action.reportActionID, '');
toggleReportActionComposeView(true, this.props.isSmallScreenWidth);
ComposerActions.setShouldShowComposeInput(true);
ReportActionComposeFocusManager.focus();

// Scroll to the last comment after editing to make sure the whole comment is clearly visible in the report.
Expand Down Expand Up @@ -304,7 +304,7 @@ class ReportActionItemMessageEdit extends React.Component {
onFocus={() => {
this.setState({isFocused: true});
ReportScrollManager.scrollToIndex({animated: true, index: this.props.index}, true);
toggleReportActionComposeView(false, this.props.isSmallScreenWidth);
ComposerActions.setShouldShowComposeInput(false);
}}
onBlur={(event) => {
this.setState({isFocused: false});
Expand All @@ -318,7 +318,7 @@ class ReportActionItemMessageEdit extends React.Component {
if (this.messageEditInput === relatedTargetId) {
return;
}
openReportActionComposeViewWhenClosingMessageEdit(this.props.isSmallScreenWidth);
openReportActionComposeViewWhenClosingMessageEdit();
}}
selection={this.state.selection}
onSelectionChange={this.onSelectionChange}
Expand Down
2 changes: 1 addition & 1 deletion src/pages/home/report/ReportFooter.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class ReportFooter extends React.Component {
)}
</View>
)}
{!hideComposer && this.props.shouldShowComposeInput && (
{!hideComposer && (this.props.shouldShowComposeInput || !this.props.isSmallScreenWidth) && (
<View style={[this.getChatFooterStyles(), this.props.isComposerFullSize && styles.chatFooterFullCompose]}>
<SwipeableView onSwipeDown={Keyboard.dismiss}>
<ReportActionCompose
Expand Down