mobile

package module
v0.4.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 3, 2026 License: MIT Imports: 9 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

MeUI Mobile

The reusable mobile shell for MeUI: Android app bar or iOS large title, a bottom bar that becomes a tablet rail, FAB, snackbar, safe-area layout, keyboard avoidance and the common presentations.

It is a widget, not a layout helper. A QML scene and a Go scene get the same MobileShell/MobilePage API; the application supplies pages and behaviour and never positions the shell.

Features

  • Android and iOS idioms from one scene — Material top app bar and FAB, or an iOS large title and grouped page.
  • Adaptive navigation — bottom destinations on a phone, a navigation rail at tablet widths (SetCompactWidth controls the breakpoint).
  • Safe area and IME — Bind tracks the platform window and insets, shrinks the page viewport for the keyboard, lifts the bar and can reveal the focused field.
  • Chrome — FAB with label, snackbar, back handling, avatar/actions and prompt helpers for bottom sheets, action sheets, alerts and search.
  • QML or Go — the same MobileShell/MobilePage types and the same phoneapp kitchen sink on the desktop or Android.

Android readiness

Android is the supported mobile target. The table is deliberately blunt: Ready means a working Android path exists, Partial means it works but has a material limitation, and Not yet means there is no Android implementation.

Area Status Notes
Shell, pages, app bar/large title, FAB, snackbar Ready Android and iOS idioms; bottom bar or tablet rail
Safe area, inset handling, density Ready Logical coordinates at 411×914 on a 1080×2400 phone
Keyboard / IME avoidance Ready Focus-driven; page and bar lift above the keyboard
APK build Ready meui new --ui mobile + meui apk; no Gradle
Text input, mouse, touch, back key Ready Touch drives the same widgets as mouse
Clipboard (text) Ready Through SDL
Power, battery, charging Ready Through SDL
System theme query Ready Query only; no change stream yet
App lifecycle Ready Background/foreground/low-memory through the Activity and mobile.Services
Orientation Ready Query plus change events; Screen can lock orientation
Device / OS / locale info Ready Manufacturer, model, OS, locale, app id/version
Permissions Ready API-level mapping, not-determined, rationale, notification fallback
Connectivity Ready Online, metered, transport, and change events
Share Ready Text/URL and one content:// file
Notifications Ready Channels, importance, actions, deep-link data, cancel; local only
Location Ready Last-known, foreground stream and a foreground-service background stream; permissions are the app's to request
Biometrics Partial Android prompt; no iOS host
System bars Partial Edge-to-edge and icon appearance
File picker and app data Ready SDL picker + ContentResolver read/write; AppDataDir on the app-private path
Sensors Ready Accelerometer, gyroscope, magnetometer, barometer, step counter; SensorsWithRate controls cadence
Haptics Ready Android predefined effects/strong fallback
Photo picker and camera Ready Android photo picker and FileProvider camera capture
Secure storage Ready Android Keystore AES/GCM
Keep awake Ready Screen.SetKeepAwake
Deep links / app links Ready meui.json links generate intent filters; delivered through mobile.Services
Audio Ready Signed 16-bit PCM playback and microphone capture; no decoder/mixer
Accessibility Partial Shell navigation and app-published nodes are exposed; arbitrary GL content still needs labels
Push notifications App-owned Local transport and deep links are framework; FCM/APNs stay in the app
Back stack Ready PushPage/Back history in addition to tab fallback
iOS device integration In progress Host scaffold exists privately; no macOS/Xcode build has been verified. iOS remains idiom-only until it builds

The detailed evidence and sequencing live in the core mobile feature-set assessment.

Push notifications are app-owned

The shell transports local notifications and their deep-link payloads. Remote push is deliberately not an abstraction: FCM and APNs require provider credentials, a server, token rotation and per-app consent, and a lowest-common-denominator wrapper would hide the part that actually fails. Add the provider SDK to the app, register the token with your backend, and hand the received payload to the same mobile.Services.OnDeepLink route used by normal links.

Install

go get github.com/sixnineone/meui-mobile@v0.4.0

Go 1.25 or later. The module depends on github.com/sixnineone/meui v0.4.2 and github.com/sixnineone/meui-gl v0.2.2.

Use

QML scene:

Window {
  MobileShell {
    id: shell
    title: "Portfolio"
    style: "auto"

    MobilePage {
      title: "Portfolio"
      label: "Home"
      icon: "grid"
      ScrollView {
        // page content
      }
    }
  }
}

Go:

import (
    "github.com/sixnineone/meui"
    "github.com/sixnineone/meui-mobile"
    "github.com/sixnineone/meui/view"
)

scene, err := view.Parse(qml, "web-light", 360, 640)
if err != nil { return err }

shell := scene.Get("shell").(*mobile.Shell)
shell.SetStyle(mobile.Android)
wnd, err := app.AddWindow(scene.Root, meui.WindowOptions{NoChrome: true})
if err != nil { return err }
shell.Bind(wnd, scene.Root)

Importing meui-mobile also registers the MobileShell and MobilePage QML types; no separate registration call is needed.

Example

The four-page kitchen sink lives in examples/phone, with the importable app in examples/phone/phoneapp:

go run ./examples/phone
go run ./examples/phone -ui ios -dark
go run ./examples/phone -page 3
go run ./examples/phone -w 800 -h 900        # rail + wide cards
go run ./examples/phone -shot phone.png

It covers a portfolio page, search/watchlist, profile, and a Kit page with buttons, selection controls, fields, swipe rows, pull-to-refresh, banner and token swatches.

Screenshots

Android iOS Tablet rail Kit
Dark Bottom sheet Actions Explore

Android host

The shell is platform-neutral; the Android host supplies the SDL3/MeUI GL window and passes it to Bind. The host owns edge-to-edge, system-bar appearance and the APK. See the MeUI Android build notes for the adapter side.

API

  • mobile.Style — Auto, Android, IOS; Preset, ParseStyle.
  • mobile.New(Options) / NewShell — build a shell.
  • Shell.AddChild(*Page), ShowPage, PushPage, Back, Pages, Current, HistoryDepth.
  • Shell.Bind(platform.Window, *meui.Window, ...*mobile.Services) — connect size, insets, keyboard; optional services add lifecycle, orientation and deep links.
  • Shell.SetCompactWidth, SetSafeArea, SetKeyboardAvoidance, RevealFocused.
  • mobile.NewServices(platform.App), Services.OnLifecycle, InitialDeepLink, PickImage, CaptureImage, PlayPCM, RecordPCM, Announce.
  • Shell.AccessibilityNodes and Shell.OnAccessibilityAction — publish app-owned GL nodes and handle activation.
  • Shell.SetFABVisible, SetFABLabel, Toast.
  • Shell.ShowSheet, ShowActionSheet, ShowAlert, ShowSearch.
  • Page — a destination with title, label, icon and children.

Status

v0.1.0 — the mobile shell extracted from meui as its own module. The mobile package in the core module remains for compatibility while consumers move; new work belongs here.

Licence

MIT — see LICENSE.

Documentation

Overview

Package mobile is the reusable phone shell: one widget that gives a scene the platform navigation, a large title or app bar, a bottom bar or rail, a FAB, a snackbar and safe-area layout.

It is deliberately a widget, not a layout helper, so QML and Go callers get the same thing:

Window {
  MobileShell {
    id: shell
    title: "Portfolio"
    style: "auto"
    MobilePage { title: "Portfolio"; label: "Home"; icon: "grid"
      ScrollView { ... }
    }
  }
}

The shell lays the active page out between the header and the navigation bar, applies the platform's safe-area insets, and switches pages when a destination is chosen. The application supplies pages and behaviour; it never positions the shell.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Preset

func Preset(style Style, dark bool) string

Preset returns the matching theme preset name.

Types

type Action

type Action struct {
	ID      string
	Icon    string
	Tooltip string
}

Action is one app-bar or large-title action. The large title shows at most three; the Android app bar can show all of them.

type Options

type Options struct {
	Style    Style
	Title    string
	Subtitle string
	Actions  []Action
	FAB      bool
	Avatar   string
}

New builds a shell with common options filled in.

type Page

type Page struct {
	meui.BaseContainer
	Title    string
	Subtitle string
	Label    string
	Icon     string

	OnShow func()
}

Page is one destination. Its content is the QML/Go child.

func NewPage

func NewPage(title, label, icon string) *Page

NewPage builds an empty page. Label falls back to Title and Icon to "grid" when the destination list is built.

func (*Page) AddChild

func (p *Page) AddChild(child meui.Widget)

AddChild adds the page's content. A page normally owns one scroll view.

func (*Page) Paint

func (p *Page) Paint(canvas *graphics.Canvas, rect graphics.Rect)

Paint draws the page background; the content paints over it.

func (*Page) PanelAt

func (p *Page) PanelAt(x, y float32) meui.Widget

PanelAt routes a tap to the page content.

func (*Page) SetBoundProperty

func (p *Page) SetBoundProperty(name string, value interface{})

SetBoundProperty implements the QML binding hook.

func (*Page) SetVisible

func (p *Page) SetVisible(visible bool) *Page

SetVisible propagates visibility to the content: QML often declares the scroll view with visible:false, and the shell owns page visibility.

func (*Page) ValidateLayout

func (p *Page) ValidateLayout()

ValidateLayout makes the content fill the page.

type Services added in v0.2.0

type Services struct {
	App           platform.App
	Lifecycle     platform.Lifecycle
	Orientation   platform.OrientationService
	DeepLinks     platform.DeepLinks
	Media         platform.Media
	Audio         platform.Audio
	Accessibility platform.Accessibility
}

Services is the optional platform context a shell can be bound to. It gives the shell (and the app that holds it) the process-level facts a window alone cannot provide: application lifecycle, and through App the capability services (permissions, files, camera, notifications, ...).

Services is deliberately a small value rather than another global: a test can supply a fake lifecycle, and an app can keep the same value for the lifetime of its process.

func NewServices added in v0.2.0

func NewServices(app platform.App) *Services

NewServices derives the available services from a backend. The lifecycle is optional; callers must still work when it is nil.

func (*Services) Announce added in v0.2.1

func (s *Services) Announce(message string) error

Announce sends a live-region message to the platform screen reader.

func (*Services) CaptureImage added in v0.2.1

func (s *Services) CaptureImage() (platform.FileRef, error)

CaptureImage opens the native camera, or reports that none is available.

func (*Services) CurrentOrientation added in v0.2.0

func (s *Services) CurrentOrientation() platform.Orientation

Orientation reports the current display orientation, or Unknown when the backend has no orientation service.

func (s *Services) InitialDeepLink() string

InitialDeepLink returns the URI that launched the app, or empty.

func (s *Services) OnDeepLink(fn func(string)) (stop func())

OnDeepLink subscribes to URLs delivered while the app is running.

func (*Services) OnLifecycle added in v0.2.0

func (s *Services) OnLifecycle(fn func(platform.LifecycleState)) (stop func())

OnLifecycle subscribes to lifecycle changes. It returns a no-op stop function when no lifecycle service is available.

func (*Services) OnOrientation added in v0.2.0

func (s *Services) OnOrientation(fn func(platform.Orientation)) (stop func())

OnOrientation subscribes to orientation changes. It returns a no-op stop function when no service is available.

func (*Services) PickImage added in v0.2.0

func (s *Services) PickImage() (platform.FileRef, error)

PickImage opens the native image picker, or reports that none is available.

func (*Services) PlayPCM added in v0.2.1

func (s *Services) PlayPCM(rate, channels int, data []byte) (func(), error)

PlayPCM plays signed 16-bit PCM, or reports that audio is unavailable.

func (*Services) RecordPCM added in v0.2.1

func (s *Services) RecordPCM(rate, channels int, fn func([]byte)) (func(), error)

RecordPCM starts microphone capture; the callback runs on the audio thread.

func (*Services) State added in v0.2.0

func (s *Services) State() platform.LifecycleState

State reports the current lifecycle state, or LifecycleActive when the backend has no lifecycle service.

type Shell

type Shell struct {
	meui.BaseContainer

	// OnAction fires for an app-bar/large-title action.
	OnAction func(string)
	// OnAvatar fires when the large-title avatar is tapped.
	OnAvatar func()
	// OnPageChanged fires after a destination changes.
	OnPageChanged func(int)
	// OnLayout is called after every reflow, with the page viewport in page-local
	// coordinates. Put inner card frames here.
	OnLayout func(graphics.Rect)
	// OnFAB fires when the floating button is tapped.
	OnFAB func()
	// OnBack runs before the shell's own back behaviour. Return true when the
	// app handled the gesture; returning false lets the shell pop a page and,
	// at the first page, lets the platform close the window.
	OnBack func() bool
	// OnLifecycle fires for application lifecycle changes after Bind has been
	// given Services. It runs on the UI thread.
	OnLifecycle func(platform.LifecycleState)
	// OnLowMemory fires when the OS asks the app to release caches. The shell
	// does not own the app's caches, so this is a hook rather than automatic.
	OnLowMemory func()
	// OnOrientationChanged fires after Bind has been given Services.
	OnOrientationChanged func(platform.Orientation)
	// OnDeepLink fires for an app link delivered while the app is running.
	OnDeepLink func(string)
	// AccessibilityNodes lets the app publish labels and hit boxes for its own
	// GL-drawn content. The shell appends them to its navigation/action nodes on
	// every accessibility sync.
	AccessibilityNodes func() []platform.AccessibilityNode
	// OnAccessibilityAction receives activation of an app-owned node. It returns
	// true when the app handled the action.
	OnAccessibilityAction func(id string) bool
	// contains filtered or unexported fields
}

Shell is the mobile scaffold. See the package comment for the QML shape.

func New

func New(opts Options) *Shell

func NewShell

func NewShell() *Shell

NewShell builds an empty shell. QML calls this; Go callers normally use New.

func (*Shell) AddChild

func (s *Shell) AddChild(child meui.Widget)

AddChild adds a MobilePage (or any other widget). Non-page children are tracked but not made destinations.

func (*Shell) Back

func (s *Shell) Back() bool

Back pops the explicit history stack, then falls back to the previous tab and reports whether it moved. Bind wires the window's back gesture to it when the root supports SetOnBack.

func (*Shell) Bind

func (s *Shell) Bind(w platform.Window, root *meui.Window, services ...*Services)

Bind attaches the shell to its platform window and its root. The root is the content window used for modals; the platform window supplies resize, insets and size. Call it after App.AddWindow.

func (*Shell) ClearHistory added in v0.2.1

func (s *Shell) ClearHistory()

ClearHistory discards the explicit back stack.

func (*Shell) CompactWidth

func (s *Shell) CompactWidth() float32

CompactWidth reports the threshold.

func (*Shell) ContentRect

func (s *Shell) ContentRect() graphics.Rect

ContentRect returns the page viewport in page-local coordinates.

func (*Shell) Current

func (s *Shell) Current() int

Current reports the active destination.

func (*Shell) FABVisible

func (s *Shell) FABVisible() bool

FABVisible reports whether the floating button is shown.

func (*Shell) HistoryDepth added in v0.2.1

func (s *Shell) HistoryDepth() int

HistoryDepth reports how many programmatic drill-downs can be popped.

func (*Shell) Insets

func (s *Shell) Insets() platform.Insets

Insets returns the current safe-area insets.

func (*Shell) KeyboardAvoidance

func (s *Shell) KeyboardAvoidance() bool

KeyboardAvoidance reports the setting.

func (*Shell) KeyboardInset

func (s *Shell) KeyboardInset() float32

KeyboardInset reports the keyboard height used by the last layout.

func (*Shell) PageCount

func (s *Shell) PageCount() int

PageCount reports the number of destinations.

func (*Shell) Pages

func (s *Shell) Pages() []*Page

Pages returns the destinations in declaration order.

func (*Shell) Paint

func (s *Shell) Paint(canvas *graphics.Canvas, rect graphics.Rect)

Paint draws the shell background, the page, the chrome and the overlays.

func (*Shell) PanelAt

func (s *Shell) PanelAt(x, y float32) meui.Widget

PanelAt routes to the chrome first, then the active page.

func (*Shell) PushPage added in v0.2.1

func (s *Shell) PushPage(i int)

PushPage selects a destination and records the previous one on the back stack. Use it for programmatic drill-down; tapping a tab uses ShowPage and does not create history.

func (*Shell) Relayout

func (s *Shell) Relayout()

Relayout reflows and asks for a paint.

func (*Shell) RevealFocused

func (s *Shell) RevealFocused() bool

RevealFocused scrolls the nearest ScrollPane ancestor of the focused widget so the widget is inside the visible height above the keyboard. It returns true when the scroll moved.

func (*Shell) SafeArea

func (s *Shell) SafeArea() bool

SafeArea reports the setting.

func (*Shell) Services added in v0.2.0

func (s *Shell) Services() *Services

Services returns the attached platform services, or nil.

func (*Shell) SetActions

func (s *Shell) SetActions(actions []Action) *Shell

SetActions replaces the header actions.

func (*Shell) SetAvatar

func (s *Shell) SetAvatar(text string, onClick func()) *Shell

SetAvatar shows the large-title avatar. An empty text hides it.

func (*Shell) SetBoundProperty

func (s *Shell) SetBoundProperty(name string, value interface{})

SetBoundProperty implements the QML binding hook.

func (*Shell) SetCompactWidth

func (s *Shell) SetCompactWidth(width float32) *Shell

SetCompactWidth changes the width below which the bottom bar is used instead of the rail. The default is 700. Mobile hosts whose window units are physical pixels can raise it; a 1080px phone with density 2.75 is 393dp.

func (*Shell) SetFABLabel

func (s *Shell) SetFABLabel(label string) *Shell

SetFABLabel sets the floating button's glyph.

func (*Shell) SetFABVisible

func (s *Shell) SetFABVisible(on bool) *Shell

SetFABVisible shows or hides the floating action button.

func (*Shell) SetInsets

func (s *Shell) SetInsets(in platform.Insets) *Shell

SetInsets sets the safe-area insets. Bind does this automatically.

func (*Shell) SetKeyboardAvoidance

func (s *Shell) SetKeyboardAvoidance(on bool) *Shell

SetKeyboardAvoidance controls whether the shell reserves the IME height. It is on by default: the navigation bar is lifted above the keyboard and the page viewport ends above it. Turn it off when the page intentionally paints behind the keyboard.

func (*Shell) SetRoot

func (s *Shell) SetRoot(root *meui.Window)

SetRoot attaches the modal root without a platform window. Shot harnesses use it before showing an overlay; Bind also sets it.

func (*Shell) SetSafeArea

func (s *Shell) SetSafeArea(on bool) *Shell

SetSafeArea controls whether the shell subtracts the platform's top/right/ bottom/left insets. It is on by default for headless layouts. Bind turns it off automatically when the content root is already the safe-area rectangle, which is what the Android adapter paints; applying the insets twice is what made a 1080px phone look like a double-inset tablet.

func (*Shell) SetServices added in v0.2.0

func (s *Shell) SetServices(services *Services) *Shell

SetServices installs the optional platform services and subscribes the shell to application lifecycle changes. Passing nil detaches the previous service.

func (*Shell) SetStyle

func (s *Shell) SetStyle(style Style) *Shell

SetStyle sets the shell idiom. Normally called by QML before the first layout.

func (*Shell) SetSubtitle

func (s *Shell) SetSubtitle(subtitle string) *Shell

SetSubtitle sets the fallback subtitle.

func (*Shell) SetTitle

func (s *Shell) SetTitle(title string) *Shell

SetTitle sets the fallback title used when a page has none.

func (*Shell) ShowActionSheet

func (s *Shell) ShowActionSheet(header, message string, items []widgets.ActionSheetItem, onChoose func(string)) *widgets.ActionSheet

ShowActionSheet opens an action sheet and reports choices through onChoose.

func (*Shell) ShowAlert

func (s *Shell) ShowAlert(title, message string, actions []widgets.DialogAction, onAction func(string)) *widgets.AlertDialog

ShowAlert opens the adaptive alert dialog.

func (*Shell) ShowPage

func (s *Shell) ShowPage(i int)

ShowPage makes a destination active and notifies the window.

func (*Shell) ShowSearch

func (s *Shell) ShowSearch(placeholder string, results []widgets.SearchViewResult, onChoose func(string)) *widgets.SearchView

ShowSearch opens a full-screen search view.

func (*Shell) ShowSheet

func (s *Shell) ShowSheet(title, body string) *widgets.BottomSheet

ShowSheet opens a bottom sheet with a wrapped body. It returns the widget so a caller can set OnDismissed.

func (*Shell) Snackbar

func (s *Shell) Snackbar() *widgets.Snackbar

Snackbar exposes the message strip.

func (*Shell) Style

func (s *Shell) Style() Style

Style reports the resolved idiom.

func (*Shell) Toast

func (s *Shell) Toast(text string)

Toast shows a snackbar message.

func (*Shell) ValidateLayout

func (s *Shell) ValidateLayout()

ValidateLayout places the chrome, the pages and the overlays. It is called by the window after every resize and by Relayout.

type Style

type Style int

Style selects the shell idiom. The theme preset is chosen separately (see Preset) because colors are resolved when QML is parsed.

const (
	Auto Style = iota
	Android
	IOS
)

func ParseStyle

func ParseStyle(s string) Style

ParseStyle reads the QML string form.

func (Style) Resolve

func (s Style) Resolve() Style

Resolve turns Auto into the host platform's idiom.

func (Style) String

func (s Style) String() string

Directories

Path Synopsis
examples
phone command
Phone — the mobile kitchen sink, hosted on the desktop.
Phone — the mobile kitchen sink, hosted on the desktop.
phone/phoneapp
Package phoneapp is the mobile kitchen sink as an importable app.
Package phoneapp is the mobile kitchen sink as an importable app.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL