Skip to content

soft-keyboard

Raises the Android soft keyboard for a screenshot, and proves it came up.

Two things have to be true, and the second is the one that is easy to miss:

  1. The device must be allowed to draw a keyboard at all. The screenshot AVDs are built hw.keyboard=yes, so Android suppresses the on-screen one — withSoftKeyboardEnabled in device-settings is what lifts that. 2. The IME must be asked for by a gesture. A field that takes focus programmatically does not get one: an Android WebView raises the IME on a real touch, and a run with the setting flipped and no touch comes back with exactly the empty band it had before. adb shell input tap is that gesture.

  2. The proof that it arrived is that the field moved, measured against a baseline read here before the first touch. An absolute offset from the viewport bottom is the same test only for a bottom-anchored field; for a centred modal it is already true with no keyboard, which used to break the loop below before it had dispatched a single touch and return success having done nothing. Reading the baseline first also makes that shape unrepresentable rather than merely corrected: the delta of the baseline against itself is zero, so the first iteration always taps.

The geometry that decides whether it worked is unit-tested in soft-keyboard-geometry; everything here drives a real device, so the whole module is integration-time code.

InterfaceDescription
RaiseSoftKeyboardParamsParameters for raiseSoftKeyboard.
TapDeviceParamsParameters for tapDevice.
FunctionDescription
raiseSoftKeyboardRaises the on-screen keyboard with a real touch on a field, and confirms it came up. Call it inside withSoftKeyboardEnabled — the device setting alone does not raise the keyboard, and this touch alone cannot while the setting suppresses it. Call it with the keyboard DOWN. The first read is the baseline every later read is compared against, so a keyboard that is already up leaves the field nothing to lift by and this throws. That is the deliberate trade for working on a centred modal as well as a bottom-anchored one — see checkIsSoftKeyboardUp.
tapDeviceTouches the device at a point, the way a thumb would.