Skip to content

bug: ionKeyboardDidShow does not fire on android/chrome #21734

@jmannau

Description

@jmannau

Bug Report

Ionic version:

[ ] 4.x
[x] 5.x

Current behavior:

On iOS, the ionKeyboardDidShow & ionKeyboardDidHide events are fired correctly. This does not happen on Android devices. I have tested this on the following devices

  • Real device with Android 8.0.0 with Chrome 83.0.4103.106
  • Android Emulator Android 9.0 with Chrome 69.0.3497. 100

Expected behavior:

For compatible versions of Chrome & Safari, ionKeyboardDidShow & ionKeyboardDidHide events should fire.

Steps to reproduce:

  1. Create an Android 9 Emulator
  2. On the emulator, open https://jmannau.github.io/ionic-keyboard-event-test/home
  3. Click in the input box. The Keyboard Is Visible field should show true. If no events are fired then Keyboard is Visible stays false

Related code:

I have created a simple repository to test the events on different devices https://github.com/jmannau/ionic-keyboard-event-test you can goto this link and test the events https://jmannau.github.io/ionic-keyboard-event-test/home

Other information:

For the devices I have tested, the problems appears to be related to layoutViewportDidChange.

const layoutViewportDidChange = (): boolean => {
return (
currentLayoutViewport.width !== previousLayoutViewport.width ||
currentLayoutViewport.height !== previousLayoutViewport.height
);
};

This returns true and prevents the detection of keyboard showing in keyboardDidOpen

export const keyboardDidOpen = (): boolean => {
const scaledHeightDifference = (previousVisualViewport.height - currentVisualViewport.height) * currentVisualViewport.scale;
return (
!keyboardOpen &&
previousVisualViewport.width === currentVisualViewport.width &&
scaledHeightDifference > KEYBOARD_THRESHOLD &&
!layoutViewportDidChange()
);
};
.

Ionic info:

Ionic:

   Ionic CLI                     : 5.4.16 (/Users/james/.npm/_npx/30492/lib/node_modules/ionic)
   Ionic Framework               : @ionic/angular 5.2.3
   @angular-devkit/build-angular : 0.901.11
   @angular-devkit/schematics    : 9.1.11
   @angular/cli                  : 9.1.11
   @ionic/angular-toolkit        : 2.2.0

Utility:

   cordova-res : not installed
   native-run  : not installed

System:

   NodeJS : v12.16.2 (/Users/james/.nvm/versions/node/v12.16.2/bin/node)
   npm    : 6.14.5
   OS     : macOS Catalina

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions