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:
+19
-1
@@ -17,6 +17,7 @@ type keyQueue struct {
|
||||
handlers map[event.Tag]*keyHandler
|
||||
reader ops.Reader
|
||||
state TextInputState
|
||||
hint key.InputHint
|
||||
}
|
||||
|
||||
type keyHandler struct {
|
||||
@@ -24,6 +25,7 @@ type keyHandler struct {
|
||||
// in the current frame.
|
||||
visible bool
|
||||
new bool
|
||||
hint key.InputHint
|
||||
}
|
||||
|
||||
const (
|
||||
@@ -38,6 +40,20 @@ func (q *keyQueue) InputState() TextInputState {
|
||||
return q.state
|
||||
}
|
||||
|
||||
// InputHint returns the input mode from the most recent key.InputOp.
|
||||
func (q *keyQueue) InputHint() (key.InputHint, bool) {
|
||||
if q.focus == nil {
|
||||
return q.hint, false
|
||||
}
|
||||
focused, ok := q.handlers[q.focus]
|
||||
if !ok {
|
||||
return q.hint, false
|
||||
}
|
||||
old := q.hint
|
||||
q.hint = focused.hint
|
||||
return q.hint, old != q.hint
|
||||
}
|
||||
|
||||
func (q *keyQueue) Frame(root *op.Ops, events *handlerEvents) {
|
||||
if q.handlers == nil {
|
||||
q.handlers = make(map[event.Tag]*keyHandler)
|
||||
@@ -108,6 +124,7 @@ func (q *keyQueue) resolveFocus(events *handlerEvents) (focus event.Tag, changed
|
||||
q.handlers[op.Tag] = h
|
||||
}
|
||||
h.visible = true
|
||||
h.hint = op.Hint
|
||||
}
|
||||
}
|
||||
return
|
||||
@@ -118,7 +135,8 @@ func decodeKeyInputOp(d []byte, refs []interface{}) key.InputOp {
|
||||
panic("invalid op")
|
||||
}
|
||||
return key.InputOp{
|
||||
Tag: refs[0].(event.Tag),
|
||||
Tag: refs[0].(event.Tag),
|
||||
Hint: key.InputHint(d[1]),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -102,6 +102,11 @@ func (q *Router) TextInputState() TextInputState {
|
||||
return q.kqueue.InputState()
|
||||
}
|
||||
|
||||
// TextInputHint returns the input mode from the most recent key.InputOp.
|
||||
func (q *Router) TextInputHint() (key.InputHint, bool) {
|
||||
return q.kqueue.InputHint()
|
||||
}
|
||||
|
||||
// WriteClipboard returns the most recent text to be copied
|
||||
// to the clipboard, if any.
|
||||
func (q *Router) WriteClipboard() (string, bool) {
|
||||
|
||||
Reference in New Issue
Block a user