-
Notifications
You must be signed in to change notification settings - Fork 282
/
pop.go
54 lines (49 loc) · 1.61 KB
/
pop.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
package flutter
import (
"github.com/pkg/errors"
)
// popBehavior defines how an application should handle the navigation pop
// event from the flutter side.
type popBehavior int
const (
// PopBehaviorNone means the system navigation pop event is ignored.
PopBehaviorNone popBehavior = iota
// PopBehaviorHide hides the application window on a system navigation pop
// event.
PopBehaviorHide
// PopBehaviorIconify minimizes/iconifies the application window on a system
// navigation pop event.
PopBehaviorIconify
// PopBehaviorClose closes the application on a system navigation pop event.
PopBehaviorClose
)
// PopBehavior sets the PopBehavior on the application
func PopBehavior(p popBehavior) Option {
return func(c *config) {
// TODO: this is a workarround because there is no renderer interface
// yet. We rely on a platform plugin singleton to handle events from the
// flutter side. Should go via Application and renderer abstraction
// layer.
//
// Downside of this workarround is that it will configure the pop
// behavior for all Application's within the same Go process.
defaultPlatformPlugin.popBehavior = p
}
}
func (p *platformPlugin) handleSystemNavigatorPop(arguments interface{}) (reply interface{}, err error) {
switch p.popBehavior {
case PopBehaviorNone:
return nil, nil
case PopBehaviorHide:
p.window.Hide()
return nil, nil
case PopBehaviorIconify:
p.window.Iconify()
return nil, nil
case PopBehaviorClose:
p.window.SetShouldClose(true)
return nil, nil
default:
return nil, errors.Errorf("unknown pop behavior %T not implemented by platform handler", p.popBehavior)
}
}