Copy link to clipboard
Copied
I'm having a challenge measuring the amount of soft keyboard content pan in my mobile Flex AIR app.
I have set the softKeyboardBehavior to pan in my application descriptor. I am able to measure the occurrence of soft keyboard activation, but I can't seem to get an accurate value of how much the content is panned. Depending upon the location of the keyboard focus element, content may be panned to accommodate both the element and the soft keyboard real estate. This works [with bugs, see below], but I need to measure by how much the content was panned so I can present another UI element always onscreen near the top edge of the display. Polling various stage and systemManager values doesn't seem to give me a number I can use.
The workaround I have is to try and guess the amount by polling the height of the soft keyboard rect. Looking at the stage.softKeyboardRect, the height value always the same amount, even if the soft keyboard is actually taking up real estate on screen or not! On an iPad Pro with a smart keyboard attached, often just a stub of a keyboard hint will be overlaid on the screen (about 100 pixels height), but the value returned is a soft keyboard height of 1426 -- obviously wrong. In addition, on the same iPad Pro with smart keyboard attached, often a huge blank white space is revealed on screen to accomodate what AIR mistakenly calculates is needed for a non-visible soft keyboard. Looking in the bugbase I see six other unresolved soft keyboard height bugs, so this may not be the way to go.
Is there a reliable method to measure the amount of pixels the application content was panned when a soft keyboard is activated?
Copy link to clipboard
Copied
Hey,
I use an ANE to measure keyboard, and have the following code to get the data:
var keyboardHeight:Number = MeasureKeyboard.getInstance().getKeyboardHeight() as Number;
var keyboardY:Number = MeasureKeyboard.getInstance().getKeyboardY() as Number;
It works nicely. Let me know if you want the ANE. Its a freshplanet MeasureKeyboard ANE.
Copy link to clipboard
Copied
I tried using the freshplanet KeyboardSize ANE from https://github.com/freshplanet/ANE-KeyboardSize but it was hard crashing the app when run on device when the getKeyboardHeight() method was called.
I assume you're using the same ANE. If there is a different or updated ANE, please let me know.
Copy link to clipboard
Copied
Yea, that's the one I'm using. I might try doing this:
try {
var keyboardHeight:Number = MeasureKeyboard.getInstance().getKeyboardHeight() as Number;
var keyboardY:Number = MeasureKeyboard.getInstance().getKeyboardY() as Number;
trace('measured keyboard height from ANE is: ' + keyboardHeight);
trace('stage keyboard height is: ' + stage.softKeyboardRect.height);
if (keyboardHeight == 0) {
trace('the measure keyboard ANE reported 0 height, which is a problem, falling back to stage keyboard height instead.');
keyboardHeight = stage.softKeyboardRect.height;
}
} catch (myError:Error) {
trace("Caught error trying to measure keyboard.");
}
Catch any exceptions that might be thrown, and fallback to the stage.softKeyboardRect.height value if the ANE crashes. Just an idea.