Skip to content

Commit

Permalink
Merge pull request #7390 from parasharrajat/composerHide
Browse files Browse the repository at this point in the history
Hide the composer when message is edited
  • Loading branch information
stitesExpensify authored Feb 8, 2022
2 parents 4e51685 + 3899a9f commit cb5a30f
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 37 deletions.
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

0 comments on commit cb5a30f

Please sign in to comment.