Documentation
¶
Overview ¶
Package device holds small device controls of mobile apps: asking for a store rating, opening the app's settings page, keeping the screen on, screen brightness, the status bar, and the software keyboard.
device.KeepScreenOn(a, true)
device.SetStatusBar(a, device.StatusBar{Style: device.StatusBarLight})
device.OnKeyboard(a, func(h float64) { ... }) // h = 0: hidden
| | iOS | Android | |---|---|---| | RequestReview | SKStoreReviewController (the system decides whether to show it; never in TestFlight) | opens the Play Store page (market://, else https://play.google.com) | | OpenSettings | UIApplicationOpenSettingsURLString | ACTION_APPLICATION_DETAILS_SETTINGS | | KeepScreenOn | UIApplication.idleTimerDisabled | FLAG_KEEP_SCREEN_ON | | Brightness | UIScreen.brightness (the whole screen, until the device locks) | the window's screenBrightness (only while the app is in front); read: the system setting | | SetStatusBar | the pages' preferredStatusBarStyle / prefersStatusBarHidden; Color: ErrUnsupported | WindowInsetsController appearance / hide; Color fills the bar's background | | keyboard | UIKeyboardWillChangeFrame / WillHide notifications | IME window insets (API 30+; older: 0) |
Every function returns ErrUnsupported on desktop and tango.ErrNotRunning after the app quit.
Index ¶
- Constants
- Variables
- func Brightness(a *tango.App) (float64, error)
- func HideKeyboard(a *tango.App) error
- func KeepScreenOn(a *tango.App, on bool) error
- func KeyboardHeight(a *tango.App) (float64, error)
- func OnKeyboard(a *tango.App, fn func(height float64))
- func OpenSettings(a *tango.App) error
- func RequestReview(a *tango.App) error
- func ResetBrightness(a *tango.App) error
- func SetBrightness(a *tango.App, v float64) error
- func SetStatusBar(a *tango.App, s StatusBar) error
- type StatusBar
- type StatusBarStyle
Constants ¶
const ( StatusBarDefault = platform.StatusBarDefault // follows light/dark mode StatusBarLight = platform.StatusBarLight // white content, for dark pages StatusBarDark = platform.StatusBarDark // dark content, for light pages )
Variables ¶
var ErrUnsupported = platform.ErrUnsupported
Functions ¶
func Brightness ¶
Brightness returns the screen brightness, 0 to 1.
func HideKeyboard ¶
HideKeyboard dismisses the software keyboard.
func KeepScreenOn ¶
KeepScreenOn stops (on) or allows (off) the screen from dimming and locking while the app is in front.
func KeyboardHeight ¶
KeyboardHeight returns the height of the software keyboard in CSS pixels, 0 when hidden.
func OnKeyboard ¶
OnKeyboard calls fn on the main thread when the keyboard appears, disappears (height 0) or changes height. It does nothing where the backend reports no keyboard.
func OpenSettings ¶
OpenSettings opens the app's page in the system settings, e.g. after the user denied a permission.
func RequestReview ¶
RequestReview asks the user to rate the app. Ask at a natural pause, not in response to a button labelled "Rate us" on iOS (the prompt may not appear); Android opens the store page.
func ResetBrightness ¶
ResetBrightness gives the brightness back to the system (Android; on iOS the system restores its own value when the device locks).
func SetBrightness ¶
SetBrightness sets the screen brightness (clamped to 0-1).
Types ¶
type StatusBarStyle ¶
type StatusBarStyle = platform.StatusBarStyle