example/network: rewrite to use event loop
Change-Id: Ibcf8fa9aec7327e98d4a0cdb5c37bb39bcc41bf8
Reviewed-on: https://go-review.googlesource.com/12278
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
diff --git a/example/network/main.go b/example/network/main.go
index 287f628..2417e3c 100644
--- a/example/network/main.go
+++ b/example/network/main.go
@@ -41,7 +41,9 @@
"net/http"
"golang.org/x/mobile/app"
+ "golang.org/x/mobile/event"
"golang.org/x/mobile/event/config"
+ "golang.org/x/mobile/event/paint"
"golang.org/x/mobile/exp/app/debug"
"golang.org/x/mobile/gl"
)
@@ -50,8 +52,17 @@
// checkNetwork runs only once when the app first loads.
go checkNetwork()
- app.Run(app.Callbacks{
- Draw: onDraw,
+ app.Main(func(a app.App) {
+ var c config.Event
+ for e := range a.Events() {
+ switch e := event.Filter(e).(type) {
+ case config.Event:
+ c = e
+ case paint.Event:
+ onDraw(c)
+ a.EndPaint()
+ }
+ }
})
}