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

Hide the composer when message is edited #7390

Merged
merged 6 commits into from
Feb 8, 2022
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
31 changes: 31 additions & 0 deletions src/libs/VirtualKeyboard/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import _ from 'underscore';
import canUseTouchScreen from '../canUseTouchscreen';

/**
* Is the virtual keyboard open?
*
* @returns {Boolean|null} – null if the VirtualKeyboard API is unavailable
*/
function isOpen() {
if (!_.has(navigator, 'virtualKeyboard')) {
return null;
}
return navigator.virtualKeyboard.boundingRect.y > 0;
}

/**
* As of January 2022, the VirtualKeyboard web API is not available in all browsers yet
* If it is unavailable, we default to assuming that the virtual keyboard is open on touch-enabled devices.
* See https://github.com/Expensify/App/issues/6767 for additional context.
*
* @returns {Boolean}
*/
function shouldAssumeIsOpen() {
const isOpened = isOpen();
return _.isNull(isOpened) ? canUseTouchScreen() : isOpened;
}

export default {
isOpen,
shouldAssumeIsOpen,
};
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function isOpen() {
return isVirtualKeyboardOpen;
}

export {
// eslint-disable-next-line import/prefer-default-export
export default {
isOpen,
shouldAssumeIsOpen: isOpen,
};
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as Session from './actions/Session';
import * as Session from '../actions/Session';

export default (shouldShowComposeInput, isSmallScreenWidth) => {
if (!isSmallScreenWidth) {
Expand Down
3 changes: 3 additions & 0 deletions src/libs/toggleReportActionComposeView/index.native.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import * as Session from '../actions/Session';

export default shouldShowComposeInput => Session.setShouldShowComposeInput(shouldShowComposeInput);
18 changes: 0 additions & 18 deletions src/libs/virtualKeyboard/index.js

This file was deleted.

17 changes: 2 additions & 15 deletions src/pages/home/report/ReportActionCompose.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ import {withNetwork, withPersonalDetails} from '../../../components/OnyxProvider
import DateUtils from '../../../libs/DateUtils';
import Tooltip from '../../../components/Tooltip';
import * as EmojiUtils from '../../../libs/EmojiUtils';
import canUseTouchScreen from '../../../libs/canUseTouchscreen';
import * as VirtualKeyboard from '../../../libs/virtualKeyboard';
import VirtualKeyboard from '../../../libs/VirtualKeyboard';

const propTypes = {
/** Beta features list */
Expand Down Expand Up @@ -357,25 +356,13 @@ class ReportActionCompose extends React.Component {
this.textInput.scrollTop = this.textInput.scrollHeight;
}

/**
* As of January 2022, the VirtualKeyboard web API is not available in all browsers yet
* If it is unavailable, we default to assuming that the virtual keyboard is open on touch-enabled devices.
* See https://github.com/Expensify/App/issues/6767 for additional context.
*
* @returns {Boolean}
*/
shouldAssumeVirtualKeyboardIsOpen() {
const isOpen = VirtualKeyboard.isOpen();
return _.isNull(isOpen) ? canUseTouchScreen() : isOpen;
}

/**
* Listens for keyboard shortcuts and applies the action
*
* @param {Object} e
*/
triggerHotkeyActions(e) {
if (!e || this.shouldAssumeVirtualKeyboardIsOpen()) {
if (!e || VirtualKeyboard.shouldAssumeIsOpen()) {
return;
}

Expand Down
3 changes: 2 additions & 1 deletion src/pages/home/report/ReportActionItemMessageEdit.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import withLocalize, {withLocalizePropTypes} from '../../../components/withLocal
import Button from '../../../components/Button';
import ReportActionComposeFocusManager from '../../../libs/ReportActionComposeFocusManager';
import compose from '../../../libs/compose';
import VirtualKeyboard from '../../../libs/VirtualKeyboard';

const propTypes = {
/** All the data of the action */
Expand Down Expand Up @@ -157,7 +158,7 @@ class ReportActionItemMessageEdit extends React.Component {
style={[styles.textInputCompose, styles.flex4]}
onFocus={() => {
ReportScrollManager.scrollToIndex({animated: true, index: this.props.index}, true);
toggleReportActionComposeView(false);
toggleReportActionComposeView(false, VirtualKeyboard.shouldAssumeIsOpen());
}}
selection={this.state.selection}
onSelectionChange={this.onSelectionChange}
Expand Down