Skip to content

Commit eeb43a9

Browse files
committed
Remove state param from lifecycle events
1 parent 17ba861 commit eeb43a9

File tree

6 files changed

+39
-43
lines changed

6 files changed

+39
-43
lines changed

crates/egui_router/examples/async_router.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ async fn main() -> eframe::Result<()> {
4848
router.navigate(&mut sender, route).ok();
4949
}
5050
RouterMessage::Back => {
51-
router.back(&mut sender).ok();
51+
router.back().ok();
5252
}
5353
});
5454

crates/egui_router/examples/route_lifecycle.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ async fn main() -> eframe::Result<()> {
4747
router.navigate(state, route).ok();
4848
}
4949
RouterMessage::Back => {
50-
router.back(state).ok();
50+
router.back().ok();
5151
}
5252
});
5353

@@ -103,19 +103,19 @@ impl Route<AppState> for HomePage {
103103
});
104104
}
105105

106-
fn on_showing(&mut self, _state: &mut AppState) {
106+
fn on_showing(&mut self) {
107107
self.events.push("on_showing (transition back started)");
108108
}
109109

110-
fn on_shown(&mut self, _state: &mut AppState) {
110+
fn on_shown(&mut self) {
111111
self.events.push("on_shown (fully visible)");
112112
}
113113

114-
fn on_hiding(&mut self, _state: &mut AppState) {
114+
fn on_hiding(&mut self) {
115115
self.events.push("on_hiding (transition away started)");
116116
}
117117

118-
fn on_hide(&mut self, _state: &mut AppState) {
118+
fn on_hide(&mut self) {
119119
self.events.push("on_hide (fully hidden)");
120120
}
121121
}
@@ -154,19 +154,19 @@ impl Route<AppState> for DetailPage {
154154
});
155155
}
156156

157-
fn on_showing(&mut self, _state: &mut AppState) {
157+
fn on_showing(&mut self) {
158158
self.events.push("on_showing (transition back started)");
159159
}
160160

161-
fn on_shown(&mut self, _state: &mut AppState) {
161+
fn on_shown(&mut self) {
162162
self.events.push("on_shown (fully visible)");
163163
}
164164

165-
fn on_hiding(&mut self, _state: &mut AppState) {
165+
fn on_hiding(&mut self) {
166166
self.events.push("on_hiding (transition away started)");
167167
}
168168

169-
fn on_hide(&mut self, _state: &mut AppState) {
169+
fn on_hide(&mut self) {
170170
self.events.push("on_hide (fully hidden)");
171171
}
172172
}
@@ -210,19 +210,19 @@ impl Route<AppState> for NoSwipePage {
210210
Some(false)
211211
}
212212

213-
fn on_showing(&mut self, _state: &mut AppState) {
213+
fn on_showing(&mut self) {
214214
self.events.push("on_showing (transition back started)");
215215
}
216216

217-
fn on_shown(&mut self, _state: &mut AppState) {
217+
fn on_shown(&mut self) {
218218
self.events.push("on_shown (fully visible)");
219219
}
220220

221-
fn on_hiding(&mut self, _state: &mut AppState) {
221+
fn on_hiding(&mut self) {
222222
self.events.push("on_hiding (transition away started)");
223223
}
224224

225-
fn on_hide(&mut self, _state: &mut AppState) {
225+
fn on_hide(&mut self) {
226226
self.events.push("on_hide (fully hidden)");
227227
}
228228
}

crates/egui_router/examples/router.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ async fn main() -> eframe::Result<()> {
5656
state.0.navigate(&mut state.1, route).unwrap();
5757
}
5858
RouterMessage::Back => {
59-
state.0.back(&mut state.1).unwrap();
59+
state.0.back().unwrap();
6060
}
6161
});
6262
}

crates/egui_router/examples/router_minimal.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ async fn main() -> eframe::Result<()> {
3434
router.navigate(&mut inbox, route).ok();
3535
}
3636
RouterMessage::Back => {
37-
router.back(&mut inbox).ok();
37+
router.back().ok();
3838
}
3939
});
4040

crates/egui_router/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,19 @@ pub trait Route<State = ()> {
3232

3333
/// Called when this route starts becoming visible again (transition starts).
3434
/// E.g., when a back navigation begins and this route starts animating in.
35-
fn on_showing(&mut self, _state: &mut State) {}
35+
fn on_showing(&mut self) {}
3636

3737
/// Called when this route is fully visible (transition completes).
3838
/// E.g., when a back navigation finishes and this route is fully shown.
39-
fn on_shown(&mut self, _state: &mut State) {}
39+
fn on_shown(&mut self) {}
4040

4141
/// Called when this route starts being hidden (transition starts).
4242
/// E.g., when a forward navigation begins and this route starts animating out.
43-
fn on_hiding(&mut self, _state: &mut State) {}
43+
fn on_hiding(&mut self) {}
4444

4545
/// Called when this route is fully hidden (transition completes).
4646
/// E.g., when a forward navigation finishes and another route is now on top.
47-
fn on_hide(&mut self, _state: &mut State) {}
47+
fn on_hide(&mut self) {}
4848

4949
/// Override the router's swipe-back gesture setting for this route.
5050
/// Return `Some(true)` to enable, `Some(false)` to disable, or `None` to

crates/egui_router/src/router.rs

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -142,14 +142,14 @@ impl<State: 'static, H: History + Default> EguiRouter<State, H> {
142142
if self.history.len() >= 2 {
143143
let idx = self.history.len() - 2;
144144
if let Ok(route) = &mut self.history[idx].route {
145-
route.on_hiding(state);
145+
route.on_hiding();
146146
}
147147
}
148148

149149
// Fire on_showing on the newly created route
150150
if let Some(last) = self.history.last_mut() {
151151
if let Ok(route) = &mut last.route {
152-
route.on_showing(state);
152+
route.on_showing();
153153
}
154154
}
155155

@@ -198,21 +198,21 @@ impl<State: 'static, H: History + Default> EguiRouter<State, H> {
198198
self.navigate_transition(state, route, self.forward_transition.clone())
199199
}
200200

201-
fn back_impl(&mut self, state: &mut State, transition_config: TransitionConfig) {
201+
fn back_impl(&mut self, transition_config: TransitionConfig) {
202202
if self.history.len() > 1 {
203203
let mut leaving_route = self.history.pop();
204204

205205
// Fire on_hiding on the leaving route
206206
if let Some(ref mut leaving) = leaving_route {
207207
if let Ok(route) = &mut leaving.route {
208-
route.on_hiding(state);
208+
route.on_hiding();
209209
}
210210
}
211211

212212
// Fire on_showing on the route that is now being revealed
213213
if let Some(last) = self.history.last_mut() {
214214
if let Ok(route) = &mut last.route {
215-
route.on_showing(state);
215+
route.on_showing();
216216
}
217217
}
218218

@@ -225,19 +225,15 @@ impl<State: 'static, H: History + Default> EguiRouter<State, H> {
225225
}
226226

227227
/// Go back with a custom transition
228-
pub fn back_transition(
229-
&mut self,
230-
state: &mut State,
231-
transition_config: TransitionConfig,
232-
) -> RouterResult {
228+
pub fn back_transition(&mut self, transition_config: TransitionConfig) -> RouterResult {
233229
self.history_kind.back()?;
234-
self.back_impl(state, transition_config);
230+
self.back_impl(transition_config);
235231
Ok(())
236232
}
237233

238234
/// Go back with the default transition
239-
pub fn back(&mut self, state: &mut State) -> RouterResult {
240-
self.back_transition(state, self.backward_transition.clone())
235+
pub fn back(&mut self) -> RouterResult {
236+
self.back_transition(self.backward_transition.clone())
241237
}
242238

243239
/// Replace the current route with a custom transition
@@ -266,7 +262,7 @@ impl<State: 'static, H: History + Default> EguiRouter<State, H> {
266262
// Fire on_hiding on the leaving route
267263
if let Some(ref mut leaving) = leaving_route {
268264
if let Ok(route) = &mut leaving.route {
269-
route.on_hiding(state);
265+
route.on_hiding();
270266
}
271267
}
272268

@@ -285,7 +281,7 @@ impl<State: 'static, H: History + Default> EguiRouter<State, H> {
285281
// Fire on_showing on the newly created route
286282
if let Some(last) = self.history.last_mut() {
287283
if let Ok(route) = &mut last.route {
288-
route.on_showing(state);
284+
route.on_showing();
289285
}
290286
}
291287

@@ -349,7 +345,7 @@ impl<State: 'static, H: History + Default> EguiRouter<State, H> {
349345
.retain(|r| r.state <= route_state || r.state == active_state);
350346

351347
if route_state < active_state {
352-
self.back_impl(state, self.backward_transition.clone());
348+
self.back_impl(self.backward_transition.clone());
353349
}
354350
} else {
355351
self.navigate_impl(state, &path, self.forward_transition.clone(), state_index)
@@ -402,33 +398,33 @@ impl<State: 'static, H: History + Default> EguiRouter<State, H> {
402398
// Leaving route is fully hidden
403399
if let Some(ref mut leaving) = transition.leaving_route {
404400
if let Ok(route) = &mut leaving.route {
405-
route.on_hide(state);
401+
route.on_hide();
406402
}
407403
}
408404
// Current top is fully shown again
409405
if let Some(last) = self.history.last_mut() {
410406
if let Ok(route) = &mut last.route {
411-
route.on_shown(state);
407+
route.on_shown();
412408
}
413409
}
414410
} else {
415411
// Forward/replace completed
416412
if let Some(ref mut leaving) = transition.leaving_route {
417413
// Replace: leaving route is fully hidden
418414
if let Ok(route) = &mut leaving.route {
419-
route.on_hide(state);
415+
route.on_hide();
420416
}
421417
} else if self.history.len() >= 2 {
422418
// Forward: previous top is now fully hidden
423419
let idx = self.history.len() - 2;
424420
if let Ok(route) = &mut self.history[idx].route {
425-
route.on_hide(state);
421+
route.on_hide();
426422
}
427423
}
428424
// The new top route is now fully shown
429425
if let Some(last) = self.history.last_mut() {
430426
if let Ok(route) = &mut last.route {
431-
route.on_shown(state);
427+
route.on_shown();
432428
}
433429
}
434430
}
@@ -561,14 +557,14 @@ impl<State: 'static, H: History + Default> EguiRouter<State, H> {
561557
// Fire on_hiding on the popped route
562558
if let Some(ref mut leaving) = popped {
563559
if let Ok(route) = &mut leaving.route {
564-
route.on_hiding(state);
560+
route.on_hiding();
565561
}
566562
}
567563

568564
// Fire on_showing on the route being revealed
569565
if let Some(last) = self.history.last_mut() {
570566
if let Ok(route) = &mut last.route {
571-
route.on_showing(state);
567+
route.on_showing();
572568
}
573569
}
574570

0 commit comments

Comments
 (0)