Skip to content

Commit

Permalink
Press BACK button if ESC fails to close soft keyboard (#471)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mykola Mokhnach authored Nov 27, 2018
1 parent 9d3d1dd commit 898bfc5
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions lib/commands/general.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,22 +68,23 @@ commands.isKeyboardShown = async function () {

commands.hideKeyboard = async function () {
let {isKeyboardShown, canCloseKeyboard} = await this.adb.isSoftKeyboardPresent();
if (isKeyboardShown) {
if (!isKeyboardShown) {
log.info('Keyboard has no UI; no closing necessary');
return;
}
// Try ESC then BACK if the first one fails
for (const keyCode of [111, 4]) {
if (canCloseKeyboard) {
// Press escape
await this.adb.keyevent(111);
await this.adb.keyevent(keyCode);
}
try {
await waitForCondition(async () => {
return await waitForCondition(async () => {
({isKeyboardShown} = await this.adb.isSoftKeyboardPresent());
return !isKeyboardShown;
}, {waitMs: 2000, intervalMs: 500});
} catch (err) {
throw new Error(`The software keyboard cannot be closed`);
}
} else {
log.info('Keyboard has no UI; no closing necessary');
}, {waitMs: 1000, intervalMs: 500});
} catch (ign) {}
}
throw new Error(`The software keyboard cannot be closed`);
};

commands.openSettingsActivity = async function (setting) {
Expand Down

0 comments on commit 898bfc5

Please sign in to comment.