Hi,
I solved this with a native Java plugin for Android which calculates the available vertical space above the keyboard. I will do something similar for iOS later (my immediate need is to conclude an Android prototype).
With this plugin I can achieve the exact layout I want above the keyboard.
A main.lua example:
display.setStatusBar(display.HiddenStatusBar) local \_W = display.contentWidth local dummyTextField = native.newTextField(-20, -20, 10, 10) native.setKeyboardFocus(dummyTextField) local function render() dummyTextField:removeSelf() local spaceAboveKeyboard = SpaceAboveKeyboard.calculate() local textBox = native.newTextBox(\_W / 2, spaceAboveKeyboard / 2, \_W, spaceAboveKeyboard) textBox.isEditable = true native.setKeyboardFocus(textBox) end timer.performWithDelay(1000, render)
I updated android/app/src/main/AndroidManifest.xml like this:
$ svn diff android/app/src/main/AndroidManifest.xml Index: android/app/src/main/AndroidManifest.xml =================================================================== --- android/app/src/main/AndroidManifest.xml (revision 598) +++ android/app/src/main/AndroidManifest.xml (working copy) @@ -41,6 +41,7 @@ \<action android:name="android.intent.action.MAIN" /\> \<category android:name="android.intent.category.LAUNCHER" /\> \</intent-filter\> + \<meta-data android:name="coronaWindowMovesWhenKeyboardAppears" android:value="true"/\> \</activity\>
I updated android/app/src/main/java/com/mycompany/app/CoronaApplication.java like this:
$ svn diff android/app/src/main/java/com/mycompany/app/CoronaApplication.java Index: android/app/src/main/java/com/mycompany/app/CoronaApplication.java =================================================================== --- android/app/src/main/java/com/mycompany/app/CoronaApplication.java (revision 598) +++ android/app/src/main/java/com/mycompany/app/CoronaApplication.java (working copy) @@ -29,14 +29,20 @@ @Override public void onLoaded(com.ansca.corona.CoronaRuntime runtime) { + com.naef.jnlua.NamedJavaFunction[] luaFunctions; + com.naef.jnlua.LuaState luaState = runtime.getLuaState(); + luaFunctions = new com.naef.jnlua.NamedJavaFunction[] { + new SpaceAboveKeyboard() + }; + luaState.register("SpaceAboveKeyboard", luaFunctions); + luaState.pop(1); } /\*\*
SpaceAboveKeyboard.java looks like this:
package com.mycompany.app; import android.app.Activity; import android.graphics.Rect; import android.view.View; public class SpaceAboveKeyboard implements com.naef.jnlua.NamedJavaFunction { public String getName() { return "calculate"; } public int invoke(com.naef.jnlua.LuaState luaState) { com.ansca.corona.CoronaActivity activity = com.ansca.corona.CoronaEnvironment.getCoronaActivity(); if (activity == null) return 1; Rect r = new Rect(); View rootview = activity.getWindow().getDecorView(); rootview.getWindowVisibleDisplayFrame(r); luaState.pushInteger(r.height()); return 1; } }
Cheers
/Joakim