app, app/internal: [wasm,android] new Option to set Orientation

Signed-off-by: Inkeliz <inkeliz@inkeliz.com>
This commit is contained in:
Inkeliz
2021-04-23 18:21:58 +01:00
committed by Elias Naur
parent a06a7a4b3c
commit d51d8b46c3
5 changed files with 85 additions and 1 deletions
+22
View File
@@ -35,6 +35,7 @@ type window struct {
requestAnimationFrame js.Value
browserHistory js.Value
visualViewport js.Value
screenOrientation js.Value
cleanfuncs []func()
touches []js.Value
composing bool
@@ -74,6 +75,9 @@ func NewWindow(win Callbacks, opts *Options) error {
if w.visualViewport.IsUndefined() {
w.visualViewport = w.window
}
if screen := w.window.Get("screen"); screen.Truthy() {
w.screenOrientation = screen.Get("orientation")
}
w.chanAnimation = make(chan struct{}, 1)
w.chanRedraw = make(chan struct{}, 1)
w.redraw = w.funcOf(func(this js.Value, args []js.Value) interface{} {
@@ -494,6 +498,9 @@ func (w *window) Option(opts *Options) {
if o := opts.NavigationColor; o != nil {
w.navigationColor(*o)
}
if o := opts.Orientation; o != nil {
w.orientation(*o)
}
}
func (w *window) SetCursor(name pointer.CursorName) {
@@ -591,6 +598,21 @@ func (w *window) windowMode(mode WindowMode) {
}
}
func (w *window) orientation(mode Orientation) {
if j := w.screenOrientation; !j.Truthy() || !j.Get("unlock").Truthy() || !j.Get("lock").Truthy() {
return // Browser don't support Screen Orientation API.
}
switch mode {
case AnyOrientation:
w.screenOrientation.Call("unlock")
case LandscapeOrientation:
w.screenOrientation.Call("lock", "landscape").Call("then", w.redraw)
case PortraitOrientation:
w.screenOrientation.Call("lock", "portrait").Call("then", w.redraw)
}
}
func (w *window) navigationColor(c color.NRGBA) {
theme := w.head.Call("querySelector", `meta[name="theme-color"]`)
if !theme.Truthy() {