diff --git a/app/os_android.go b/app/os_android.go index c56fc10b0..956030639 100644 --- a/app/os_android.go +++ b/app/os_android.go @@ -121,7 +121,6 @@ import "C" import ( "errors" "fmt" - "gioui.org/io/transfer" "image" "image/color" "io" @@ -147,6 +146,7 @@ import ( "gioui.org/io/pointer" "gioui.org/io/semantic" "gioui.org/io/system" + "gioui.org/io/transfer" "gioui.org/unit" ) @@ -527,6 +527,8 @@ func Java_org_gioui_GioView_onStopView(env *C.JNIEnv, class C.jclass, handle C.j w := cgo.Handle(handle).Value().(*window) w.started = false w.visible = false + w.focused = false + w.sendConfigEvent() } @@ -534,6 +536,8 @@ func Java_org_gioui_GioView_onStopView(env *C.JNIEnv, class C.jclass, handle C.j func Java_org_gioui_GioView_onStartView(env *C.JNIEnv, class C.jclass, handle C.jlong) { w := cgo.Handle(handle).Value().(*window) w.started = true + w.focused = true + if w.win != nil { w.setVisible(env) } diff --git a/app/os_ios.go b/app/os_ios.go index 50d21a44f..6883b0733 100644 --- a/app/os_ios.go +++ b/app/os_ios.go @@ -132,6 +132,9 @@ func onCreate(view, controller C.CFTypeRef) { w := &window{ view: view, w: wopts.window, + config: Config{ + Focused: true, + }, } w.loop = newEventLoop(w.w, w.wakeup) w.w.SetDriver(w) @@ -196,13 +199,17 @@ func (w *window) draw(sync bool) { func onStop(h C.uintptr_t) { w := viewFor(h) w.hidden = true + w.config.Focused = false + w.ProcessEvent(ConfigEvent{Config: w.config}) } //export onStart func onStart(h C.uintptr_t) { w := viewFor(h) w.hidden = false + w.config.Focused = true w.draw(true) + w.ProcessEvent(ConfigEvent{Config: w.config}) } //export onDestroy diff --git a/app/window.go b/app/window.go index 3953600d4..6a63ef0cb 100644 --- a/app/window.go +++ b/app/window.go @@ -667,11 +667,15 @@ func (w *Window) processEvent(e event.Event) bool { w.decorations.Config = e2.Config e2.Config = w.effectiveConfig() w.coalesced.cfg = &e2 + + handled := false if f := w.decorations.Config.Focused; f != wasFocused { w.queue.Queue(key.FocusEvent{Focus: f}) + // Ensures focus change is processed on android. + handled = true } - t, handled := w.queue.WakeupTime() - if handled { + t, h := w.queue.WakeupTime() + if handled || h { w.setNextFrame(t) w.updateAnimation() }