Skip to main content

Module patterns

Module patterns 

Source
Expand description

Core transition patterns: the object-safe TransitionPattern trait plus the four source-verified patterns — FadeThrough, SharedAxis (X/Y/Scaled), FadeScale, and ContainerTransform (rect-to-rect morph + fade-through composite) — that super::switcher::PatternSwitcher stages an outgoing/incoming child pair under. A design system’s own patterns live in its own crate (frust_glyph::motion is the shipped example) and implement the same public trait from there.

§Pure staging math, no widgets

A pattern is pure staging math: given a 0.0..=1.0 transition progress (p), a reverse flag, and the container Size, it yields per-child paint parameters (PatternLayer — {alpha, dx, dy, scale}) for the incoming and exiting children. It never touches a widget, so the staging numbers are table-testable in isolation (mirroring nav::transition::resolve_layers’s pure-geometry precedent); the switcher is the sole consumer that applies a resolved PatternLayer via push_layer/push_transform and a pod-origin offset.

§Progress: raw for position, clamped for opacity

p is raw — a spring Timing can overshoot past 1.0, and that overshoot is applied to position/scale so a slide visibly springs past its rest spot. Opacity always uses the [0, 1]-clamped value (push_layer alpha is never meaningful outside that range) — the same split nav::transition::resolve_layers uses.

§Source-verified staging numbers

Every constant below is either a Material 3 published value or a source-verified Flutter animations-package number, cited per constant per docs/CODE_STANDARDS.md’s named-constant rule.

§Scaffold contract

This file owns its own contents only — the TransitionPattern trait and the four patterns above all live here and never edit motion/mod.rs’s module list or re-export block (see that module’s docs). The trait’s size parameter is a deliberate extension point the hero-rect-bearing patterns hang off of, kept in the signature now so a boxed dyn TransitionPattern never needs a shape change.

Structs§

ContainerTransform
Material 3 “container transform” (Flutter OpenContainer semantics): the incoming content morphs from a captured source rect to a target rect while opacity fades the source content out and the incoming content in.
FadeScale
Material 3 “fade scale” (Flutter FadeScaleTransition): the incoming child fades in over the first 30% of the timeline while scaling [FADE_SCALE_SCALE_START]→1.0 over the full timeline ([FADE_SCALE_SCALE_CURVE]); the exiting child fades only (no scale). Non-directional — reverse has no geometric effect (it selects the faster FADE_SCALE_REVERSE duration at the switcher’s timing layer instead). The idiomatic pattern for a dialog/menu/FAB appearing over stable content.
FadeThrough
Material 3 “fade through”: the outgoing child fades 1→0 over the first 6/20 of the timeline then holds, while the incoming child holds at [FADE_THROUGH_SCALE_START] scale / 0 opacity for that 6/20 then fades in and scales up to 1.0 over the remaining 14/20. Non-directional (no slide) — reverse has no effect. The idiomatic pattern for a destination change with no spatial relationship (bottom-nav switch, account switch), and the reduce_motion collapse target.
PatternLayer
Per-child paint parameters for one frame of a pattern transition: a paint offset (added to the child’s pod origin, so paint and hit-testing move together), an opacity (composited via push_layer), and a uniform scale (composited via push_transform about the child’s centre).

Enums§

ContainerFade
How a ContainerTransform stages opacity while its bounds morph (the fade / fadeThrough variants).
SharedAxis
Which axis (or the scaled variant) a SharedAxis transition moves along.

Constants§

CONTAINER_TRANSFORM_DURATION
ContainerTransform default duration — the Material 3 container-transform / Flutter OpenContainer 300ms morph.
FADE_SCALE_FORWARD
Fade-scale default forward duration — Flutter FadeScaleTransition’s 150ms enter. A source-verified pattern-native constant the switcher’s caller can pass to .timing(...); the switcher’s own default resolves from the theme instead.
FADE_SCALE_REVERSE
Fade-scale default reverse duration — Flutter FadeScaleTransition’s 75ms exit (“exits always faster than entrances”). See FADE_SCALE_FORWARD.

Traits§

TransitionPattern
Pure staging math for a keyed child switch: maps a 0.0..=1.0 transition progress onto per-child PatternLayers for the incoming and exiting children. See the module docs for the raw-vs-clamped progress contract.