mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-07 18:35:34 +00:00
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:
@@ -30,6 +30,7 @@ type window struct {
|
|||||||
cleanfuncs []func()
|
cleanfuncs []func()
|
||||||
touches []js.Value
|
touches []js.Value
|
||||||
composing bool
|
composing bool
|
||||||
|
requestFocus bool
|
||||||
|
|
||||||
mu sync.Mutex
|
mu sync.Mutex
|
||||||
scale float32
|
scale float32
|
||||||
@@ -130,6 +131,10 @@ func (w *window) addEventListeners() {
|
|||||||
})
|
})
|
||||||
w.addEventListener(w.cnv, "mousedown", func(this js.Value, args []js.Value) interface{} {
|
w.addEventListener(w.cnv, "mousedown", func(this js.Value, args []js.Value) interface{} {
|
||||||
w.pointerEvent(pointer.Press, 0, 0, args[0])
|
w.pointerEvent(pointer.Press, 0, 0, args[0])
|
||||||
|
if w.requestFocus {
|
||||||
|
w.focus()
|
||||||
|
w.requestFocus = false
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
w.addEventListener(w.cnv, "mouseup", func(this js.Value, args []js.Value) interface{} {
|
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.addEventListener(w.cnv, "touchstart", func(this js.Value, args []js.Value) interface{} {
|
||||||
w.touchEvent(pointer.Press, args[0])
|
w.touchEvent(pointer.Press, args[0])
|
||||||
|
if w.requestFocus {
|
||||||
|
w.focus()
|
||||||
|
w.requestFocus = false
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
w.addEventListener(w.cnv, "touchend", func(this js.Value, args []js.Value) interface{} {
|
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() {
|
func (w *window) focus() {
|
||||||
w.tarea.Call("focus")
|
w.tarea.Call("focus")
|
||||||
|
w.requestFocus = true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *window) keyEvent(e js.Value, ks key.State) {
|
func (w *window) keyEvent(e js.Value, ks key.State) {
|
||||||
|
|||||||
Reference in New Issue
Block a user