Keyboard reopens after close repeatedly on iOS

I’m facing an issue with the Keyboard on iOS repeatedly opening after every touch event.

On my end, I can reproduce it by opening the keyboard on an input field and then navigating away from the page.

I tried to tap into the ionViewWillLeave() lifecycle event to call Keyboard.close() but it still pops up continuously on each touch event.

ionViewWillLeave(){
    this.keyboard.close();
  }

It doesn’t do this on Android and I have hideKeyboardAccessoryBar(false) set on iOS in our platform.ready().

        if(platform.is('ios')){
          this.keyboard.hideKeyboardAccessoryBar(false);
        }

This was done because some of views with only a single input ended up with us not being able to dismiss the keyboard.

My package.json:

        "---",
        "ionic-plugin-keyboard": "^2.2.1",
        "---",

The issue was not all iOS input fields but turned out to be specifically the Javascript Stripe implementation that we had.

It injects an iframe into the page and this was causing the issue.

I ended up taking the approach suggested at https://forum.ionicframework.com/t/ios-iframe-input-issue/106486/2 and implemented it as follows:

declare var cordova;
@ViewChild('ioshack') ioshack;
  ionViewWillLeave(){
    if(cordova.plugins.Keyboard.isVisible){
      this.ioshack.setFocus();
    }
  }
<ion-input #ioshack type="text" value="" class="ioshack" style="height: 0px;"></ion-input>

Its a hack but it works.

3 Likes

You save my day TODAY)) Hello from 2022
IFRAME + MODALWINDOW + Keyboard are terrifying.