amenui
en·中 github ↗ v0.0.1
01docs 02components 03lab 04works
en·中github ↗
×

docs / components / feedback / bottom sheet docs / components / feedback /

bottom sheet

04.24
On this page ▾
  1. Installation
  2. Usage
  3. Examples
  4. API
  5. Keyboard and accessibility

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).

drawn by amenuiopen ↗

Installation

Components are distributed as source. Copy it and what it depends on into your project, then change it as you need:

sh
cargo run --release --bin amenui -- add bottom_sheet --to ../my-app

Files copied: src/widgets/bottom_sheet.rs, src/gesture.rs, src/widgets/mod.rs

Usage

rust
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

rust
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

Functionsbottom_sheet
Propskey, sheet (Sheet: detents, dismiss_velocity, projection_decel, backdrop, spring, rubber, height), title, body, msg.
Filessrc/widgets/bottom_sheet.rs, src/gesture.rs
Depends onbase
Response to frontsnudge (a control: pushed as one piece by fronts, held and condensing at most to Look::legible_cap)
Recompositionkeyed labels recompose when their text changes

Keyboard and accessibility

Statesclosed, presenting, resting on a detent, dragged (captured until release), springing to a detent or away; Esc dismisses; role dialog.
Keys and messagesmsg(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).

Recipes: Gestures: a bottom sheet and a floating box