safearea
import "github.com/tangoui/tango/sys/safearea"本页由
site/tools/apigen从源码注释生成(按 darwin 构建标签选文件),请勿手改。
Package safearea reports the parts of a page covered by system UI (status bar, notch / Dynamic Island, home indicator, navigation bar) and follows their changes, e.g. on rotation.
in, err := safearea.Get(a)
safearea.OnChange(a, func(in safearea.Insets) { ... })
SyncPage mirrors the insets into every page as CSS variables on <html>:
--tango-safe-top, --tango-safe-bottom, --tango-safe-left, --tango-safe-right
for pages that cannot rely on env(safe-area-inset-*) (Android WebView, which reports 0 there, older engines, values needed in JS). Use them with env() as the fallback:
padding-top: var(--tango-safe-top, env(safe-area-inset-top, 0px));
Insets are in CSS pixels relative to the page's web view. On iOS a page fills the screen; the values matter once the page opts into viewport-fit=cover (otherwise WKWebView insets the content itself, and padding by them again would double it). The Android host keeps pages clear of system bars, so they are normally zero there.
Get returns ErrUnsupported on desktop and tango.ErrNotRunning after the app quit.
变量
var ErrUnsupported = platform.ErrUnsupported函数
func OnChange
func OnChange(a *tango.App, fn func(Insets))OnChange calls fn on the main thread with the new insets whenever they change. It does nothing where the backend has no safe area.
func SyncPage
func SyncPage(a *tango.App) errorSyncPage keeps the --tango-safe-* CSS variables of every page current. Pages can also listen for the "tangosafearea" event on window, whose detail is {top, bottom, left, right}. Call it before creating surfaces (it adds a bridge script). It returns ErrUnsupported (and installs nothing) where the backend has no safe area.
类型
Insets
type Insets = platform.InsetsInsets in CSS pixels.
func Get
func Get(a *tango.App) (Insets, error)Get returns the current insets.