A panel that rises from the bottom edge: dragged by its handle or body between detents, swiped down to dismiss.
The release velocity carries on into a spring; where it rests is decided by where that velocity would take it; past the top detent it resists; a scroll inside hands off to the sheet at its top. Esc dismisses. Rising and dragged, it leaves a trail in the field map (El::stirr; the preset sets how strong).
Installation
Components are distributed as source. Copy it and what it depends on into your project, then change it as you need:
cargo run --release --bin amenui -- add bottom_sheet --to ../my-appFiles copied: src/widgets/bottom_sheet.rs, src/gesture.rs, src/widgets/mod.rs
Usage
use amenui::widgets::{bottom_sheet};
fn view() -> El<Msg> {
let sheet = Sheet::resting(260.0, 0);
let body = col().gap(8.0).child(text("一行内容", 14.0, Paint::TEXT)).child(text("另一行", 14.0, Paint::TEXT));
layers([col().fill_width().fill_height(), bottom_sheet("bs1", &sheet, "分享到", body, Msg::Sheet)])
.width(260.0).height(260.0).radius(16.0).border(1.0, Paint::DIM).clip()
}Examples
At the top detent
fn view() -> El<Msg> {
let mut sheet = Sheet::default();
sheet.detents = vec![0.3, 0.8];
let sheet = sheet.rest_on(260.0, 1);
layers([col().fill_width().fill_height(), bottom_sheet("bs2", &sheet, "筛选", text("拖动把手或正文", 14.0, Paint::DIM), Msg::Sheet)])
.width(260.0).height(260.0).radius(16.0).border(1.0, Paint::DIM).clip()
}API
| Functions | bottom_sheet |
|---|---|
| Props | key, sheet (Sheet: detents, dismiss_velocity, projection_decel, backdrop, spring, rubber, height), title, body, msg. |
| Files | src/widgets/bottom_sheet.rs, src/gesture.rs |
| Depends on | base |
| Response to fronts | nudge (a control: pushed as one piece by fronts, held and condensing at most to Look::legible_cap) |
| Recomposition | keyed labels recompose when their text changes |
Keyboard and accessibility
| States | closed, presenting, resting on a detent, dragged (captured until release), springing to a detent or away; Esc dismisses; role dialog. |
|---|---|
| Keys and messages | msg(SheetMsg) for every drag step, Esc and a press on the backdrop; the application calls Sheet::update with it and Sheet::step on every tick while Sheet::moving(). |
On the web every control is mirrored into the page as an element with its role and name, so screen readers and the browser's own focus see it (DESIGN.md §1.14).