Ionic Keyboard Information Update

Hey guys just had a chat with @mhartington on the ionic slack channel about ionic keyboard and wanted to share with you all what was discussed because I thought it might be helpful.

If you’re have trouble getting the keyboard api to work ensure that the following is true in your project.

1.ionic-plugin-keyboard is removed using ionic cordova plugin rm ionic-plugin-keyboard ( why? )
2. cordova-plugin-ionic-keyboard is added using ionic cordova plugin add cordova-plugin-ionic-keyboard
3. You are using the keyboard api docs here, not the docs here ( these ones are outdated according @mhartington )


Update

Currently documentation states that keyboard close on all platforms is done with Keyboard.hide(), this is only the case for iOS. For Android use Keyboard.close() until pull request is merged.

Hopefully this helps someone!

Update 2

There has been some questions about how to access the keyboard events and methods below. The code below is how I’ve been utilizing the keyboard methods and events.

//Accessing Methods Example
(<any>window).Keyboard.show();
(<any>window).Keyboard.hide();

//Accessing Events Example
window.addEventListener("keyboardWillShow",() => {
    console.log("Keyboard open!");
});
window.addEventListener("keyboardWillHide",() => {
    console.log("Keyboard closed!");
});
3 Likes

@meatloaf4 Hoping you could help me out with this…

So I visit the current docs so I can use Keyboard in my project. I do some fishing around see the Ionic native plugin is deprecated, and then I find your post here.

I’m obviously not keen on using Ionic’s deprecated ionic-plugin-keyboard plugin. Their own github page recommends using cordova-plugin-ionic-keyboard, yet this isn’t compatible with @ionic-native/keyboard. I don’t understand why they’ve deprecated their plugin without even adding support for the one they’re switching to :confused:

If I try to use @ionic-native/keyboard with cordova-plugin-ionic-keyboard I get:

console.warn: Native: tried calling Keyboard.show, but the Keyboard plugin is not installed. 
console.warn: Install the Keyboard plugin: 'ionic cordova plugin add ionic-plugin-keyboard' 

How do I use the cordova-plugin-ionic-keyboard without @ionic-native/keyboard? Have I got to go through these hoops just to access the darn keyboard?

I’m new to Ionic, Angular, and Cordova… and these issues are stupidly hard to keep on top of.

Thanks for any help!

As far as I understood, right now, @ionic-native/keyboard is not really compatible straight forward with the new plugin cordova-plugin-ionic-keyboard , you could have a look to this issue https://github.com/ionic-team/ionic-native/issues/2306

BUT, the new plugin cordova-plugin-ionic-keyboard really improves the quality I think or at least in my case. With ionic-plugin-keyboard I was using the wrapper because I still had to handle close/show actions of the keyboard because sometimes it didn’t worked aka the keyboard sometimes used to stayed open. With the new plugin I just don’t have too, it works like a charm, so now in my productive app I just don’t need @ionic-native/keyboard anymore.

So depending of the reason why you would need the native wrapper, specially if you need it to close the keyboard, I would suggest first to try without because the new plugin works fine :wink:

I’m just after some of the basic show/hide events.

How are you accessing the plugin, window.keyboard? This all just seems like such a hack to me, Ionic devs need to get their s**t together…

2 Likes

Like I said, I don’t have anymore, for me show/hide just work fine straight forward now which is a cool improvement

About window.keyboard just like described in the doc. And if typescript complains, maybe trying to declare the variable for now on as any or write your own typescript file…didn’t tried just a guess

The docs there only explain direct use of the Keyboard object. I still can’t figure out how to access it in my components. I’ve tried declaring it above my class, accessing it through window.plugins.keyboard, window.keyboard, window.cordova.plugins.keyboard etc., with no luck.

How are you accessing the Keyboard object?

Okay, i’m using this to handle events if it helps anyone…

Observable.fromEvent( window, 'keyboardWillShow' ).subscribe(e => {
	this.keyboardVisible = true;
	console.log( 'keyboard will open!' );
});

Observable.fromEvent( window, 'keyboardWillHide' ).subscribe(e => {
	this.keyboardVisible = false;
	console.log( 'keyboard will close!' );
});

But I still can’t get access Keyboard.

Again I don’t :wink:

Have you try declaring it as any? Maybe that’s enough?

declare var Keyboard: any;

@IonicPage()
export class...

Haha oh.

I think i’ll give up and just use the events for now until Ionic release a working native plugin wrapper.

Thanks anyway :slight_smile:

1 Like

I’ll update the main post with how you go about accessing show and hide as well as the events.

1 Like

Dismissing the keyboard when KeyboardResize is set to false requires two taps, anyone else experiencing this.

@mhartington Why is the Issue tracker for the forked branch disabled?

I have made a provider to handler the new plugin properties, events and methods.
I hope this help you!

1 Like

For Ionic 4 Tutorial on Keyboard Native Plugin and Event, listeners check this link