Skip to content

device ​

go
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.

常量 ​

go
const (
	StatusBarDefault = platform.StatusBarDefault // follows light/dark mode
	StatusBarLight   = platform.StatusBarLight   // white content, for dark pages
	StatusBarDark    = platform.StatusBarDark    // dark content, for light pages
)

变量 ​

go
var ErrUnsupported = platform.ErrUnsupported

函数 ​

func Brightness ​

go
func Brightness(a *tango.App) (float64, error)

Brightness returns the screen brightness, 0 to 1.

func HideKeyboard ​

go
func HideKeyboard(a *tango.App) error

HideKeyboard dismisses the software keyboard.

func KeepScreenOn ​

go
func KeepScreenOn(a *tango.App, on bool) error

KeepScreenOn stops (on) or allows (off) the screen from dimming and locking while the app is in front.

func KeyboardHeight ​

go
func KeyboardHeight(a *tango.App) (float64, error)

KeyboardHeight returns the height of the software keyboard in CSS pixels, 0 when hidden.

func OnKeyboard ​

go
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 ​

go
func OpenSettings(a *tango.App) error

OpenSettings opens the app's page in the system settings, e.g. after the user denied a permission.

func RequestReview ​

go
func RequestReview(a *tango.App) error

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 ​

go
func ResetBrightness(a *tango.App) error

ResetBrightness gives the brightness back to the system (Android; on iOS the system restores its own value when the device locks).

func SetBrightness ​

go
func SetBrightness(a *tango.App, v float64) error

SetBrightness sets the screen brightness (clamped to 0-1).

func SetStatusBar ​

go
func SetStatusBar(a *tango.App, s StatusBar) error

SetStatusBar sets the status bar's content style, visibility and (Android) background color.

类型 ​

StatusBar ​

go
type StatusBar = platform.StatusBar

StatusBar describes how the status bar looks.

StatusBarStyle ​

go
type StatusBarStyle = platform.StatusBarStyle

以 MIT 许可发布