forked from joejulian/gio
app, io: [wasm, android] add support for numeric/email keyboard mode
Previously, the on-screen keyboard always displays the text keyboard, (QWERTY or equivalent). For optimal user experience, it's possible to specify the keyboard type using `InputHint`. The on-screen keyboard will provide shortcuts or restrict what the user can input. Due to some limitations (gio#116), only numeric and text keyboards are supported on Android. Signed-off-by: Inkeliz <inkeliz@inkeliz.com>
This commit is contained in:
@@ -313,6 +313,27 @@ func (w *window) focus() {
|
||||
w.requestFocus = true
|
||||
}
|
||||
|
||||
func (w *window) keyboard(hint key.InputHint) {
|
||||
var m string
|
||||
switch hint {
|
||||
case key.HintAny:
|
||||
m = "text"
|
||||
case key.HintText:
|
||||
m = "text"
|
||||
case key.HintNumeric:
|
||||
m = "decimal"
|
||||
case key.HintEmail:
|
||||
m = "email"
|
||||
case key.HintURL:
|
||||
m = "url"
|
||||
case key.HintTelephone:
|
||||
m = "tel"
|
||||
default:
|
||||
m = "text"
|
||||
}
|
||||
w.tarea.Set("inputMode", m)
|
||||
}
|
||||
|
||||
func (w *window) keyEvent(e js.Value, ks key.State) {
|
||||
k := e.Get("key").String()
|
||||
if n, ok := translateKey(k); ok {
|
||||
@@ -524,6 +545,10 @@ func (w *window) ShowTextInput(show bool) {
|
||||
}()
|
||||
}
|
||||
|
||||
func (w *window) SetInputHint(mode key.InputHint) {
|
||||
w.keyboard(mode)
|
||||
}
|
||||
|
||||
// Close the window. Not implemented for js.
|
||||
func (w *window) Close() {}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user