From e195309d553c315df7bc8967f83f66a811d21701 Mon Sep 17 00:00:00 2001 From: Inkeliz Date: Sat, 21 Nov 2020 03:44:34 +0000 Subject: [PATCH] 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 --- app/internal/window/os_js.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/app/internal/window/os_js.go b/app/internal/window/os_js.go index 718dbe75..60768b6a 100644 --- a/app/internal/window/os_js.go +++ b/app/internal/window/os_js.go @@ -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) {