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

Press BACK button if ESC fails to close soft keyboard #471

Merged
merged 1 commit into from
Nov 27, 2018
Merged
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
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