forked from gomatcha/matcha
/
navigation.go
92 lines (81 loc) · 1.9 KB
/
navigation.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package ios
import (
"fmt"
"image/color"
"golang.org/x/image/colornames"
"gomatcha.io/matcha/bridge"
"gomatcha.io/matcha/paint"
"gomatcha.io/matcha/pointer"
"gomatcha.io/matcha/view"
"gomatcha.io/matcha/view/ios"
)
func init() {
bridge.RegisterFunc("gomatcha.io/matcha/examples/screen New", func() view.View {
stackview1 := ios.NewStackView()
stackview2 := ios.NewStackView()
stackview3 := ios.NewStackView()
stackview4 := ios.NewStackView()
tabview := ios.NewTabView()
app := &NavigationApp{
stack1: stackview1.Stack,
stack2: stackview2.Stack,
stack3: stackview3.Stack,
stack4: stackview4.Stack,
tabs: tabview.Tabs,
}
app.stack1.SetViews(NewNavigationChild(app))
app.stack2.SetViews(NewNavigationChild(app))
app.stack3.SetViews(NewNavigationChild(app))
app.stack4.SetViews(NewNavigationChild(app))
app.tabs.SetViews(stackview1, stackview2, stackview3, stackview4)
return tabview
})
}
type NavigationApp struct {
tabs *ios.Tabs
stack1 *ios.Stack
stack2 *ios.Stack
stack3 *ios.Stack
stack4 *ios.Stack
}
func (app *NavigationApp) CurrentStackView() *ios.Stack {
switch app.tabs.SelectedIndex() {
case 0:
return app.stack1
case 1:
return app.stack2
case 2:
return app.stack3
case 3:
return app.stack4
}
return nil
}
type NavigationChild struct {
view.Embed
app *NavigationApp
Color color.Color
}
func NewNavigationChild(app *NavigationApp) *NavigationChild {
return &NavigationChild{
Color: colornames.White,
app: app,
}
}
func (v *NavigationChild) Build(ctx view.Context) view.Model {
tap := &pointer.TapGesture{
Count: 1,
OnEvent: func(e *pointer.TapEvent) {
child := NewNavigationChild(v.app)
child.Color = colornames.Red
v.app.CurrentStackView().Push(child)
fmt.Println("child", child)
},
}
return view.Model{
Painter: &paint.Style{BackgroundColor: v.Color},
Options: []view.Option{
pointer.GestureList{tap},
},
}
}