Skip to main content

navigation

Package navigation provides routing and navigation for the Drift framework.

Constants

TransitionDuration is the default duration for page transitions.

const TransitionDuration = 350 * time.Millisecond

func HandleBackButton

func HandleBackButton() bool

HandleBackButton attempts to pop the active navigator. Returns true if handled (route popped), false if at root.

type BaseNavigatorObserver

BaseNavigatorObserver provides default no-op implementations.

type BaseNavigatorObserver struct{}

func (*BaseNavigatorObserver) DidPop

func (b *BaseNavigatorObserver) DidPop(route, previousRoute Route)

DidPop is a no-op.

func (*BaseNavigatorObserver) DidPush

func (b *BaseNavigatorObserver) DidPush(route, previousRoute Route)

DidPush is a no-op.

func (*BaseNavigatorObserver) DidRemove

func (b *BaseNavigatorObserver) DidRemove(route, previousRoute Route)

DidRemove is a no-op.

func (*BaseNavigatorObserver) DidReplace

func (b *BaseNavigatorObserver) DidReplace(newRoute, oldRoute Route)

DidReplace is a no-op.

type BaseRoute

BaseRoute provides a default implementation of Route lifecycle methods.

type BaseRoute struct {
// contains filtered or unexported fields
}

func NewBaseRoute

func NewBaseRoute(settings RouteSettings) BaseRoute

NewBaseRoute creates a BaseRoute with the given settings.

func (*BaseRoute) DidChangeNext

func (r *BaseRoute) DidChangeNext(nextRoute Route)

DidChangeNext is a no-op by default.

func (*BaseRoute) DidChangePrevious

func (r *BaseRoute) DidChangePrevious(previousRoute Route)

DidChangePrevious is a no-op by default.

func (*BaseRoute) DidPop

func (r *BaseRoute) DidPop(result any)

DidPop is a no-op by default.

func (*BaseRoute) DidPush

func (r *BaseRoute) DidPush()

DidPush is a no-op by default.

func (*BaseRoute) Settings

func (r *BaseRoute) Settings() RouteSettings

Settings returns the route settings.

func (*BaseRoute) WillPop

func (r *BaseRoute) WillPop() bool

WillPop returns true by default, allowing the pop.

type DeepLinkController

DeepLinkController listens for deep links and navigates to matching routes.

type DeepLinkController struct {
RouteForLink func(link platform.DeepLink) (DeepLinkRoute, bool)
OnError func(err error)
// contains filtered or unexported fields
}

func NewDeepLinkController

func NewDeepLinkController(routeForLink func(platform.DeepLink) (DeepLinkRoute, bool), onError func(error)) *DeepLinkController

NewDeepLinkController creates a controller with the route mapper and immediately starts listening for deep links.

func (*DeepLinkController) Stop

func (c *DeepLinkController) Stop()

Stop stops listening for deep links.

type DeepLinkRoute

DeepLinkRoute describes a navigation target from a deep link.

type DeepLinkRoute struct {
Name string
Args any
}

type FadeTransition

FadeTransition animates the opacity of its child.

type FadeTransition struct {
Animation *animation.AnimationController
ChildWidget core.Widget
}

func (FadeTransition) Child

func (f FadeTransition) Child() core.Widget

Child returns the child widget.

func (FadeTransition) CreateElement

func (f FadeTransition) CreateElement() core.Element

CreateElement returns a RenderObjectElement for this FadeTransition.

func (FadeTransition) CreateRenderObject

func (f FadeTransition) CreateRenderObject(ctx core.BuildContext) layout.RenderObject

CreateRenderObject creates the RenderFadeTransition.

func (FadeTransition) Key

func (f FadeTransition) Key() any

Key returns nil (no key).

func (FadeTransition) UpdateRenderObject

func (f FadeTransition) UpdateRenderObject(ctx core.BuildContext, renderObject layout.RenderObject)

UpdateRenderObject updates the RenderFadeTransition.

type MaterialPageRoute

MaterialPageRoute provides a route with Material Design page transitions.

type MaterialPageRoute struct {
BaseRoute

// Builder creates the page content.
Builder func(ctx core.BuildContext) core.Widget
// contains filtered or unexported fields
}

func NewMaterialPageRoute

func NewMaterialPageRoute(builder func(core.BuildContext) core.Widget, settings RouteSettings) *MaterialPageRoute

NewMaterialPageRoute creates a MaterialPageRoute with the given builder and settings.

func (*MaterialPageRoute) Build

func (m *MaterialPageRoute) Build(ctx core.BuildContext) core.Widget

Build returns the page content wrapped in a transition.

func (*MaterialPageRoute) DidPop

func (m *MaterialPageRoute) DidPop(result any)

DidPop is called when the route is popped.

func (*MaterialPageRoute) DidPush

func (m *MaterialPageRoute) DidPush()

DidPush is called when the route is pushed.

func (*MaterialPageRoute) SetInitialRoute

func (m *MaterialPageRoute) SetInitialRoute()

SetInitialRoute marks this as the initial route (no animation).

type Navigator

Navigator manages a stack of routes.

type Navigator struct {
// InitialRoute is the name of the first route to display.
InitialRoute string

// OnGenerateRoute creates routes from route settings.
OnGenerateRoute func(settings RouteSettings) Route

// OnUnknownRoute is called when OnGenerateRoute returns nil.
OnUnknownRoute func(settings RouteSettings) Route

// Observers receive navigation events.
Observers []NavigatorObserver
}

func (Navigator) CreateElement

func (n Navigator) CreateElement() core.Element

CreateElement returns a StatefulElement for this Navigator.

func (Navigator) CreateState

func (n Navigator) CreateState() core.State

CreateState creates the NavigatorState.

func (Navigator) Key

func (n Navigator) Key() any

Key returns nil (no key).

type NavigatorObserver

NavigatorObserver observes navigation events.

type NavigatorObserver interface {
// DidPush is called when a route is pushed.
DidPush(route, previousRoute Route)

// DidPop is called when a route is popped.
DidPop(route, previousRoute Route)

// DidRemove is called when a route is removed.
DidRemove(route, previousRoute Route)

// DidReplace is called when a route is replaced.
DidReplace(newRoute, oldRoute Route)
}

type NavigatorState

NavigatorState is the mutable state for a Navigator.

type NavigatorState interface {
// Push adds a route to the stack.
Push(route Route)

// PushNamed pushes a route by name.
PushNamed(name string, args any)

// PushReplacementNamed replaces the current route by name
PushReplacementNamed(name string, args any)

// Pop removes the current route and optionally returns a result.
Pop(result any)

// PopUntil removes routes until the predicate returns true.
PopUntil(predicate func(Route) bool)

// PushReplacement replaces the current route.
PushReplacement(route Route)

// CanPop returns true if there's a route to pop.
CanPop() bool

// MaybePop pops if possible, returns true if popped.
MaybePop(result any) bool
}

func GlobalNavigator

func GlobalNavigator() NavigatorState

GlobalNavigator returns the active navigator, if any.

func NavigatorOf

func NavigatorOf(ctx core.BuildContext) NavigatorState

NavigatorOf returns the NavigatorState from the nearest Navigator ancestor. Returns nil if no Navigator is found.

type PageRoute

PageRoute is a simpler route without transitions.

type PageRoute struct {
BaseRoute

// Builder creates the page content.
Builder func(ctx core.BuildContext) core.Widget
}

func NewPageRoute

func NewPageRoute(builder func(core.BuildContext) core.Widget, settings RouteSettings) *PageRoute

NewPageRoute creates a PageRoute with the given builder and settings.

func (*PageRoute) Build

func (p *PageRoute) Build(ctx core.BuildContext) core.Widget

Build returns the page content.

type Route

Route represents a screen in the navigation stack.

type Route interface {
// Build creates the widget for this route.
Build(ctx core.BuildContext) core.Widget

// Settings returns the route configuration.
Settings() RouteSettings

// DidPush is called when the route is pushed onto the navigator.
DidPush()

// DidPop is called when the route is popped from the navigator.
DidPop(result any)

// DidChangeNext is called when the next route in the stack changes.
DidChangeNext(nextRoute Route)

// DidChangePrevious is called when the previous route in the stack changes.
DidChangePrevious(previousRoute Route)

// WillPop is called before the route is popped.
// Return false to prevent the pop.
WillPop() bool
}

type RouteSettings

RouteSettings contains route configuration.

type RouteSettings struct {
// Name is the route name (e.g., "/home", "/details").
Name string
// Arguments contains any arguments passed to the route.
Arguments any
}

type SlideDirection

SlideDirection determines the direction of a slide transition.

type SlideDirection int
const (
// SlideFromRight slides content in from the right.
SlideFromRight SlideDirection = iota
// SlideFromLeft slides content in from the left.
SlideFromLeft
// SlideFromBottom slides content in from the bottom.
SlideFromBottom
// SlideFromTop slides content in from the top.
SlideFromTop
)

type SlideTransition

SlideTransition animates a child sliding from a direction.

type SlideTransition struct {
Animation *animation.AnimationController
Direction SlideDirection
ChildWidget core.Widget
}

func (SlideTransition) Child

func (s SlideTransition) Child() core.Widget

Child returns the child widget.

func (SlideTransition) CreateElement

func (s SlideTransition) CreateElement() core.Element

CreateElement returns a RenderObjectElement for this SlideTransition.

func (SlideTransition) CreateRenderObject

func (s SlideTransition) CreateRenderObject(ctx core.BuildContext) layout.RenderObject

CreateRenderObject creates the RenderSlideTransition.

func (SlideTransition) Key

func (s SlideTransition) Key() any

Key returns nil (no key).

func (SlideTransition) UpdateRenderObject

func (s SlideTransition) UpdateRenderObject(ctx core.BuildContext, renderObject layout.RenderObject)

UpdateRenderObject updates the RenderSlideTransition.

type Tab

Tab configures a single tab in a TabScaffold.

type Tab struct {
Item widgets.TabItem
Builder func(ctx core.BuildContext) core.Widget
InitialRoute string
OnGenerateRoute func(settings RouteSettings) Route
OnUnknownRoute func(settings RouteSettings) Route
Observers []NavigatorObserver
}

func NewTab

func NewTab(item widgets.TabItem, builder func(ctx core.BuildContext) core.Widget) Tab

NewTab creates a Tab with a simple root builder.

type TabController

TabController coordinates tab selection state.

type TabController struct {
// contains filtered or unexported fields
}

func NewTabController

func NewTabController(initialIndex int) *TabController

NewTabController creates a controller with the initial index.

func (*TabController) AddListener

func (c *TabController) AddListener(listener func(int)) func()

AddListener registers a listener. Returns an unsubscribe function.

func (*TabController) Index

func (c *TabController) Index() int

Index returns the current tab index.

func (*TabController) SetIndex

func (c *TabController) SetIndex(index int)

SetIndex updates the active tab index.

type TabScaffold

TabScaffold hosts tab navigation with a separate Navigator per tab.

type TabScaffold struct {
Tabs []Tab
Controller *TabController
}

func (TabScaffold) CreateElement

func (t TabScaffold) CreateElement() core.Element

func (TabScaffold) CreateState

func (t TabScaffold) CreateState() core.State

func (TabScaffold) Key

func (t TabScaffold) Key() any

Generated by gomarkdoc