Skip to content

mobile 实验性 ​

实验性

本包属于实验层:任何 0.x 版本都可能有不兼容变化(docs/release.md「API 稳定性」)。

go
import "github.com/tangoui/tango/ui/mobile"

本页由 site/tools/apigen 从源码注释生成(按 darwin 构建标签选文件),请勿手改。

Package mobile provides touch-first widgets for the Tango self-drawn UI in the visual language of Ant Design Mobile (default), Vant and a mobile derivation of shadcn/ui (Shadcn: chosen automatically under a theme.Shadcn ui theme; Drawer-style bottom sheets with a grab handle, grouped action sheet cards, Sonner toasts, segmented tabs): NavBar, TabBar, List/Cell, SwipeCell, PullToRefresh, InfiniteList, ActionSheet, Popup, Dialog, Toast, Picker (cascade, date/time), Stepper, SearchBar, Tabs, Swiper, Grid, NoticeBar, Skeleton, Empty, Result, Badge, Tag, Button, Form, IndexBar, FloatingBubble and SafeArea.

Gestures (tap, long press, swipe with direction and speed, drag, inertial scrolling, rubber-band edges) are recognized from the ui layer's pointer events by a gesture arena (see Area and Touchable); pinch comes from the ui layer's multi-touch events (input.TouchEvent). Drags that start on plain ui widgets inside a scroll view or swipe cell are handed to the container by the ui layer's pointer takeover. The scroll physics (Scroller) and recognizers (Track, PinchRecognizer, RefreshMachine) are pure types usable on their own. Long lists of fixed-height rows build only the visible rows with ScrollViewW.Rows.

Under a high-contrast ui theme (theme.HighContrast) the mobile neutrals are lifted to WCAG AA like the ui theme's (NewTheme).

Components read ConfigProvider defaults under "mobile.<Component>" names (ui.ConfigProvider(c).Defaults("mobile.Button", ui.Props{"size": "large"})); explicit modifiers win. Each constructor documents its keys.

On iOS and Android the widgets run in a self-drawn canvas page that uihost.Open shows natively (touch, safe area, keyboard, input methods and accessibility come from the platform; see docs/specs/mobile-canvas.md and examples/mobile-ui). On the desktop they run in any uihost window.

Wrap a mobile page in Provider to pick the design style and safe area:

mobile.Provider(c, mobile.Options{Style: mobile.Vant}, func() {
	mobile.NavBar(c, "标题").Back("")
	mobile.ScrollView(c).Layout(layout.Grow(1)).Body(func() { ... })
	mobile.TabBar(c, tabs, &active)
})

Experimental: this package's API may change in any 0.x release (see docs/release.md, "API 稳定性").

常量 ​

go
const (
	// DecelerationRate is the fraction of velocity kept per millisecond of
	// a fling (iOS "normal" deceleration).
	DecelerationRate = 0.998
	// RubberBand is the resistance of dragging past an edge: the content
	// follows by dim·(1 − 1/(d·RubberBand/dim + 1)).
	RubberBand = 0.55
	// SpringOmega is the angular frequency (1/s) of the critically damped
	// spring that pulls an over-scrolled view back to its edge.
	SpringOmega = 13.0
)

Physics constants of the scroll model.

go
const (
	TouchSlop        = 8                      // px a finger may wander before a tap becomes a drag
	LongPressDelay   = 500 * time.Millisecond // hold time of a long press
	SwipeMinVelocity = 250                    // px/s for a release to count as a swipe (flick)
	SwipeMinDistance = 30                     // px of travel that counts as a swipe at any speed

)

Gesture thresholds.

函数 ​

func Badge ​

go
func Badge(c *ui.Context, content string, fn func()) *ui.Box

Badge wraps content with a badge at its top-end corner (top right; top left in RTL): content is the text ("99+"), "dot" for a dot, or "" for none.

func ClearToast ​

go
func ClearToast(c *ui.Context)

ClearToast hides the imperative toast.

func Decay ​

go
func Decay(p0, v0, t float64) (p, v float64)

Decay returns the position and velocity t seconds into a fling that started at p0 with velocity v0 (px/s).

func DecayTarget ​

go
func DecayTarget(p0, v0 float64) float64

DecayTarget is where a fling from p0 with velocity v0 comes to rest.

func DrawBadge ​

go
func DrawBadge(l *paint.List, th *Theme, s string, cx, cy float32)

DrawBadge paints a badge centred at (cx, cy): s is the count text, "" or "dot" for a dot. Use it in custom painters (avatars, icons).

func Provider ​

go
func Provider(c *ui.Context, o Options, fn func())

Provider runs fn with the mobile options o (design style, safe area) and then renders imperative toasts queued with ShowToast. Wrap a mobile page in one Provider; without it components use the Ant Design Mobile style.

func Rubber ​

go
func Rubber(d, dim float64) float64

Rubber maps an overshoot d (px past the edge, ≥ 0) to the displayed overshoot for a viewport of size dim.

func RubberInverse ​

go
func RubberInverse(v, dim float64) float64

RubberInverse is the inverse of Rubber: the finger overshoot that displays as v.

func SafeArea ​

go
func SafeArea(c *ui.Context, edge Edge) *ui.Box

SafeArea adds a blank of the safe-area inset of edge (Top: status bar / notch, Bottom: home indicator), filled with the box color.

func SafeAreaInsets ​

go
func SafeAreaInsets(c *ui.Context) geom.Insets

SafeAreaInsets returns the insets in effect: the innermost Provider override, else the window's (ui.Context.SafeArea).

func ShowToast ​

go
func ShowToast(c *ui.Context, msg string, o ...ToastOptions)

ShowToast shows msg as a toast from event-handling code (replacing the current one). It is drawn by the enclosing Provider.

func Spring ​

go
func Spring(x0, v0, omega, t float64) (x, v float64)

Spring returns the displacement and velocity t seconds after a critically damped spring was released at displacement x0 with velocity v0 (target is 0).

func Within ​

go
func Within(c *ui.Context, id ui.ID, fn func())

Within builds fn as the content of area id: touchables and areas created inside attach to it.

类型 ​

Action ​

go
type Action struct {
	Key         string
	Text        string
	Description string
	Danger      bool
	Bold        bool
	Disabled    bool
}

Action is one entry of an ActionSheet.

ActionSheetW ​

go
type ActionSheetW struct {
	// contains filtered or unexported fields
}

ActionSheetW is a bottom menu of actions.

func ActionSheet ​

go
func ActionSheet(c *ui.Context, open *bool, actions []Action) *ActionSheetW

ActionSheet opens a bottom action menu bound to *open. It renders when Show is called (after options) and closes after a selection. In the shadcn style the actions sit in an outlined rounded card floating above the bottom edge, the cancel button in a second card below.

ConfigProvider defaults ("mobile.ActionSheet"): "cancelText" (string, shows the cancel button), "closeOnMaskClick" (bool).

func (*ActionSheetW) Cancel ​

go
func (w *ActionSheetW) Cancel(s string) *ActionSheetW

Cancel adds a separated cancel button ("" uses the localized "取消").

func (*ActionSheetW) Cancelled ​

go
func (w *ActionSheetW) Cancelled() bool

Cancelled reports a tap on the cancel button or the mask this frame.

func (*ActionSheetW) Extra ​

go
func (w *ActionSheetW) Extra(s string) *ActionSheetW

Extra shows a caption above the actions.

func (*ActionSheetW) Selected ​

go
func (w *ActionSheetW) Selected() (int, bool)

Selected returns the index of the action tapped this frame.

func (*ActionSheetW) Show ​

go
func (w *ActionSheetW) Show() *ActionSheetW

Show renders the sheet.

Axis ​

go
type Axis uint8

Axis is the set of drag directions an area accepts.

go
const (
	AxisNone       Axis = 0
	AxisHorizontal Axis = 1 << 0
	AxisVertical   Axis = 1 << 1
	AxisBoth            = AxisHorizontal | AxisVertical
)

ButtonW ​

go
type ButtonW struct {
	// contains filtered or unexported fields
}

ButtonW is a touch button sized for fingers.

func Button ​

go
func Button(c *ui.Context, label string) *ButtonW

Button adds a button labelled label. In the shadcn style the default color is the outline variant, "primary" the near-black default variant and "danger" the destructive one, with medium-weight labels and h-11 (Middle) touch heights.

ConfigProvider defaults ("mobile.Button"): "size" ("mini", "small", "middle", "large", a mobile.Size or a ui.ControlSize; otherwise the ConfigProvider size), "shape" ("round" or "default"), "fill" ("solid", "outline", "none"), "color" (string), "block" (bool).

func (*ButtonW) A11yLabel ​

go
func (w *ButtonW) A11yLabel(s string) *ButtonW

A11yLabel sets the accessible name (icon-only buttons).

func (*ButtonW) Block ​

go
func (w *ButtonW) Block() *ButtonW

Block stretches the button to the full width.

func (*ButtonW) Clicked ​

go
func (w *ButtonW) Clicked() bool

Clicked reports a tap this frame.

func (*ButtonW) Color ​

go
func (w *ButtonW) Color(s string) *ButtonW

Color sets the color: "default", "primary", "success", "warning", "danger".

func (*ButtonW) Danger ​

go
func (w *ButtonW) Danger() *ButtonW

Danger is Color("danger").

func (*ButtonW) Disabled ​

go
func (w *ButtonW) Disabled(on bool) *ButtonW

Disabled greys the button out.

func (*ButtonW) Fill ​

go
func (w *ButtonW) Fill(s string) *ButtonW

Fill sets "solid" (default), "outline" or "none".

func (*ButtonW) ID ​

go
func (w *ButtonW) ID() ui.ID

ID returns the button's ID.

func (*ButtonW) Icon ​

go
func (w *ButtonW) Icon(ic *icon.Icon) *ButtonW

Icon adds a leading icon.

func (*ButtonW) Layout ​

go
func (w *ButtonW) Layout(opts ...layout.Option) *ButtonW

Layout applies layout options.

func (*ButtonW) Loading ​

go
func (w *ButtonW) Loading(on bool) *ButtonW

Loading shows a spinner and ignores taps.

func (*ButtonW) Primary ​

go
func (w *ButtonW) Primary() *ButtonW

Primary is Color("primary").

func (*ButtonW) Round ​

go
func (w *ButtonW) Round() *ButtonW

Round makes the ends fully rounded.

func (*ButtonW) Size ​

go
func (w *ButtonW) Size(s Size) *ButtonW

Size sets the size.

CellW ​

go
type CellW struct {
	// contains filtered or unexported fields
}

CellW is a list row: optional icon, title with description, value at the end, arrow, or switch (the end is the right; the left in RTL, where the arrow points left).

func Cell ​

go
func Cell(c *ui.Context, title string) *CellW

Cell adds a list row titled title.

ConfigProvider defaults ("mobile.Cell"): "arrow", "clickable" (bool).

func (*CellW) Arrow ​

go
func (w *CellW) Arrow() *CellW

Arrow shows the navigation arrow and pressed feedback.

func (*CellW) Changed ​

go
func (w *CellW) Changed() bool

Changed reports a switch toggle this frame.

func (*CellW) Clickable ​

go
func (w *CellW) Clickable() *CellW

Clickable shows pressed feedback without an arrow.

func (*CellW) Clicked ​

go
func (w *CellW) Clicked() bool

Clicked reports a tap on the row (not on its switch).

func (*CellW) Desc ​

go
func (w *CellW) Desc(s string) *CellW

Desc shows a description line under the title.

func (*CellW) Disabled ​

go
func (w *CellW) Disabled(on bool) *CellW

Disabled greys the row out and ignores taps.

func (*CellW) Extra ​

go
func (w *CellW) Extra(s string) *CellW

Extra shows a value at the end.

func (*CellW) ID ​

go
func (w *CellW) ID() ui.ID

ID returns the row's ID.

func (*CellW) Icon ​

go
func (w *CellW) Icon(ic *icon.Icon) *CellW

Icon shows an icon before the title.

func (*CellW) LongPressed ​

go
func (w *CellW) LongPressed() bool

LongPressed reports a long press on the row.

func (*CellW) Required ​

go
func (w *CellW) Required() *CellW

Required marks the title with a red asterisk (forms).

func (*CellW) Switch ​

go
func (w *CellW) Switch(on *bool) *CellW

Switch shows a switch bound to *on; tapping it toggles.

DatePrecision ​

go
type DatePrecision uint8

DatePrecision is the finest column of a date picker.

go
const (
	PrecisionYear DatePrecision = iota
	PrecisionMonth
	PrecisionDay
	PrecisionHour
	PrecisionMinute
)

DialogW ​

go
type DialogW struct {
	// contains filtered or unexported fields
}

DialogW is a centred modal with a title, message and buttons.

func Dialog ​

go
func Dialog(c *ui.Context, open *bool, title string) *DialogW

Dialog creates a modal dialog bound to *open. By default it is an alert with one acknowledge button; Confirm adds a cancel button. Call Show (or a query) after the options.

In the shadcn style the dialog follows AlertDialog on small screens: an outlined card with a centred title, a muted message and full-width stacked buttons (solid confirm above an outline cancel).

ConfigProvider defaults ("mobile.Dialog"): "closeOnMaskClick" (bool), "confirmText" (string, the acknowledge / OK text), "cancelText" (string, used by Confirm when it gets "").

func (*DialogW) Cancelled ​

go
func (w *DialogW) Cancelled() bool

Cancelled reports a cancel this frame (button or mask).

func (*DialogW) CloseOnMask ​

go
func (w *DialogW) CloseOnMask() *DialogW

CloseOnMask lets a mask tap dismiss the dialog (cancel).

func (*DialogW) Confirm ​

go
func (w *DialogW) Confirm(ok, cancel string) *DialogW

Confirm turns the dialog into a confirm box with OK / Cancel buttons ("" keeps the localized texts).

func (*DialogW) Confirmed ​

go
func (w *DialogW) Confirmed() bool

Confirmed reports a tap on the OK / acknowledge button this frame.

func (*DialogW) Content ​

go
func (w *DialogW) Content(s string) *DialogW

Content sets the message.

func (*DialogW) Custom ​

go
func (w *DialogW) Custom(fn func()) *DialogW

Custom builds custom content under the message.

func (*DialogW) OKText ​

go
func (w *DialogW) OKText(s string) *DialogW

OKText sets the acknowledge button text of an alert.

func (*DialogW) PanelID ​

go
func (w *DialogW) PanelID() ui.ID

PanelID returns the ID of the dialog panel (0 while closed).

func (*DialogW) Show ​

go
func (w *DialogW) Show() *DialogW

Show renders the dialog.

Direction ​

go
type Direction uint8

Direction is the dominant direction of a movement.

go
const (
	DirNone Direction = iota
	DirLeft
	DirRight
	DirUp
	DirDown
)

func DirectionOf ​

go
func DirectionOf(v geom.Point) Direction

DirectionOf returns the dominant direction of v.

func (Direction) Horizontal ​

go
func (d Direction) Horizontal() bool

Horizontal reports whether d is left or right.

func (Direction) String ​

go
func (d Direction) String() string

Edge ​

go
type Edge uint8

Edge selects a side of the screen.

go
const (
	Top Edge = iota
	Bottom
	Left
	Right
)

EmptyW ​

go
type EmptyW struct {
	// contains filtered or unexported fields
}

EmptyW is an empty-state placeholder.

func Empty ​

go
func Empty(c *ui.Context) *EmptyW

Empty adds an empty state with the localized "暂无数据" (shadcn: an icon on a muted tile above the muted caption).

ConfigProvider defaults ("mobile.Empty"): "description" (string).

func (*EmptyW) Description ​

go
func (w *EmptyW) Description(s string) *EmptyW

Description replaces the caption.

FieldW ​

go
type FieldW struct {
	// contains filtered or unexported fields
}

FieldW is a borderless single-line text input for forms and cells.

func Field ​

go
func Field(c *ui.Context, val *string) *FieldW

Field adds a borderless text input bound to *val. It reuses ui.Input (editing, IME, clipboard) and hides its frame.

ConfigProvider defaults ("mobile.Field"): "clearable" (bool), "maxLength" (int), "placeholder" (string).

func (*FieldW) Changed ​

go
func (w *FieldW) Changed() bool

Changed reports an edit this frame.

func (*FieldW) EnterKey ​

go
func (w *FieldW) EnterKey(k input.EnterKey) *FieldW

EnterKey labels the soft keyboard's return key (input.EnterNext, input.EnterDone, …); pressing it still reports Submitted.

func (*FieldW) Input ​

go
func (w *FieldW) Input() *ui.InputW

Input returns the underlying ui.InputW.

func (*FieldW) MaxLength ​

go
func (w *FieldW) MaxLength(n int) *FieldW

MaxLength limits the length.

func (*FieldW) Password ​

go
func (w *FieldW) Password() *FieldW

Password masks the text.

func (*FieldW) Placeholder ​

go
func (w *FieldW) Placeholder(s string) *FieldW

Placeholder sets the hint text.

func (*FieldW) Submitted ​

go
func (w *FieldW) Submitted() bool

Submitted reports Enter.

func (*FieldW) Type ​

go
func (w *FieldW) Type(k input.TextKind) *FieldW

Type tells the soft keyboard what the field holds (input.TextNumber, input.TextEmail, input.TextPhone, …): its layout and suggestions. input.TextPassword also masks the text.

FloatingBubbleW ​

go
type FloatingBubbleW struct {
	// contains filtered or unexported fields
}

FloatingBubbleW is a draggable round button that floats over the page and sticks to the nearest side when released.

func FloatingBubble ​

go
func FloatingBubble(c *ui.Context, ic *icon.Icon, axis Axis, magnetic bool) *FloatingBubbleW

FloatingBubble adds a floating bubble showing ic. axis limits dragging (AxisBoth by default); magnetic snaps it to the left or right edge. It starts in the bottom end corner (bottom right; bottom left in RTL).

ConfigProvider defaults ("mobile.FloatingBubble"): "size" (number, at least the 44pt touch minimum; default 48).

func (*FloatingBubbleW) A11yLabel ​

go
func (w *FloatingBubbleW) A11yLabel(s string) *FloatingBubbleW

A11yLabel sets the accessible name of the bubble (it shows an icon only).

func (*FloatingBubbleW) Clicked ​

go
func (w *FloatingBubbleW) Clicked() bool

Clicked reports a tap on the bubble.

FormItemW ​

go
type FormItemW struct {
	// contains filtered or unexported fields
}

FormItemW is one labelled field of a Form.

func FormItem ​

go
func FormItem(c *ui.Context, label string) *FormItemW

FormItem starts a labelled field; build the control in Body.

func (*FormItemW) Arrow ​

go
func (w *FormItemW) Arrow() *FormItemW

Arrow shows a navigation arrow (pickers opened from the row).

func (*FormItemW) Body ​

go
func (w *FormItemW) Body(fn func()) *FormItemW

Body builds the field control.

func (*FormItemW) Clicked ​

go
func (w *FormItemW) Clicked() bool

Clicked reports a tap on the row (open a picker from an Arrow item).

func (*FormItemW) Error ​

go
func (w *FormItemW) Error(msg string) *FormItemW

Error shows a validation message under the field ("" for none).

func (*FormItemW) Help ​

go
func (w *FormItemW) Help(s string) *FormItemW

Help shows a hint under the field.

func (*FormItemW) Required ​

go
func (w *FormItemW) Required() *FormItemW

Required marks the label with an asterisk.

FormW ​

go
type FormW struct {
	// contains filtered or unexported fields
}

FormW lays out labelled fields in a white group, labels on the left (default) or on top.

func Form ​

go
func Form(c *ui.Context) *FormW

Form starts a mobile form; add FormItems in Body.

ConfigProvider defaults ("mobile.Form"): "layout" ("horizontal" or "vertical"), "mode" ("default" or "card").

func (*FormW) Body ​

go
func (w *FormW) Body(fn func())

Body builds the items.

func (*FormW) Card ​

go
func (w *FormW) Card() *FormW

Card insets the group with rounded corners.

func (*FormW) Header ​

go
func (w *FormW) Header(s string) *FormW

Header shows a group caption.

func (*FormW) Vertical ​

go
func (w *FormW) Vertical() *FormW

Vertical puts labels above their fields.

Gesture ​

go
type Gesture struct {
	ID         ui.ID
	Pan        Pan
	Tap        bool // a tap landed inside the area (bubbles from touchables)
	TapPos     geom.Point
	LongPress  bool
	LongPos    geom.Point
	TouchStart bool // a finger went down inside the area this frame
	Outside    bool // a finger went down outside the area this frame
	Swipe      Swipe
	Swiped     bool // the drag owned by this area ended as a swipe
	Pinch      Pinch
}

Gesture is the per-frame gesture state of an area.

func Area ​

go
func Area(c *ui.Context, b *ui.Box, axis Axis, accept func(Direction) bool) Gesture

Area makes box b a gesture area accepting drags along axis (accept, if non-nil, can refuse a direction at claim time) and returns its state. Build the area's content with Within so nested touchables and areas attach to it.

GridItem ​

go
type GridItem struct {
	Text  string
	Icon  *icon.Icon
	Badge string // "", "dot" or count text
}

GridItem is one cell of a Grid.

GridW ​

go
type GridW struct {
	// contains filtered or unexported fields
}

GridW is a grid of icon + text entries.

func Grid ​

go
func Grid(c *ui.Context, cols int, items []GridItem) *GridW

Grid adds a grid of items in cols columns. In the shadcn style the icons sit on muted rounded-xl tiles and cells have no separators.

ConfigProvider defaults ("mobile.Grid"): "bordered" (bool).

func (*GridW) Border ​

go
func (w *GridW) Border(on bool) *GridW

Border toggles cell separators.

func (*GridW) Clicked ​

go
func (w *GridW) Clicked() (int, bool)

Clicked returns the index tapped this frame.

IndexBarW ​

go
type IndexBarW struct {
	// contains filtered or unexported fields
}

IndexBarW is a grouped list with an alphabet index at the end (on the right; on the left in RTL): tap or drag along the index to jump to a group. The current group's title sticks to the top.

func IndexBar ​

go
func IndexBar(c *ui.Context, indexes []string) *IndexBarW

IndexBar creates an index bar for groups titled indexes.

func (*IndexBarW) Body ​

go
func (w *IndexBarW) Body(group func(i int)) *IndexBarW

Body builds the groups; group(i) builds the rows of group i.

func (*IndexBarW) Layout ​

go
func (w *IndexBarW) Layout(opts ...layout.Option) *IndexBarW

Layout applies layout options to the container (give it a height).

ListW ​

go
type ListW struct {
	// contains filtered or unexported fields
}

ListW is a group of cells with an optional header.

func List ​

go
func List(c *ui.Context, header string) *ListW

List starts a cell group titled header ("" for none); add cells in Body.

ConfigProvider defaults ("mobile.List"): "mode" ("default" or "card").

func (*ListW) Body ​

go
func (w *ListW) Body(fn func())

Body builds the cells.

func (*ListW) Card ​

go
func (w *ListW) Card() *ListW

Card insets the group with rounded corners (Ant Mobile mode="card", Vant inset).

func (*ListW) Layout ​

go
func (w *ListW) Layout(opts ...layout.Option) *ListW

Layout applies layout options to the outer box.

go
type NavBarW struct {
	// contains filtered or unexported fields
}

NavBarW is the top navigation bar: back arrow and text at the start (left; right in RTL, the arrow mirrored to point right), centred title, text or icon at the end.

go
func NavBar(c *ui.Context, title string) *NavBarW

NavBar adds a navigation bar titled title.

ConfigProvider defaults ("mobile.NavBar"): "bordered" (bool).

go
func (w *NavBarW) Back(text string) *NavBarW

Back shows the back arrow with optional text (Ant Mobile shows the arrow only by default; Vant styles typically pass "返回").

go
func (w *NavBarW) BackClicked() bool

BackClicked reports a tap on the back area.

go
func (w *NavBarW) Border(on bool) *NavBarW

Border toggles the bottom hairline (Vant and shadcn default on, Ant Mobile off).

go
func (w *NavBarW) ID() ui.ID

ID returns the bar's ID.

go
func (w *NavBarW) Right(text string) *NavBarW

Right shows a text action at the end (right; left in RTL).

go
func (w *NavBarW) RightClicked() bool

RightClicked reports a tap on the right action.

go
func (w *NavBarW) RightIcon(ic *icon.Icon) *NavBarW

RightIcon shows an icon action at the end; name it with RightLabel unless Right gives it a text.

go
func (w *NavBarW) RightLabel(s string) *NavBarW

RightLabel sets the accessible name of the right action (needed for an icon-only action).

NoticeBarW ​

go
type NoticeBarW struct {
	// contains filtered or unexported fields
}

NoticeBarW is a one-line announcement bar, optionally scrolling.

func NoticeBar ​

go
func NoticeBar(c *ui.Context, msg string) *NoticeBarW

NoticeBar adds an announcement bar showing msg (a neutral shadcn Alert strip in the shadcn style).

ConfigProvider defaults ("mobile.NoticeBar"): "color" (string), "closeable", "scroll" (bool).

func (*NoticeBarW) Closeable ​

go
func (w *NoticeBarW) Closeable() *NoticeBarW

Closeable shows a close button.

func (*NoticeBarW) Closed ​

go
func (w *NoticeBarW) Closed() bool

Closed reports a tap on the close button this frame.

func (*NoticeBarW) Color ​

go
func (w *NoticeBarW) Color(s string) *NoticeBarW

Color sets "default" (orange), "alert", "error" or "info".

func (*NoticeBarW) Scroll ​

go
func (w *NoticeBarW) Scroll() *NoticeBarW

Scroll makes long text scroll (marquee; towards the start, so to the right in RTL).

Options ​

go
type Options struct {
	Style Style
	// SafeArea overrides the window's safe-area insets (ui.Context.SafeArea,
	// set by the host through ui.SafeAreaWindow or Runner.SetSafeArea).
	SafeArea *geom.Insets
}

Options configure the mobile components inside a Provider.

Pan ​

go
type Pan struct {
	Active   bool       // the area owns a drag in progress
	Began    bool       // ownership started this frame
	Ended    bool       // the finger lifted this frame
	Delta    geom.Point // travel since the drag was claimed
	Velocity geom.Point // px/s (release velocity when Ended)
	Dir      Direction  // direction at claim time
}

Pan is the drag state of a gesture area that owns the current drag.

PickerViewW ​

go
type PickerViewW struct {
	// contains filtered or unexported fields
}

PickerViewW is an inline set of scroll wheels.

func CascadePickerView ​

go
func CascadePickerView(c *ui.Context, opts []ui.CascaderOption, value *[]string) *PickerViewW

CascadePickerView shows linked wheels for a tree of options (province / city / district); value holds the Value path.

func DatePickerView ​

go
func DatePickerView(c *ui.Context, value *time.Time, p DatePrecision, bounds ...time.Time) *PickerViewW

DatePickerView shows year / month / day (… hour / minute) wheels bound to *value. Optional bounds are the earliest and latest selectable time (default: ten years either side of the value).

func PickerView ​

go
func PickerView(c *ui.Context, cols [][]ui.Option, value *[]string) *PickerViewW

PickerView shows one wheel per column; value holds the selected option Value of each column. The shadcn style marks the selected row with a muted rounded-md band instead of hairlines.

ConfigProvider defaults ("mobile.PickerView", also read by the views of Picker, CascadePickerView and DatePickerView): "visibleItemCount" (int, at least 3).

func (*PickerViewW) A11yLabel ​

go
func (w *PickerViewW) A11yLabel(s string) *PickerViewW

A11yLabel names the wheels for screen readers (each wheel is an adjustable slider whose value is the selected option); A11yLabels names them one by one. Date pickers name their columns year, month, day ….

func (*PickerViewW) A11yLabels ​

go
func (w *PickerViewW) A11yLabels(names ...string) *PickerViewW

A11yLabels sets the accessible name of each wheel.

func (*PickerViewW) Changed ​

go
func (w *PickerViewW) Changed() bool

Changed reports a wheel settling on a new value this frame.

func (*PickerViewW) ID ​

go
func (w *PickerViewW) ID() ui.ID

ID returns the wheel row's ID.

func (*PickerViewW) Show ​

go
func (w *PickerViewW) Show() *PickerViewW

Show renders the wheels.

func (*PickerViewW) Visible ​

go
func (w *PickerViewW) Visible(n int) *PickerViewW

Visible sets how many rows each wheel shows (odd numbers centre best).

PickerW ​

go
type PickerW struct {
	// contains filtered or unexported fields
}

PickerW is a bottom popup with a toolbar (cancel / title / confirm) and wheels; the bound value only changes on confirm.

func Picker ​

go
func Picker(c *ui.Context, open *bool, title string) *PickerW

Picker creates a popup picker bound to *open; choose the wheels with Columns, Cascade or Date, then call Show. The shadcn style shows it as a Drawer (grab handle, semibold title).

ConfigProvider defaults ("mobile.Picker"): "closeOnMaskClick" (bool); the wheels read "mobile.PickerView".

func (*PickerW) Cancelled ​

go
func (w *PickerW) Cancelled() bool

Cancelled reports a cancel this frame.

func (*PickerW) Cascade ​

go
func (w *PickerW) Cascade(opts []ui.CascaderOption, value *[]string) *PickerW

Cascade shows linked wheels for a tree of options.

func (*PickerW) Columns ​

go
func (w *PickerW) Columns(cols [][]ui.Option, value *[]string) *PickerW

Columns shows independent wheels; value receives the Values on confirm.

func (*PickerW) Confirmed ​

go
func (w *PickerW) Confirmed() bool

Confirmed reports a confirm this frame (the bound value was updated).

func (*PickerW) Date ​

go
func (w *PickerW) Date(value *time.Time, p DatePrecision, bounds ...time.Time) *PickerW

Date shows date / time wheels down to precision p (optional bounds as in DatePickerView).

func (*PickerW) Show ​

go
func (w *PickerW) Show() *PickerW

Show renders the popup.

Pinch ​

go
type Pinch struct {
	Scale    float32    // current finger distance / start distance
	Rotation float64    // radians, positive clockwise
	Center   geom.Point // midpoint of the fingers
	Pan      geom.Point // movement of the midpoint since the start
	Active   bool
}

Pinch is the state of a two-finger gesture relative to its start.

PinchRecognizer ​

go
type PinchRecognizer struct {
	// contains filtered or unexported fields
}

PinchRecognizer turns two-finger frames into scale / rotation / pan. Gesture areas feed it from the ui layer's touch events (Gesture.Pinch); custom code can call Update with the fingers of a ui.Box.Touches stream.

func (*PinchRecognizer) Update ​

go
func (r *PinchRecognizer) Update(pts []TouchPoint) Pinch

Update consumes the current set of touching fingers and returns the pinch state (Active false with fewer than two fingers).

PopupW ​

go
type PopupW struct {
	// contains filtered or unexported fields
}

PopupW is a sliding panel over a dimmed mask.

go
func Popup(c *ui.Context, open *bool) *PopupW

Popup creates a popup bound to *open (bottom sheet by default); set options, then build the content with Body. Tapping the mask or pressing Escape closes it. In the shadcn style a bottom popup is a Drawer: an outlined sheet with rounded top corners and a grab handle that can be dragged down to close it.

ConfigProvider defaults ("mobile.Popup"): "position" ("bottom", "top", "center", "left", "right", "start", "end"), "round", "mask", "closeOnMaskClick", "handle" (bool).

func (*PopupW) A11yLabel ​

go
func (w *PopupW) A11yLabel(s string) *PopupW

A11yLabel sets the accessible name of the panel (a dialog for screen readers; name it after its content).

func (*PopupW) Bg ​

go
func (w *PopupW) Bg(col paintColor) *PopupW

Bg sets the panel background.

func (*PopupW) Body ​

go
func (w *PopupW) Body(fn func()) *PopupW

Body builds the panel content (only while open or animating out).

func (*PopupW) CloseOnMask ​

go
func (w *PopupW) CloseOnMask(on bool) *PopupW

CloseOnMask toggles closing on a mask tap (default on).

func (*PopupW) Closed ​

go
func (w *PopupW) Closed() bool

Closed reports that the user dismissed the popup this frame.

func (*PopupW) Handle ​

go
func (w *PopupW) Handle(on bool) *PopupW

Handle toggles the drawer grab handle of a bottom popup (shadcn default on): a bar on top of the sheet; dragging it down closes the popup.

func (*PopupW) Layout ​

go
func (w *PopupW) Layout(opts ...layout.Option) *PopupW

Layout applies layout options to the panel.

func (*PopupW) Mask ​

go
func (w *PopupW) Mask(on bool) *PopupW

Mask toggles the dimmed backdrop (default on).

func (*PopupW) Position ​

go
func (w *PopupW) Position(p Position) *PopupW

Position sets where the panel appears.

func (*PopupW) Round ​

go
func (w *PopupW) Round(on bool) *PopupW

Round toggles rounded corners on the inner edge.

Position ​

go
type Position uint8

Position places a popup. PosLeft and PosRight are physical sides; PosStart and PosEnd are logical: the left and right edge left to right, the right and left edge in RTL.

go
const (
	PosBottom Position = iota
	PosTop
	PosCenter
	PosLeft
	PosRight
	PosStart
	PosEnd
)

Press ​

go
type Press struct {
	Pressed   bool       // a finger is down on it and has not moved away
	PressPos  geom.Point // where the finger went down
	Tap       bool       // tapped this frame
	TapPos    geom.Point
	LongPress bool // held for LongPressDelay this frame
	LongPos   geom.Point
	// KeyTap reports that Tap came from the keyboard (Enter / Space on the
	// focused widget) or a screen reader (Press action); TapPos is then
	// the centre of the widget.
	KeyTap bool
}

Press is the per-frame touch state of a touchable widget.

func Touchable ​

go
func Touchable(c *ui.Context, b *ui.Box) Press

Touchable registers box b as a tappable widget and returns its touch state for this frame. Call it once per frame per widget. Inside a gesture area b gets no ui hit (the area captures the finger and the arena forwards taps); elsewhere b becomes hit-testable and a keyboard focus stop (Enter / Space tap it). In both cases a screen reader's Press action on b reports a Tap, so give b a role (b.Semantics) to expose it.

RefreshMachine ​

go
type RefreshMachine struct {
	Status    RefreshStatus
	Threshold float64       // pull distance that arms the refresh
	Delay     time.Duration // how long RefreshComplete stays
	// contains filtered or unexported fields
}

RefreshMachine is the pull-to-refresh state machine (pure).

func (*RefreshMachine) Finish ​

go
func (m *RefreshMachine) Finish(now time.Time)

Finish ends a refresh at now.

func (*RefreshMachine) Holding ​

go
func (m *RefreshMachine) Holding() bool

Holding reports whether the header is held open.

func (*RefreshMachine) Pull ​

go
func (m *RefreshMachine) Pull(d float64)

Pull updates the status for a drag at distance d (displayed px).

func (*RefreshMachine) Release ​

go
func (m *RefreshMachine) Release() bool

Release ends the drag; it reports whether a refresh starts.

func (*RefreshMachine) Start ​

go
func (m *RefreshMachine) Start()

Start enters the refreshing state programmatically.

func (*RefreshMachine) Tick ​

go
func (m *RefreshMachine) Tick(now time.Time) (next time.Time)

Tick advances timed transitions; it returns the time of the next one.

RefreshStatus ​

go
type RefreshStatus uint8

RefreshStatus is the phase of a pull-to-refresh header.

go
const (
	RefreshIdle       RefreshStatus = iota
	RefreshPulling                  // dragged down, below the threshold
	RefreshCanRelease               // past the threshold: releasing refreshes
	RefreshRefreshing               // loading; the header stays open
	RefreshComplete                 // finished; shows the success text briefly
)

ResultW ​

go
type ResultW struct {
	// contains filtered or unexported fields
}

ResultW is a full-width outcome page block.

func Result ​

go
func Result(c *ui.Context, status, title string) *ResultW

Result adds an outcome block: status "success", "error", "info", "waiting" or "warning".

func (*ResultW) Description ​

go
func (w *ResultW) Description(s string) *ResultW

Description adds an explanation under the title.

Sample ​

go
type Sample struct {
	Pos geom.Point
	T   time.Time
}

Sample is one pointer position at a time.

ScrollMode ​

go
type ScrollMode uint8

ScrollMode is what a Scroller is doing.

go
const (
	Idle      ScrollMode = iota
	Dragging             // following the finger
	Flinging             // inertial deceleration
	Springing            // bouncing back to an edge or settling on a snap point
)

ScrollViewW ​

go
type ScrollViewW struct {
	// contains filtered or unexported fields
}

ScrollViewW is a touch scroll container: finger tracking, inertial fling, rubber-band edges and bounce back, with optional pull-to-refresh header and infinite-load footer.

func InfiniteList ​

go
func InfiniteList(c *ui.Context, loading *bool) *ScrollViewW

InfiniteList creates a ScrollView that loads more when scrolled near the end: it sets *loading = true and LoadMore reports it. Set *loading back to false after appending rows; call Finished(true) when nothing is left.

func PullToRefresh ​

go
func PullToRefresh(c *ui.Context, refreshing *bool) *ScrollViewW

PullToRefresh creates a ScrollView with a pull-down refresh header. Dragging past the threshold and releasing sets *refreshing = true and Refreshed reports it; set it back to false when the data has loaded.

func ScrollView ​

go
func ScrollView(c *ui.Context) *ScrollViewW

ScrollView creates a vertical touch scroll container. Give it a bounded height (Layout(layout.Grow(1)) in a sized column, or layout.H), set options, then build the content with Body.

func (*ScrollViewW) Bg ​

go
func (w *ScrollViewW) Bg(col paintColor) *ScrollViewW

Bg sets the background color.

func (*ScrollViewW) Body ​

go
func (w *ScrollViewW) Body(fn func()) *ScrollViewW

Body builds the scrolling content.

func (*ScrollViewW) ContentID ​

go
func (w *ScrollViewW) ContentID() ui.ID

ContentID returns the ID of the moving content box.

func (*ScrollViewW) Failed ​

go
func (w *ScrollViewW) Failed(failed *bool) *ScrollViewW

Failed binds a load error flag: the footer offers a retry tap.

func (*ScrollViewW) Finished ​

go
func (w *ScrollViewW) Finished(on bool) *ScrollViewW

Finished marks the list complete (footer shows "no more").

func (*ScrollViewW) ID ​

go
func (w *ScrollViewW) ID() ui.ID

ID returns the container's ID.

func (*ScrollViewW) Infinite ​

go
func (w *ScrollViewW) Infinite(loading *bool) *ScrollViewW

Infinite enables the load-more footer bound to *loading.

func (*ScrollViewW) Layout ​

go
func (w *ScrollViewW) Layout(opts ...layout.Option) *ScrollViewW

Layout applies layout options to the container.

func (*ScrollViewW) LoadMore ​

go
func (w *ScrollViewW) LoadMore() bool

LoadMore reports that the list asked for more rows this frame.

func (*ScrollViewW) Offset ​

go
func (w *ScrollViewW) Offset(px float32) *ScrollViewW

Offset sets how close (px) to the end loading starts (default 50).

func (*ScrollViewW) Pull ​

go
func (w *ScrollViewW) Pull(refreshing *bool) *ScrollViewW

Pull enables the pull-to-refresh header bound to *refreshing.

func (*ScrollViewW) PullTexts ​

go
func (w *ScrollViewW) PullTexts(pulling, release, refreshing, complete string) *ScrollViewW

PullTexts overrides the header texts (pulling, can release, refreshing, complete); empty entries keep the localized defaults.

func (*ScrollViewW) Refreshed ​

go
func (w *ScrollViewW) Refreshed() bool

Refreshed reports that the user pulled to refresh this frame.

func (*ScrollViewW) Rows ​

go
func (w *ScrollViewW) Rows(n int, rowH float32, row func(i int))

Rows builds a long list of n rows of a fixed height rowH inside Body, creating only the rows in or near the visible part of the view: the rest is a blank of the right height, so the scroll range, the fling and the infinite-load trigger behave as if every row were there. row(i) builds row i (keyed by i, so its state follows the index); keep the row's content within rowH. Other content may come before or after the rows in the same Body.

sv := mobile.ScrollView(c).Layout(layout.Grow(1))
sv.Body(func() {
	mobile.List(c, "").Body(func() {
		sv.Rows(len(items), 50, func(i int) { mobile.Cell(c, items[i]) })
	})
})

Rows that are not built are not in the accessibility tree; a screen reader reaches them by scrolling. For variable row heights or a desktop scroll bar use ui.VirtualList inside the page instead.

func (*ScrollViewW) ScrollOffset ​

go
func (w *ScrollViewW) ScrollOffset() float64

Offset returns the scroll offset (negative while pulled down).

func (*ScrollViewW) ScrollTo ​

go
func (w *ScrollViewW) ScrollTo(y float64) *ScrollViewW

ScrollTo jumps to offset y (clamped).

func (*ScrollViewW) Scrolling ​

go
func (w *ScrollViewW) Scrolling() bool

Scrolling reports whether the view is being dragged or still moving.

func (*ScrollViewW) Status ​

go
func (w *ScrollViewW) Status() RefreshStatus

Status returns the pull-to-refresh status.

Scroller ​

go
type Scroller struct {
	Pos      float64 // current offset
	Min, Max float64 // scroll range
	Dim      float64 // viewport size on this axis (rubber band scale)
	Snap     float64 // > 0: rest only on multiples of Snap (from Min)
	// NoBounce clamps at the edges instead of rubber-banding.
	NoBounce bool

	Mode ScrollMode
	// contains filtered or unexported fields
}

Scroller is the scroll physics of one axis: finger tracking with rubber band past the edges, inertial fling with exponential deceleration, critically damped bounce back, and optional snapping (picker wheels, pages). Positions grow as content moves up/left (like scroll offsets). It is pure: callers pass the time and read Pos.

func (*Scroller) Active ​

go
func (s *Scroller) Active() bool

Active reports whether the scroller is moving on its own.

func (*Scroller) BeginDrag ​

go
func (s *Scroller) BeginDrag()

BeginDrag stops any motion and starts following the finger.

func (*Scroller) DragBy ​

go
func (s *Scroller) DragBy(delta float64)

DragBy moves to the drag-start position plus delta (finger travel in content direction, i.e. negative finger movement for natural scrolling).

func (*Scroller) Release ​

go
func (s *Scroller) Release(v float64, now time.Time)

Release ends a drag with velocity v (px/s, content direction) at time now and starts the fling, bounce or snap that follows.

func (*Scroller) Settle ​

go
func (s *Scroller) Settle()

Settle jumps to the rest position of the current motion.

func (*Scroller) SnapTo ​

go
func (s *Scroller) SnapTo(target float64, now time.Time)

SnapTo glides to target (decelerating so it lands exactly there).

func (*Scroller) Step ​

go
func (s *Scroller) Step(now time.Time) bool

Step advances the motion to now and reports whether it is still moving.

func (*Scroller) Stop ​

go
func (s *Scroller) Stop()

Stop halts the motion where it is (a finger caught a fling).

SearchBarW ​

go
type SearchBarW struct {
	// contains filtered or unexported fields
}

SearchBarW is a rounded search field with an optional cancel action.

go
func SearchBar(c *ui.Context, q *string, placeholder, cancel string) *SearchBarW

SearchBar adds a search field bound to *q. placeholder "" uses the localized "搜索". Pass a non-empty cancel text to show a cancel action while the field has text. In the shadcn style the field is a muted, borderless rounded-lg input on the bar background with a ring on focus.

ConfigProvider defaults ("mobile.SearchBar"): "placeholder" (string, used when placeholder is ""), "cancelText" (string, used when cancel is ""), "shape" ("round" or "default").

func (*SearchBarW) Cancelled ​

go
func (w *SearchBarW) Cancelled() bool

Cancelled reports a tap on the cancel action.

func (*SearchBarW) Changed ​

go
func (w *SearchBarW) Changed() bool

Changed reports an edit this frame.

func (*SearchBarW) Submitted ​

go
func (w *SearchBarW) Submitted() bool

Submitted reports Enter (search).

Size ​

go
type Size uint8

Size is a mobile control size.

go
const (
	Middle Size = iota
	Mini
	Small
	Large
)

SkeletonW ​

go
type SkeletonW struct {
	// contains filtered or unexported fields
}

SkeletonW is a loading placeholder of grey bars.

func Skeleton ​

go
func Skeleton(c *ui.Context) *SkeletonW

Skeleton adds a placeholder; choose parts with Title, Paragraph, Avatar. The shadcn style pulses rounded-md muted bars instead of a shimmer.

ConfigProvider defaults ("mobile.Skeleton"): "title", "avatar", "animated" (bool), "rows" (int).

func (*SkeletonW) Animated ​

go
func (w *SkeletonW) Animated(on bool) *SkeletonW

Animated toggles the shimmer (on by default when animations run).

func (*SkeletonW) Avatar ​

go
func (w *SkeletonW) Avatar() *SkeletonW

Avatar shows a round avatar placeholder.

func (*SkeletonW) Paragraph ​

go
func (w *SkeletonW) Paragraph(n int) *SkeletonW

Paragraph sets the number of text rows.

func (*SkeletonW) Title ​

go
func (w *SkeletonW) Title() *SkeletonW

Title shows a title bar.

StepperW ​

go
type StepperW struct {
	// contains filtered or unexported fields
}

StepperW is a − value + control.

func Stepper ​

go
func Stepper(c *ui.Context, v *float64) *StepperW

Stepper adds a stepper bound to *v (step 1, no bounds). Set options, then read Changed (applying the tap happens on the first query or at paint, whichever comes first, so bounds always apply). In the shadcn style it is an outlined button group (h-10) with ghost − / + buttons.

ConfigProvider defaults ("mobile.Stepper"): "step", "min", "max", "digits" (numbers), "disabled" (bool).

func (*StepperW) A11yLabel ​

go
func (w *StepperW) A11yLabel(s string) *StepperW

A11yLabel sets the accessible name (inside a FormItem the label is used).

func (*StepperW) Changed ​

go
func (w *StepperW) Changed() bool

Changed reports a step this frame.

func (*StepperW) Digits ​

go
func (w *StepperW) Digits(n int) *StepperW

Digits fixes the decimals shown.

func (*StepperW) Disabled ​

go
func (w *StepperW) Disabled(on bool) *StepperW

Disabled disables the control.

func (*StepperW) Max ​

go
func (w *StepperW) Max(v float64) *StepperW

Max sets the upper bound.

func (*StepperW) Min ​

go
func (w *StepperW) Min(v float64) *StepperW

Min sets the lower bound.

func (*StepperW) Step ​

go
func (w *StepperW) Step(s float64) *StepperW

Step sets the increment.

Style ​

go
type Style uint8

Style names the mobile design language the components imitate.

go
const (
	AntMobile Style = iota // Ant Design Mobile (default)
	Vant                   // Vant
	// Shadcn derives a mobile look from the shadcn/ui design language
	// (neutral colors, thin borders, rounded-lg/xl, near-black primary,
	// Drawer-style bottom sheets, Sonner toasts). The default AntMobile
	// resolves to Shadcn under a shadcn ui theme (theme.Shadcn).
	Shadcn
)

Swipe ​

go
type Swipe struct {
	Dir      Direction
	Velocity geom.Point // px/s
	Speed    float32    // px/s along Dir
	Distance float32    // px along Dir
}

Swipe is a quick directional movement.

SwipeAction ​

go
type SwipeAction struct {
	Key   string
	Text  string
	Color string // "primary" | "success" | "warning" | "danger" | "light" | "" (light)
}

SwipeAction is a button revealed by swiping a SwipeCell.

SwipeCellW ​

go
type SwipeCellW struct {
	// contains filtered or unexported fields
}

SwipeCellW wraps content that can be swiped sideways to reveal actions.

Sides are logical: the Right actions sit at the end of the row and are revealed by swiping towards the start (to the left; in RTL the actions sit on the left and a swipe to the right reveals them), the Left ones at the start.

func SwipeCell ​

go
func SwipeCell(c *ui.Context) *SwipeCellW

SwipeCell starts a swipeable row; set actions, then build the content with Body (typically one Cell).

ConfigProvider defaults ("mobile.SwipeCell"): "closeOnAction" (bool).

func (*SwipeCellW) Action ​

go
func (w *SwipeCellW) Action() (side, index int, ok bool)

Action reports a tapped action this frame: side (1 Right / end, -1 Left / start), index into that side's actions.

func (*SwipeCellW) ActionKey ​

go
func (w *SwipeCellW) ActionKey() string

ActionKey returns the Key (or Text) of the tapped action, "" if none.

func (*SwipeCellW) Body ​

go
func (w *SwipeCellW) Body(fn func()) *SwipeCellW

Body builds the row content.

func (*SwipeCellW) Close ​

go
func (w *SwipeCellW) Close() *SwipeCellW

Close closes the cell.

func (*SwipeCellW) IsOpen ​

go
func (w *SwipeCellW) IsOpen() bool

IsOpen reports whether actions are (being) shown.

func (*SwipeCellW) KeepOpen ​

go
func (w *SwipeCellW) KeepOpen() *SwipeCellW

KeepOpen keeps the cell open after an action tap.

func (*SwipeCellW) Left ​

go
func (w *SwipeCellW) Left(a ...SwipeAction) *SwipeCellW

Left sets the actions at the start, revealed by swiping right (left in RTL).

func (*SwipeCellW) Open ​

go
func (w *SwipeCellW) Open(side int) *SwipeCellW

Open opens the Right (end, side > 0) or Left (start, side < 0) actions.

func (*SwipeCellW) Right ​

go
func (w *SwipeCellW) Right(a ...SwipeAction) *SwipeCellW

Right sets the actions at the end, revealed by swiping left (right in RTL).

SwiperW ​

go
type SwiperW struct {
	// contains filtered or unexported fields
}

SwiperW is a swipeable carousel of slides with indicator dots.

func Swiper ​

go
func Swiper(c *ui.Context, cur *int) *SwiperW

Swiper creates a carousel; *cur is the current slide (nil keeps it internally). Set options, then build slides with Slides. In RTL the slides run right to left: the next slide comes in from the left, a swipe to the right shows it and the indicator starts at the right.

ConfigProvider defaults ("mobile.Swiper"): "autoplay" (time.Duration or ms), "loop", "indicator" (bool), "height", "radius" (numbers), "indicatorColor" ("white" for IndicatorWhite).

func (*SwiperW) Autoplay ​

go
func (w *SwiperW) Autoplay(d time.Duration) *SwiperW

Autoplay advances every d.

func (*SwiperW) Changed ​

go
func (w *SwiperW) Changed() bool

Changed reports a slide change this frame.

func (*SwiperW) Height ​

go
func (w *SwiperW) Height(px float32) *SwiperW

Height sets the slide height (default 150).

func (*SwiperW) Indicator ​

go
func (w *SwiperW) Indicator(on bool) *SwiperW

Indicator toggles the dots.

func (*SwiperW) IndicatorColor ​

go
func (w *SwiperW) IndicatorColor(active, inactive theme.Color) *SwiperW

IndicatorColor sets the color of the current slide's dot and of the others (a zero inactive color is active at 40% opacity). Use it when the style's dots (primary on a faint track) would vanish on the slides.

func (*SwiperW) IndicatorWhite ​

go
func (w *SwiperW) IndicatorWhite() *SwiperW

IndicatorWhite draws white dots (Ant Design Mobile's indicator color "white"), for slides that are images or saturated colors.

func (*SwiperW) Loop ​

go
func (w *SwiperW) Loop() *SwiperW

Loop wraps from the last slide to the first.

func (*SwiperW) Radius ​

go
func (w *SwiperW) Radius(px float32) *SwiperW

Radius rounds the corners.

func (*SwiperW) Slides ​

go
func (w *SwiperW) Slides(n int, slide func(i int)) *SwiperW

Slides builds n slides; slide(i) builds slide i.

TabBarW ​

go
type TabBarW struct {
	// contains filtered or unexported fields
}

TabBarW is the bottom tab bar.

func TabBar ​

go
func TabBar(c *ui.Context, items []TabItem, active *string) *TabBarW

TabBar adds a bottom tab bar; *active holds the selected item's Key. It reserves the bottom safe-area inset below the items.

ConfigProvider defaults ("mobile.TabBar"): "bordered" (bool, the top line; default on).

func (*TabBarW) Border ​

go
func (w *TabBarW) Border(on bool) *TabBarW

Border toggles the top line (default on).

func (*TabBarW) Changed ​

go
func (w *TabBarW) Changed() bool

Changed reports a tab switch this frame.

func (*TabBarW) ID ​

go
func (w *TabBarW) ID() ui.ID

ID returns the bar's ID.

TabItem ​

go
type TabItem struct {
	Key   string
	Title string
	Icon  *icon.Icon
	Badge string // "" none, "dot" for a dot, else the count text
}

TabItem is one entry of a TabBar.

TabsW ​

go
type TabsW struct {
	// contains filtered or unexported fields
}

TabsW is a tab header with an underline and (optionally swipeable) content panes.

func Tabs ​

go
func Tabs(c *ui.Context, titles []string, active *int) *TabsW

Tabs adds tabs titled titles; *active is the selected index. Build the panes with Body (or Header for a header only).

In the shadcn style the header is a segmented control: a muted rounded-lg track with the selected title on a raised thumb.

In RTL the first title is at the right, the header scrolls from its right end and the panes follow the titles (the next pane comes in from the left).

ConfigProvider defaults ("mobile.Tabs"): "swipeable" (bool).

func (*TabsW) Body ​

go
func (w *TabsW) Body(pane func(i int)) *TabsW

Body builds the header and the panes; pane(i) builds pane i.

func (*TabsW) Changed ​

go
func (w *TabsW) Changed() bool

Changed reports a tab switch this frame.

func (*TabsW) Header ​

go
func (w *TabsW) Header() *TabsW

Header builds the header only.

func (*TabsW) Swipeable ​

go
func (w *TabsW) Swipeable() *TabsW

Swipeable lets a horizontal swipe on the content switch tabs.

TagW ​

go
type TagW struct {
	// contains filtered or unexported fields
}

TagW is a small label.

func Tag ​

go
func Tag(c *ui.Context, label string) *TagW

Tag adds a tag (a shadcn Badge in the shadcn style: rounded-md, text-xs medium; "default" is the secondary variant).

ConfigProvider defaults ("mobile.Tag"): "color" (string), "fill" ("solid", "outline", "light"), "round" (bool).

func (*TagW) Color ​

go
func (w *TagW) Color(s string) *TagW

Color sets "default", "primary", "success", "warning", "danger".

func (*TagW) Light ​

go
func (w *TagW) Light() *TagW

Light uses a tinted background with colored text.

func (*TagW) Outline ​

go
func (w *TagW) Outline() *TagW

Outline draws a border instead of a solid fill.

func (*TagW) Round ​

go
func (w *TagW) Round() *TagW

Round makes the tag pill-shaped.

Theme ​

go
type Theme struct {
	Style Style
	Dark  bool
	Base  *theme.Theme

	// Brand and status colors.
	Primary, Success, Warning, Danger theme.Color
	PrimaryLight                      theme.Color // tinted background (tags, notice bars)

	// Neutrals.
	Text, TextSecondary, TextWeak, TextLight theme.Color
	Border                                   theme.Color // hairlines between cells
	PageBg                                   theme.Color // page background behind lists
	Box                                      theme.Color // cells, bars, panels
	Fill                                     theme.Color // stepper buttons, search fields, skeleton
	Press                                    theme.Color // overlay drawn over a pressed item
	Mask                                     theme.Color
	ToastBg                                  theme.Color
	OnPrimary                                theme.Color // text on solid colored controls

	// Typography (logical px; 1pt = 1px at the mobile reference density).
	FontTiny, FontSmall, FontMain, FontBody, FontTitle, FontLarge float32

	// Geometry.
	TouchMin                      float32 // minimum touch target (44pt)
	PadH                          float32 // horizontal page padding
	Radius, RadiusLarge, PopupRad float32
	NavBarHeight, TabBarHeight    float32
	CellPadV, CellMinHeight       float32
	ButtonHeight                  [4]float32 // Mini, Small, Middle, Large
	ButtonFont                    [4]float32
	ButtonRadius                  float32
	PickerItemHeight              float32
	PickerVisible                 int // rows shown in a picker wheel
	TabsHeight                    float32
	TabsLineWidth, TabsLineHeight float32 // 0 width = as wide as the title
	DialogWidth                   float32
	ActionHeight                  float32
	ToastPad                      float32
	SearchHeight, SearchRadius    float32
	StepperHeight, StepperInputW  float32
	BadgeColor                    theme.Color
	NoticeBg, NoticeText          theme.Color
	TitleWeight                   text.Weight
	FormLabelWidth                float32

	// Tokens of the shadcn derivation; the Ant Mobile and Vant values keep
	// their looks (zero colors mean "none").
	OnSolid       theme.Color // text on solid success / warning / danger fills
	ButtonWeight  text.Weight // button label weight
	CardBorder    theme.Color // outline of lists, cards, sheets and dialogs
	DrawerHandle  theme.Color // grab handle on top of bottom sheets
	ToastText     theme.Color // toast message color (on ToastBg)
	ToastBorder   theme.Color // toast outline
	NoticeBorder  theme.Color // notice bar top / bottom lines
	SwitchOff     theme.Color // switch track when off
	SwitchThumb   theme.Color // switch thumb when off
	SwitchThumbOn theme.Color // switch thumb when on
	SwitchW       float32     // switch track size
	SwitchH       float32
	Ring          theme.Color // keyboard focus outline
	SegmentThumb  theme.Color // selected tab of the segmented (shadcn) Tabs
}

Theme holds the mobile design tokens. It is derived from the ui theme (dark mode, brand color, mask) and the selected Style (sizes, neutrals). Components capture it at build time; read it with ThemeOf.

func NewTheme ​

go
func NewTheme(base *theme.Theme, style Style) *Theme

NewTheme derives the mobile tokens for style from the ui theme base. Under a high-contrast base (theme.HighContrast) the neutrals are lifted to WCAG AA like the ui theme's: text 4.5:1, arrows, borders and switch tracks 3:1 (see highContrast).

func ThemeOf ​

go
func ThemeOf(c *ui.Context) *Theme

ThemeOf returns the mobile theme in effect.

func (*Theme) ColorOf ​

go
func (t *Theme) ColorOf(name string) theme.Color

ColorOf maps a status name ("primary", "success", "warning", "danger", "default") to a color.

func (*Theme) Font ​

go
func (t *Theme) Font(px float32, w text.Weight) text.Style

Font returns a text style of px size and weight with a mobile line height (1.5×, rounded).

ToastOptions ​

go
type ToastOptions struct {
	Icon     string        // "success", "fail", "loading" or ""
	Duration time.Duration // default 2 s
	Position Position      // default PosCenter
}

ToastOptions configure ShowToast.

ToastW ​

go
type ToastW struct {
	// contains filtered or unexported fields
}

ToastW is a short centred message.

func Toast ​

go
func Toast(c *ui.Context, show *bool, msg string) *ToastW

Toast shows msg while *show is true and clears it after the duration (2 s; 0 keeps it). Call Show after the options. In the shadcn style it is a Sonner toast: an outlined popover card with the icon inline, shown at the bottom by default.

ConfigProvider defaults ("mobile.Toast"): "duration" (time.Duration or ms), "position" ("top", "center", "bottom").

func (*ToastW) Duration ​

go
func (w *ToastW) Duration(d time.Duration) *ToastW

Duration sets the auto-hide delay (0 = stay).

func (*ToastW) Icon ​

go
func (w *ToastW) Icon(kind string) *ToastW

Icon adds an icon: "success", "fail", "loading".

func (*ToastW) Position ​

go
func (w *ToastW) Position(p Position) *ToastW

Position sets the vertical placement (PosTop, PosCenter, PosBottom).

func (*ToastW) Show ​

go
func (w *ToastW) Show() *ToastW

Show renders the toast.

TouchPoint ​

go
type TouchPoint struct {
	ID  int64
	Pos geom.Point
}

TouchPoint is one finger of a multi-touch frame.

Track ​

go
type Track struct {
	Start, Last Sample

	Moved     bool // travelled more than TouchSlop
	Ended     bool
	LongFired bool
	// contains filtered or unexported fields
}

Track records one finger from down to up and classifies it. It is pure (no Context): feed Begin / Move / End with timestamps.

func (*Track) Begin ​

go
func (t *Track) Begin(s Sample)

Begin starts the track at s.

func (*Track) Delta ​

go
func (t *Track) Delta() geom.Point

Delta is the travel from the start.

func (*Track) End ​

go
func (t *Track) End(s Sample)

End finishes the track at s.

func (*Track) Held ​

go
func (t *Track) Held(now time.Time) time.Duration

Held is how long the finger has been down at now.

func (*Track) IsTap ​

go
func (t *Track) IsTap() bool

IsTap reports whether an ended track was a tap: short travel and not turned into a long press.

func (*Track) Move ​

go
func (t *Track) Move(s Sample) (crossed bool)

Move adds a sample; it reports whether this move crossed the slop.

func (*Track) Swipe ​

go
func (t *Track) Swipe() (Swipe, bool)

Swipe classifies an ended track as a swipe: fast enough or far enough along its dominant direction.

func (*Track) Velocity ​

go
func (t *Track) Velocity() geom.Point

Velocity is the release velocity (px/s) over the last 100 ms of samples; zero when the finger rested or time did not advance.

以 MIT 许可发布