use std::rc::Rc;
use frust_core::AnyView;
use super::controller::NavigatorController;
use super::options::{PageBuilder, PageVisibility, RouteChangeCallback, VisibilityCallback};
use super::path::Location;
use super::route_state::RouteStack;
use super::transition::{PageTransition, TransitionSpec};
#[allow(unused_imports)]
use super::navigator::NavigatorWidget;
#[allow(unused_imports)]
use super::options::{BackPolicy, PushOptions};
#[allow(unused_imports)]
use frust_core::{View, Widget};
pub struct NavigatorView<State: 'static> {
pub(super) controller: NavigatorController<State>,
pub(super) initial: PageBuilder<State>,
pub(super) default_transition: TransitionSpec,
pub(super) pop_swipe: Option<bool>,
pub(super) platform_pop_swipe: Option<bool>,
pub(super) root_visibility: Option<VisibilityCallback>,
pub(super) cull_covered_builds: bool,
pub(super) root_route: Option<Location>,
pub(super) route_change: Option<RouteChangeCallback>,
}
impl<State: 'static> NavigatorView<State> {
pub fn transition(mut self, spec: TransitionSpec) -> Self {
self.default_transition = spec;
self
}
pub fn pop_swipe(mut self, enabled: bool) -> Self {
self.pop_swipe = Some(enabled);
self
}
pub fn platform_pop_swipe(mut self, enabled: bool) -> Self {
self.platform_pop_swipe = Some(enabled);
self
}
pub fn on_root_visibility(mut self, f: impl Fn(PageVisibility) + 'static) -> Self {
self.root_visibility = Some(Rc::new(f));
self
}
pub fn cull_covered_builds(mut self, enabled: bool) -> Self {
self.cull_covered_builds = enabled;
self
}
pub fn root_route(mut self, location: Location) -> Self {
self.root_route = Some(location);
self
}
pub fn on_route_change(mut self, f: impl Fn(&RouteStack) + 'static) -> Self {
self.route_change = Some(Rc::new(f));
self
}
pub(super) fn resolve_pop_swipe(&self) -> bool {
self.pop_swipe
.or(self.platform_pop_swipe)
.unwrap_or(self.default_transition.preset == PageTransition::IosPush)
}
}
pub fn navigator<State: 'static>(
controller: &NavigatorController<State>,
initial: impl Fn() -> AnyView<State> + 'static,
) -> NavigatorView<State> {
NavigatorView {
controller: controller.clone(),
initial: Rc::new(initial),
default_transition: TransitionSpec::NONE,
pop_swipe: None,
platform_pop_swipe: None,
root_visibility: None,
cull_covered_builds: false,
root_route: None,
route_change: None,
}
}
pub fn overlay_host<State: 'static>(
controller: &NavigatorController<State>,
app: impl Fn() -> AnyView<State> + 'static,
) -> NavigatorView<State> {
navigator(controller, app)
.pop_swipe(false)
.transition(TransitionSpec::NONE)
}