Skip to main content

ferroui_android/
i_android_navigation_service.rs

1//! The back button of an activity, as a service: who raises the request,
2//! and the arguments of it.
3
4use ferroui_base::reactive::IDisposable;
5use std::cell::Cell;
6use std::rc::Rc;
7
8pub trait IActivityNavigationService {
9    /// Raised when the user asks to go back.
10    ///
11    /// Disposing the returned value removes the handler.
12    fn back_requested(&self, handler: Rc<dyn Fn(&AndroidBackRequestedEventArgs)>) -> Rc<dyn IDisposable>;
13}
14
15#[derive(Default)]
16pub struct AndroidBackRequestedEventArgs {
17    handled: Cell<bool>,
18}
19
20impl AndroidBackRequestedEventArgs {
21    pub fn new() -> Self {
22        Self::default()
23    }
24
25    pub fn handled(&self) -> bool {
26        self.handled.get()
27    }
28
29    pub fn set_handled(&self, value: bool) {
30        self.handled.set(value);
31    }
32}