nativeview-scroll-physics 0.1.0-rc.1

Pluggable, zero-allocation scroll physics engine, composable ScrollBehavior decorators, platform presets, and per-container nv.scroll_physics overrides.
Documentation

nativeview-scroll-physics

Standalone, zero-allocation scroll physics module for native-view-engine implementing nativeview_layout::ScrollPhysicsEngine over the closed-form solvers in nativeview-physics.

Capabilities

  • Whole-engine pluggability: swap between PlatformScrollPhysics, custom PooledScrollPhysics<B>, or any independent ScrollPhysicsEngine via LaidOutScene::set_scroll_physics / SkiaBackend::set_scroll_physics.
  • Composable ScrollBehavior decorators: stack BoundaryPhysics (ClampBoundary, RubberBandBoundary), FlingPhysics (ExponentialDecayFling, NoFling), SnapPhysics (FreeScroll, PageSnap, FixedExtentSnap, DetentSnap), SpringReturn, and WheelPhysics (SmoothWheel, InstantWheel) via ComposedScrollBehavior.
  • Platform presets: ScrollPhysicsProfile::{Apple, Android, Windows, Linux} and PlatformScrollPhysics::platform_default(), preserving macOS native-momentum rules.
  • Per-container sparse overrides (nv.scroll_physics): attach ScrollPhysics to any scrollview for zero-overhead per-container bounce, snap, deceleration, spring, or smooth-wheel overrides (auto-honoring Scroll::paging).

Quick Example

use nativeview_layout::{LaidOutScene, TaffyStoreLayout};
use nativeview_physics::{DecaySpec, RubberBandSpec, SmoothWheelSpec};
use nativeview_scroll_physics::{
    ComposedScrollBehavior, ExponentialDecayFling, PageSnap, PlatformScrollPhysics,
    PooledScrollPhysics, RubberBandBoundary, ScrollPhysicsProfile, SmoothWheel,
};

let mut scene = LaidOutScene::new(TaffyStoreLayout::new());
scene.set_scroll_physics(Box::new(PlatformScrollPhysics::new(
    ScrollPhysicsProfile::Apple,
)));

let carousel_behavior = ComposedScrollBehavior::new()
    .with_boundary(RubberBandBoundary(RubberBandSpec::APPLE))
    .with_fling(ExponentialDecayFling(DecaySpec::apple()))
    .with_snap(PageSnap)
    .with_wheel(SmoothWheel(SmoothWheelSpec::apple()));
scene.set_scroll_physics(Box::new(PooledScrollPhysics::new(carousel_behavior)));