Skip to main content

make_driver

Function make_driver 

Source
pub fn make_driver(timing: Timing) -> (TransitionDriver, SpringDesc)
Expand description

The page-transition resolve/drive path: the framework’s own reduce- motion collapse policy, re-exported so an app-authored animation reuses it rather than re-deriving it.

resolve_spec applies Theme.motion.reduce_motion‘s hard accessibility rule to a TransitionSpec — collapsing any animated preset to a ≤120ms linear cross-fade — and resolves a bare Timing::ThemeDefault against the active MotionScheme. make_driver then turns the resolved Timing into a running TransitionDriver (advanced each frame via TransitionDriver::advance) plus the SpringDesc to settle it with later (an interactive edge-swipe’s release fling). This is exactly the pair frust-widgets’ own navigator and motion::switcher::PatternSwitcher drive their transitions through — before this re-export, an app widget implementing its own page/dialog animation had to hand-roll the reduce-motion collapse (read Theme.motion.reduce_motion, apply the 120ms + linear + zero-motion rule) instead of calling the framework’s one implementation, so the two would silently drift the next time the framework’s rule changes.

Not otherwise re-exported at frust-widgets’ own crate root (reached here via frust_widgets::nav::transition, a pub mod two levels down) — this is the facade’s job precisely so app code never has to know that.

use frust::{Curve, PageTransition, Theme, Timing, TransitionDriver, TransitionSpec};

// A theme with reduce_motion on: resolve_spec collapses the spec to the
// framework's own linear cross-fade, with no app-side collapse logic.
let mut theme = Theme::neutral();
theme.motion.reduce_motion = true;

let spec = TransitionSpec::duration(PageTransition::SlideUp);
let resolved = frust::resolve_spec(spec, Some(&theme.motion));
assert_eq!(resolved.preset, PageTransition::ReducedCrossfade);
assert_eq!(
    resolved.timing,
    Timing::Duration(std::time::Duration::from_millis(120), Curve::Linear)
);

let (driver, _settle_spring) = frust::make_driver(resolved.timing);
assert!(matches!(driver, TransitionDriver::Auto(_)));

Build a fresh TransitionDriver (already running 0 → 1) plus the spring to use for a later manual settle, from a Timing.