I have a TextField in a container (VBox) in the bottom. When i select the TextField to enter some text it gets hidden behind the keyboard (iPhone). I put the VBox in ScrollPane but still the same.
Can i get the keyboard somehow to get its height? How do i place TextFields which are not covered from keyboard?
Thank you for your help.
At this moment, there is no built-in method in JavaFX or JavaFXPorts to get the (native) iOS soft keyboard.
The solution to get the keyboard and find out if any node, like a
TextField
will be covered by it, would require aService
from those available in the Gluon Charm Down library, but for now there is no suchKeyboardService
.Based on native solutions like this, it's easy to get a notification when the keyboard is being shown or hidden. So we could make use of those listeners and send the height value back to the JavaFX layer.
So let's create the
KeyboardService
taking into account how the services are created in the Charm Down library.Since this is a little bit out of scope here, I've created this gist with the required files.
Follow these steps to make it work:
Create a Gluon project (single view) with the latest version of the Gluon plugin for your IDE.
Add the package
com.gluonhq.charm.down.plugins
. Add the classesKeyboardService
(link) andKeyboardServiceFactory
(link).Under the iOS package add the iOS implementation of the service
IOSKeyboardService
(link).Create a
native
folder under/src/ios
and add theKeyboard.h
(link) file:and the
Keyboard.m
(link) file:On a Mac with a recent version of XCode, you can build the native library
libKeyboard.a
. For that you need to add thexcodebuild
task to thebuild.gradle
file of the project (link). It is based on theios-build.gradle
file from Charm Down.Save your project, and run
./gradlew clean build xcodebuild
from command line under the project root.If everything is in place you should find
libKeyboard.a
underbuild/native
. Copy the file, create the folderjniLibs
undersrc/ios
, and paste it there.Add a
TextField
to theBasicView
, and change the alignment toBOTTOM-CENTER
.Implement the service:
You should have everything in place. Plug your iPhone/iPad, and run
./gradlew --info launchIOSDevice
.When the textField gets the focus, the soft keyboard shows up, and the view is translated, so the textField is fully visible:
Hopefully this service will be included in Charm Down at some point. But this is also a good example of how you can add custom services. Also note the Charm Down project is open source, so any contribution is wellcome.