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!");
});
@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
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.
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
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.