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 : Unable to type next paragraph in message #7355

Merged
merged 10 commits into from
Jan 24, 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
18 changes: 18 additions & 0 deletions src/libs/virtualKeyboard/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import _ from 'underscore';

/**
* 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;
}

export {
// eslint-disable-next-line import/prefer-default-export
isOpen,
};
33 changes: 33 additions & 0 deletions src/libs/virtualKeyboard/index.native.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import {Keyboard} from 'react-native';

let isVirtualKeyboardOpen = false;

Keyboard.addListener(
'keyboardDidShow',
() => {
isVirtualKeyboardOpen = true;
},
);

Keyboard.addListener(
'keyboardDidHide',
() => {
isVirtualKeyboardOpen = false;
},
);

/**
* Is the virtual keyboard open?
*
* Note – the web equivalent of this function may return null.
*
* @returns {Boolean}
*/
function isOpen() {
return isVirtualKeyboardOpen;
}

export {
// eslint-disable-next-line import/prefer-default-export
isOpen,
};
16 changes: 15 additions & 1 deletion src/pages/home/report/ReportActionCompose.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ 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';

const propTypes = {
/** Beta features list */
Expand Down Expand Up @@ -353,13 +355,25 @@ class ReportActionCompose extends React.Component {
}
}

/**
* 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();
ahmdshrif marked this conversation as resolved.
Show resolved Hide resolved
return _.isNull(isOpen) ? canUseTouchScreen() : isOpen;
}

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

Expand Down