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 ¶
- func Preset(style Style, dark bool) string
- type Action
- type Options
- type Page
- type Services
- func (s *Services) CurrentOrientation() platform.Orientation
- func (s *Services) InitialDeepLink() string
- func (s *Services) OnDeepLink(fn func(string)) (stop func())
- func (s *Services) OnLifecycle(fn func(platform.LifecycleState)) (stop func())
- func (s *Services) OnOrientation(fn func(platform.Orientation)) (stop func())
- func (s *Services) PickImage() (platform.FileRef, error)
- func (s *Services) State() platform.LifecycleState
- type Shell
- func (s *Shell) AddChild(child meui.Widget)
- func (s *Shell) Back() bool
- func (s *Shell) Bind(w platform.Window, root *meui.Window, services ...*Services)
- func (s *Shell) CompactWidth() float32
- func (s *Shell) ContentRect() graphics.Rect
- func (s *Shell) Current() int
- func (s *Shell) FABVisible() bool
- func (s *Shell) Insets() platform.Insets
- func (s *Shell) KeyboardAvoidance() bool
- func (s *Shell) KeyboardInset() float32
- func (s *Shell) PageCount() int
- func (s *Shell) Pages() []*Page
- func (s *Shell) Paint(canvas *graphics.Canvas, rect graphics.Rect)
- func (s *Shell) PanelAt(x, y float32) meui.Widget
- func (s *Shell) Relayout()
- func (s *Shell) RevealFocused() bool
- func (s *Shell) SafeArea() bool
- func (s *Shell) Services() *Services
- func (s *Shell) SetActions(actions []Action) *Shell
- func (s *Shell) SetAvatar(text string, onClick func()) *Shell
- func (s *Shell) SetBoundProperty(name string, value interface{})
- func (s *Shell) SetCompactWidth(width float32) *Shell
- func (s *Shell) SetFABLabel(label string) *Shell
- func (s *Shell) SetFABVisible(on bool) *Shell
- func (s *Shell) SetInsets(in platform.Insets) *Shell
- func (s *Shell) SetKeyboardAvoidance(on bool) *Shell
- func (s *Shell) SetRoot(root *meui.Window)
- func (s *Shell) SetSafeArea(on bool) *Shell
- func (s *Shell) SetServices(services *Services) *Shell
- func (s *Shell) SetStyle(style Style) *Shell
- func (s *Shell) SetSubtitle(subtitle string) *Shell
- func (s *Shell) SetTitle(title string) *Shell
- func (s *Shell) ShowActionSheet(header, message string, items []widgets.ActionSheetItem, onChoose func(string)) *widgets.ActionSheet
- func (s *Shell) ShowAlert(title, message string, actions []widgets.DialogAction, onAction func(string)) *widgets.AlertDialog
- func (s *Shell) ShowPage(i int)
- func (s *Shell) ShowSearch(placeholder string, results []widgets.SearchViewResult, onChoose func(string)) *widgets.SearchView
- func (s *Shell) ShowSheet(title, body string) *widgets.BottomSheet
- func (s *Shell) Snackbar() *widgets.Snackbar
- func (s *Shell) Style() Style
- func (s *Shell) Toast(text string)
- func (s *Shell) ValidateLayout()
- type Style
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Action ¶
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 ¶
NewPage builds an empty page. Label falls back to Title and Icon to "grid" when the destination list is built.
func (*Page) SetBoundProperty ¶
SetBoundProperty implements the QML binding hook.
func (*Page) SetVisible ¶
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
}
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
NewServices derives the available services from a backend. The lifecycle is optional; callers must still work when it is nil.
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 (*Services) InitialDeepLink ¶ added in v0.2.0
InitialDeepLink returns the URI that launched the app, or empty.
func (*Services) OnDeepLink ¶ added in v0.2.0
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
PickImage opens the native image picker, or reports that none is available.
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)
// contains filtered or unexported fields
}
Shell is the mobile scaffold. See the package comment for the QML shape.
func NewShell ¶
func NewShell() *Shell
NewShell builds an empty shell. QML calls this; Go callers normally use New.
func (*Shell) AddChild ¶
AddChild adds a MobilePage (or any other widget). Non-page children are tracked but not made destinations.
func (*Shell) Back ¶
Back moves to the previous destination and reports whether it did. Bind wires the window's back gesture to it when the root supports SetOnBack.
func (*Shell) Bind ¶
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) CompactWidth ¶
CompactWidth reports the threshold.
func (*Shell) ContentRect ¶
ContentRect returns the page viewport in page-local coordinates.
func (*Shell) FABVisible ¶
FABVisible reports whether the floating button is shown.
func (*Shell) KeyboardAvoidance ¶
KeyboardAvoidance reports the setting.
func (*Shell) KeyboardInset ¶
KeyboardInset reports the keyboard height used by the last layout.
func (*Shell) RevealFocused ¶
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) SetActions ¶
SetActions replaces the header actions.
func (*Shell) SetBoundProperty ¶
SetBoundProperty implements the QML binding hook.
func (*Shell) SetCompactWidth ¶
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 ¶
SetFABLabel sets the floating button's glyph.
func (*Shell) SetFABVisible ¶
SetFABVisible shows or hides the floating action button.
func (*Shell) SetKeyboardAvoidance ¶
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 ¶
SetRoot attaches the modal root without a platform window. Shot harnesses use it before showing an overlay; Bind also sets it.
func (*Shell) SetSafeArea ¶
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
SetServices installs the optional platform services and subscribes the shell to application lifecycle changes. Passing nil detaches the previous service.
func (*Shell) SetStyle ¶
SetStyle sets the shell idiom. Normally called by QML before the first layout.
func (*Shell) SetSubtitle ¶
SetSubtitle sets the fallback subtitle.
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) 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) 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.
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. |







