device
import "github.com/tangoui/tango/sys/device"本页由
site/tools/apigen从源码注释生成(按 darwin 构建标签选文件),请勿手改。
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.
常量
const (
StatusBarDefault = platform.StatusBarDefault // follows light/dark mode
StatusBarLight = platform.StatusBarLight // white content, for dark pages
StatusBarDark = platform.StatusBarDark // dark content, for light pages
)变量
var ErrUnsupported = platform.ErrUnsupported函数
func Brightness
func Brightness(a *tango.App) (float64, error)Brightness returns the screen brightness, 0 to 1.
func HideKeyboard
func HideKeyboard(a *tango.App) errorHideKeyboard dismisses the software keyboard.
func KeepScreenOn
func KeepScreenOn(a *tango.App, on bool) errorKeepScreenOn stops (on) or allows (off) the screen from dimming and locking while the app is in front.
func KeyboardHeight
func KeyboardHeight(a *tango.App) (float64, error)KeyboardHeight returns the height of the software keyboard in CSS pixels, 0 when hidden.
func OnKeyboard
func OnKeyboard(a *tango.App, fn func(height float64))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
func OpenSettings(a *tango.App) errorOpenSettings opens the app's page in the system settings, e.g. after the user denied a permission.
func RequestReview
func RequestReview(a *tango.App) errorRequestReview 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
func ResetBrightness(a *tango.App) errorResetBrightness gives the brightness back to the system (Android; on iOS the system restores its own value when the device locks).
func SetBrightness
func SetBrightness(a *tango.App, v float64) errorSetBrightness sets the screen brightness (clamped to 0-1).
func SetStatusBar
func SetStatusBar(a *tango.App, s StatusBar) errorSetStatusBar sets the status bar's content style, visibility and (Android) background color.
类型
StatusBar
type StatusBar = platform.StatusBarStatusBar describes how the status bar looks.
StatusBarStyle
type StatusBarStyle = platform.StatusBarStyle