euv_ui/router/struct.rs
1use super::*;
2
3/// Resolved route match containing normalized path, dynamic `:param` captures, and `?key=value` query entries.
4#[derive(Clone, Data, Debug, Default, Eq, PartialEq)]
5pub struct EuvRouteMatch {
6 /// Clean route path without query string (e.g. `"/users/42"`).
7 pub(crate) path: String,
8 /// Matched route pattern (e.g. `"/users/:id"`).
9 pub(crate) pattern: String,
10 /// Human-readable page title associated with the route.
11 pub(crate) title: String,
12 /// Extracted dynamic path parameters.
13 pub(crate) params: HashMap<String, String>,
14 /// Extracted URL query parameters.
15 pub(crate) query: HashMap<String, String>,
16}
17
18/// Declarative route entry stored inside `EuvRouter`.
19#[derive(Clone, CustomDebug, Data)]
20pub struct EuvRouteDef {
21 /// Route path pattern supporting static segments and `:param` captures.
22 pub(crate) pattern: String,
23 /// Human-readable route title.
24 pub(crate) title: String,
25 /// Optional explicit retention override (`None` delegates to the mounted page's `Lifecycle::retention_policy`).
26 #[get(skip)]
27 pub(crate) retention: Option<PageRetention>,
28 /// Page builder invoked lazily when this route first becomes active.
29 #[debug(skip)]
30 #[get(skip)]
31 pub(crate) builder: Rc<dyn Fn(&EuvRouteMatch) -> NodeId>,
32}
33
34/// Shared lazy page builder wrapper avoiding verbose closure type signatures across router APIs.
35#[derive(Clone, CustomDebug)]
36pub struct EuvRouteBuilderFn {
37 /// Underlying shared route page factory closure.
38 #[debug(skip)]
39 pub(crate) func: Rc<dyn Fn(&EuvRouteMatch) -> NodeId>,
40}
41
42/// Resolved route lookup result pairing matched metadata, optional builder, and optional retention override.
43#[derive(Clone, CustomDebug)]
44pub struct EuvResolvedRoute {
45 /// Matched path, pattern, dynamic params, and query map.
46 pub(crate) matched: EuvRouteMatch,
47 /// Optional matched page builder wrapper.
48 pub(crate) builder: Option<EuvRouteBuilderFn>,
49 /// Optional explicit retention override.
50 pub(crate) retention: Option<PageRetention>,
51}
52
53/// Lifecycle observer vectors and departed scroll offset collected during a fused router swap.
54#[derive(Default)]
55pub(crate) struct EuvFusedSwapState {
56 /// Leaving page lifecycle observers to freeze outside the scene write lock.
57 pub(crate) prev_obs: Vec<(NodeId, Rc<dyn Lifecycle>)>,
58 /// Entering page lifecycle observers to resume or activate outside the scene write lock.
59 pub(crate) page_obs: Vec<(NodeId, Rc<dyn Lifecycle>)>,
60 /// Scroll offset captured from the leaving page wrapper before hiding it.
61 pub(crate) prev_scroll: Point,
62}
63
64/// Snapshot describing a cached route's retention policy and live `LifecyclePhase`.
65#[derive(Clone, Data, Debug, Eq, PartialEq)]
66pub struct EuvRouteLifecycleEntry {
67 /// Normalized route path.
68 pub(crate) path: String,
69 /// Active retention policy (`Destroy`, `Freeze`, or `Alive`).
70 #[get(type(copy))]
71 pub(crate) retention: PageRetention,
72 /// Current lifecycle phase (`Active`, `Frozen`, `Mounted`).
73 #[get(type(copy))]
74 pub(crate) phase: LifecyclePhase,
75 /// Cumulative number of activations for this route.
76 #[get(type(copy))]
77 pub(crate) activations: u32,
78}
79
80/// Internal cached page record managed lazily by `EuvRouterOutlet`.
81#[derive(Clone, CustomDebug)]
82pub(crate) struct EuvCachedPage {
83 /// Per-page `ScrollView` wrapper toggled between `Display::Flex` and `Display::None`, preserving exact scroll offsets across freezes.
84 pub(crate) wrapper: NodeId,
85 /// Mounted page root node returned by the route builder or `Component::mount`.
86 pub(crate) page_node: NodeId,
87 /// Dedicated reactive ownership scope frozen/resumed/disposed on route transitions.
88 pub(crate) scope: Scope,
89 /// Resolved retention strategy for this page.
90 pub(crate) retention: PageRetention,
91 /// Current lifecycle phase of this cached page.
92 pub(crate) phase: LifecyclePhase,
93 /// Theme tokens currently applied to this page subtree for zero-teardown in-place theme remapping.
94 pub(crate) applied_tokens: ThemeTokens,
95 /// Whether `applied_tokens` holds an initialized theme snapshot.
96 pub(crate) has_applied_tokens: bool,
97 /// Dynamic OTA page revision active when this page was rendered.
98 pub(crate) dynamic_rev: u64,
99 /// Cumulative activation counter.
100 pub(crate) activations: u32,
101 /// Monotonic `PageLifecycleController` page identifier for deterministic LRU budget eviction.
102 pub(crate) page_id: u64,
103 /// True when the mounted page subtree contains at least one `Lifecycle` observer node.
104 pub(crate) has_lifecycle: bool,
105}
106
107/// Internal snapshot of an active or just-released interactive horizontal page drag preview.
108#[derive(Clone, Debug)]
109pub(crate) struct EuvDragPreviewState {
110 /// Adjacent destination route path currently positioned beside the active page.
111 pub(crate) target_path: String,
112 /// Wrapper `NodeId` of the adjacent preview page.
113 pub(crate) target_wrapper: NodeId,
114 /// Direction (`+1.0` forward/next on left drag, `-1.0` backward/prev on right drag).
115 pub(crate) direction: f32,
116 /// Current horizontal translation offset `dx` of the active page in logical pixels.
117 pub(crate) offset_x: f32,
118 /// Outlet width captured during the drag.
119 pub(crate) width: f32,
120}
121
122/// Shared immutable context bundle used by `EuvRouterOutlet` when lazily mounting a route wrapper.
123#[derive(Clone)]
124pub(crate) struct EuvOutletMountEnv {
125 /// Bound router handle.
126 pub(crate) router: EuvRouter,
127 /// Fallback route builder.
128 pub(crate) fallback: Rc<dyn Fn(&EuvRouteMatch) -> NodeId>,
129 /// Optional dynamic OTA update hub.
130 pub(crate) hub_opt: Option<DynamicUpdateHub>,
131 /// Default retention policy when unspecified by route or component.
132 pub(crate) default_ret: PageRetention,
133 /// Build context used to mount new pages.
134 pub(crate) ctx: Context,
135 /// Retained scene handle.
136 pub(crate) scene: SceneHandle,
137 /// Outlet host node handle.
138 pub(crate) host: NodeId,
139 /// Shared page lifecycle controller enforcing bounded cold-page LRU eviction.
140 pub(crate) lifecycle: Rc<RefCell<PageLifecycleController>>,
141}
142
143/// Internal mutable history stack shared across cloned `EuvRouter` handles.
144#[derive(Clone, CustomDebug, Data)]
145pub(crate) struct EuvRouterInner {
146 /// Registered declarative routes in match priority order.
147 pub(crate) routes: Vec<EuvRouteDef>,
148 /// Ordered navigation history stack.
149 pub(crate) history: Vec<String>,
150 /// Current cursor index inside `history`.
151 #[get(type(copy))]
152 pub(crate) cursor: usize,
153 /// Optional dynamic OTA hub allowing remote hot-pushed page overrides.
154 #[debug(skip)]
155 #[get(skip)]
156 pub(crate) dynamic_hub: Option<DynamicUpdateHub>,
157 /// Default retention policy applied when neither route nor component overrides it.
158 #[get(type(copy))]
159 pub(crate) default_retention: PageRetention,
160}
161
162/// Production cross-platform UI router with reactive history stack, lazy page mounting, and `PageRetention` lifecycle management.
163#[derive(Clone, CustomDebug, Data)]
164pub struct EuvRouter {
165 /// Reactive active route path signal.
166 #[get(type(copy))]
167 pub(crate) current_path: Signal<String>,
168 /// Reactive back-navigation availability signal.
169 #[get(type(copy))]
170 pub(crate) can_go_back: Signal<bool>,
171 /// Reactive forward-navigation availability signal.
172 #[get(type(copy))]
173 pub(crate) can_go_forward: Signal<bool>,
174 /// Reactive history depth signal.
175 #[get(type(copy))]
176 pub(crate) history_len: Signal<usize>,
177 /// Reactive count of currently frozen cached pages (`PageRetention::Freeze`).
178 #[get(type(copy))]
179 pub(crate) frozen_count: Signal<usize>,
180 /// Reactive count of currently alive background pages (`PageRetention::Alive`).
181 #[get(type(copy))]
182 pub(crate) alive_count: Signal<usize>,
183 /// Reactive snapshot of all mounted/cached route lifecycle entries.
184 #[get(type(copy))]
185 pub(crate) lifecycle_entries: Signal<Vec<EuvRouteLifecycleEntry>>,
186 /// Shared mutable route table and history stack.
187 pub(crate) inner: Rc<RefCell<EuvRouterInner>>,
188 /// Shared retained page/scroll layer registry preserving scroll offsets, input focus, and animation timelines across route transitions.
189 pub(crate) retained_layers: Rc<RefCell<RetainedLayerRegistry>>,
190}
191
192/// Declarative animated router outlet lazily mounting only the active page and enforcing `PageRetention` (`Destroy` / `Freeze` / `Alive`).
193#[derive(Clone, CustomDebug, Data)]
194pub struct EuvRouterOutlet {
195 /// Bound UI router handle.
196 pub(crate) router: EuvRouter,
197 /// Fallback page builder invoked when no registered route matches.
198 #[debug(skip)]
199 #[get(skip)]
200 pub(crate) fallback: Rc<dyn Fn(&EuvRouteMatch) -> NodeId>,
201 /// Optional reactive theme state enabling in-place theme updates without page teardown or scroll loss.
202 #[debug(skip)]
203 #[get(skip)]
204 pub(crate) theme: Option<UiThemeState>,
205 /// Enables standard app double-back-to-exit at the root route with a bottom snackbar/toast prompt.
206 #[get(type(copy))]
207 pub(crate) double_back_exit: bool,
208 /// Bottom prompt message displayed on the first root Back press before a consecutive second Back exits.
209 pub(crate) exit_prompt: String,
210 /// Optional ordered route sequence used to compute coupled 1:1 left/right directional slide transitions across tabs and swipes.
211 pub(crate) route_order: Vec<String>,
212 /// Optional reactive per-page scroll container padding synchronized with the hosting shell.
213 #[get(skip)]
214 pub(crate) page_padding: Option<Signal<Edges>>,
215}
216
217/// Declarative navigation link pushing a target path onto an `EuvRouter` when clicked.
218#[derive(Clone, Data, Debug, Props)]
219pub struct EuvLink {
220 /// Target route path (e.g. `"/themes"`).
221 pub(crate) to: String,
222 /// Visible link label.
223 pub(crate) label: String,
224 /// Bound router handle.
225 pub(crate) router: EuvRouter,
226 /// Active theme tokens.
227 #[get(type(copy))]
228 pub(crate) tokens: ThemeTokens,
229}