nicholas
nicholas

Reputation: 14563

iOS keyboard events in Adobe PhoneGap Build

Are there keyboard events in Adobe PhoneGap Build? Or a plugin that will expose them. Specifically I want to attach a callback to the keyboard showing and hiding.

I'm currently using focus and blur events on my inputs, but I'd rather be listening to the keyboard itself.

Upvotes: 0

Views: 454

Answers (2)

Andreas
Andreas

Reputation: 1150

I have used the ionic keyboard on plain Cordova but is also available for phonegap build here and it worked like charm on android but it's multiplatfrom and works both on android and ios Plus some extra features for iOS but the feature you want is multiplatform: after adding this on your config.xml:

<gap:plugin name="com.ionic-for-phonegap.keyboard" version="0.0.1" />

then use this on device ready:

//add event listeners
window.addEventListener('native.showkeyboard', keyboardShowFunction);
window.addEventListener('native.hidekeyboard', keyboardHideFunction);

//the handlers
//here if you want keyboard height use e.keyboardHeight in keyboardShowFunction to get it
function keyboardShowFunction(e){
    alert('Keyboard is on');
}

function keyboardHideFunction(e){
    alert('key board is off');
}

more features described on github

Upvotes: 0

Hendrik
Hendrik

Reputation: 291

There is a plugin to help you with this issue: https://github.com/mhweiner/CordovaiOSKeyboardPlugin

It basically lets you do stuff like this:

// See if keyboard is open or not
var is_open = Keyboard.isOpen();

// Get height of open keyboard (including inputAccessoryView toolbar)
var height = Keyboard.getHeight();

// The following jQuery events are available:
// keyboardWillShow, keyboardDidShow, keyboardWillHide, keyboardDidHide

// Set callback
$('body').on('keyboardWillShow', myCallback);

// Remove callback
$('body').off('keyboardWillShow');

Instructions can be found in the readme file wihtin the git repo.

Upvotes: 1

Related Questions