app/internal/window: mitigate keyboard issue on WASM iOS

That change mitigates the issue gio#150 and gio#166. The
iOS can only `focus()` as a response to touchstart/click
events. We can't `focus()` at random, without user interaction.

The `w.requestFocus` will try to focus on the next `touchstart`,
which may need some "double click" in some cases. That mitigates
the issue, but doesn't fixes completely, but open the keyboard. (:

I didn't notice any side-effect of that change on Android and on
Windows.

Signed-off-by: Inkeliz <inkeliz@inkeliz.com>
This commit is contained in:
Inkeliz
2020-11-21 03:44:34 +00:00
committed by Elias Naur
parent fb15547b7a
commit e195309d55
+10
View File
@@ -30,6 +30,7 @@ type window struct {
cleanfuncs []func()
touches []js.Value
composing bool
requestFocus bool
mu sync.Mutex
scale float32
@@ -130,6 +131,10 @@ func (w *window) addEventListeners() {
})
w.addEventListener(w.cnv, "mousedown", func(this js.Value, args []js.Value) interface{} {
w.pointerEvent(pointer.Press, 0, 0, args[0])
if w.requestFocus {
w.focus()
w.requestFocus = false
}
return nil
})
w.addEventListener(w.cnv, "mouseup", func(this js.Value, args []js.Value) interface{} {
@@ -153,6 +158,10 @@ func (w *window) addEventListeners() {
})
w.addEventListener(w.cnv, "touchstart", func(this js.Value, args []js.Value) interface{} {
w.touchEvent(pointer.Press, args[0])
if w.requestFocus {
w.focus()
w.requestFocus = false
}
return nil
})
w.addEventListener(w.cnv, "touchend", func(this js.Value, args []js.Value) interface{} {
@@ -221,6 +230,7 @@ func (w *window) blur() {
func (w *window) focus() {
w.tarea.Call("focus")
w.requestFocus = true
}
func (w *window) keyEvent(e js.Value, ks key.State) {