Components / overlay
ActionSheet view
A sheet of caller-owned actions. Choosing a row does not close the sheet or assume success; the caller supplies pending/loading/error and closes it.
A view survives a frame. Hold it in an Entity with cx.new(..) and reach it with .update(..).
use gpui_kit::overlay::ActionSheet;
Reviewed in action-sheet.
Construct
new(ident: impl Into<Ident>, window: &mut Window, cx: &mut Context<Self>) -> Self
Commands
Need a Context, so they need a view.
set_actions(actions: Vec<SheetAction>, cx: &mut Context<Self>)
set_state(state: SheetActionState, cx: &mut Context<Self>)
open(window: &mut Window, cx: &mut Context<Self>)
close(window: &mut Window, cx: &mut Context<Self>)
Queries
Only answer; they change nothing.
sheet() -> Entity<BottomSheet>
Reports
The variants of the event it emits. It never applies the change itself.
- ActionRequested
- Sheet
Example · action-sheet
fn action_sheet(window: &mut Window, cx: &mut App) -> AnyElement {
use crate::overlay::sheet::{ActionSheet, SheetAction, SheetActionState};
if !cx.has_global::<SceneActionSheet>() {
let sheet = cx.new(|cx| ActionSheet::new("scene.action-sheet", window, cx));
sheet.update(cx, |sheet, cx| {
let mut remove = SheetAction::new("remove", "Remove from collection");
remove.destructive = true;
let mut share = SheetAction::new("share", "Share unavailable");
share.disabled = true;
sheet.set_actions(
vec![SheetAction::new("save", "Save a copy"), share, remove],
cx,
);
sheet.set_state(
SheetActionState::Error(
"Fixture refusal: the last attempt failed; nothing was removed.".into(),
),
cx,
);
sheet.sheet().update(cx, |sheet, cx| {
sheet.set_title("Collection actions · fixture", cx);
});
sheet.open(window, cx);
sheet.sheet().update(cx, |sheet, cx| sheet.settle(cx));
});
cx.set_global(SceneActionSheet(sheet));
}
let theme = cx.theme().clone();
stack(&theme)
.w_full()
.h(px(600.0))
.child(page_behind(&theme, "Last verified collection"))
.child(cx.global::<SceneActionSheet>().0.clone())
.into_any_element()
}