The modal already has stable internal slots, enter/exit motion and a dismissal boundary. Rebuilding those with a positioned container and opacity timer would make the example longer whilst losing the widget's normal behavior.
The draft and open/closed flag are local UI state. A confirmed version is a snapshot in application state. Closing the dialog cancels review, not the draft; changing the draft later does not silently edit the already confirmed version.
{"id":"fission-tabs-1","tabs":[{"index":0,"label":"src/app.rs","value":"src-app-rs"},{"index":1,"label":"src/app/state.rs","value":"src-app-state-rs"},{"index":2,"label":"src/app/screen.rs","value":"src-app-screen-rs"},{"index":3,"label":"src/i18n.rs","value":"src-i18n-rs"},{"index":4,"label":"src/lib.rs","value":"src-lib-rs"},{"index":5,"label":"preview/lib.rs","value":"preview-lib-rs"},{"index":6,"label":"i18n/en-US.yaml","value":"i18n-en-us-yaml"},{"index":7,"label":"i18n/es-ES.yaml","value":"i18n-es-es-yaml"}]}
{"id":"fission-tabs-1","index":0,"label":"src/app.rs","value":"src-app-rs"}
mod screen;
pub mod state;
pub use screen::ReviewScreen;
pub use state::ReviewState;
{"id":"fission-tabs-1","index":1,"label":"src/app/state.rs","value":"src-app-state-rs"}
use fission::prelude::*;
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct ReviewState {
pub locale: Locale,
pub animate: bool,
pub approved_note: Option<String>,
}
impl Default for ReviewState {
fn default() -> Self {
Self {
locale: Locale::from("en-US"),
animate: false,
approved_note: None,
}
}
}
impl GlobalState for ReviewState {}
{"id":"fission-tabs-1","index":2,"label":"src/app/screen.rs","value":"src-app-screen-rs"}
use super::state::ReviewState;
use fission::prelude::*;
fission_component! {
pub ReviewScreen<ReviewState> {
state {
draft: String = String::new(),
review_open: bool = false,
}
}
view(screen, state, cx) {
let tokens = &cx.view.env().theme.tokens;
} => SafeArea(
child: Scroll(
child: Container(Column(gap: tokens.spacing.m, children: [
Text(cx.tr("review.heading")).size(tokens.typography.heading2_size),
Text(cx.tr("review.explanation")),
Row(gap: tokens.spacing.s, children: [
Button(
child: Text(cx.tr("language.english")), key: "english",
on_press: reduce { state.locale = Locale::from("en-US"); },
),
Button(
child: Text(cx.tr("language.spanish")), key: "spanish",
on_press: reduce { state.locale = Locale::from("es-ES"); },
),
]),
Button(
child: Text(if state.animate { cx.tr("review.motion_off") } else { cx.tr("review.motion_on") }),
key: "toggle-animation",
on_press: reduce { state.animate = !state.animate; },
),
TextInput(
value: screen.draft.clone(), bind(on_input): to(screen.draft),
label: Some(TextContent::Key("review.note".into())),
multiline: true, keyboard_type: TextInputType::Multiline,
),
Button(
child: Text(cx.tr("review.open")), key: "open-review",
disabled: screen.draft.trim().is_empty(),
on_press: reduce { screen.review_open = true; },
),
if let Some(note) = &state.approved_note {
Column(gap: tokens.spacing.s, children: [
Text(cx.tr("review.approved")).weight(tokens.typography.font_weight_semibold),
Text(note.clone()),
Text(cx.tr("review.session")).color(tokens.colors.text_secondary),
])
},
Modal(
title: cx.tr("review.dialog_title"),
is_open: screen.review_open,
motion: Some(if state.animate { ModalMotion::Default } else { ModalMotion::None }),
on_dismiss: reduce { screen.review_open = false; },
content: Column(gap: tokens.spacing.m, children: [
Text(screen.draft.clone()),
Text(cx.tr("review.dialog_help")),
Row(gap: tokens.spacing.s, wrap: ir_op::FlexWrap::Wrap, children: [
Button(
child: Text(cx.tr("review.keep_editing")), key: "keep-editing",
on_press: reduce { screen.review_open = false; },
),
Button(
child: Text(cx.tr("review.confirm")), key: "confirm-note",
on_press: reduce {
state.approved_note = Some(screen.draft.trim().to_owned());
screen.review_open = false;
},
),
]),
]),
),
]))
.padding_all(tokens.spacing.l),
),
)
}
{"id":"fission-tabs-1","index":3,"label":"src/i18n.rs","value":"src-i18n-rs"}
use fission::i18n::{Locale, TranslationBundle};
use fission::prelude::*;
use std::collections::HashMap;
pub fn create_env() -> Env {
let mut env = Env::default();
env.locale = Locale::from("en-US");
for (locale, source) in [
("en-US", include_str!("../i18n/en-US.yaml")),
("es-ES", include_str!("../i18n/es-ES.yaml")),
] {
let messages: HashMap<String, String> =
serde_yaml::from_str(source).expect("valid review translations");
env.i18n.add_bundle(TranslationBundle {
locale: Locale::from(locale),
messages,
});
}
env
}
pub fn sync_env(state: &crate::app::ReviewState, env: &mut Env) {
env.locale = state.locale.clone();
env.widget_motion = if state.animate {
WidgetMotion::Standard
} else {
WidgetMotion::Off
};
// Do not overwrite a host-supplied Reduced motion preference.
}
{"id":"fission-tabs-1","index":4,"label":"src/lib.rs","value":"src-lib-rs"}
pub mod app;
mod i18n;
use app::{ReviewScreen, ReviewState};
use fission::prelude::*;
#[cfg(not(any(target_arch = "wasm32", target_os = "android", target_os = "ios")))]
pub fn run_desktop() -> anyhow::Result<()> {
DesktopApp::<ReviewState, _>::new(ReviewScreen)
.with_env(i18n::create_env())
.with_sync_env(i18n::sync_env)
.run()
}
#[cfg(any(target_os = "android", target_os = "ios"))]
pub fn run_mobile() -> anyhow::Result<()> {
MobileApp::<ReviewState, _>::new(ReviewScreen)
.with_env(i18n::create_env())
.with_sync_env(i18n::sync_env)
.run()
}
#[cfg(target_os = "android")]
#[no_mangle]
fn android_main(app_handle: AndroidApp) {
let _ = MobileApp::<ReviewState, _>::new(ReviewScreen)
.with_env(i18n::create_env())
.with_sync_env(i18n::sync_env)
.run_with_android_app(app_handle);
}
#[cfg(target_arch = "wasm32")]
#[wasm_bindgen::prelude::wasm_bindgen(start)]
pub fn run_web() -> Result<(), wasm_bindgen::JsValue> {
console_error_panic_hook::set_once();
WebApp::<ReviewState, _>::new(ReviewScreen)
.with_env(i18n::create_env())
.with_sync_env(i18n::sync_env)
.run()
.map_err(|error| wasm_bindgen::JsValue::from_str(&error.to_string()))
}
{"id":"fission-tabs-1","index":5,"label":"preview/lib.rs","value":"preview-lib-rs"}
mod app;
mod i18n;
use fission::prelude::*;
use wasm_bindgen::prelude::*;
#[wasm_bindgen(start)]
pub fn run() -> Result<(), JsValue> {
console_error_panic_hook::set_once();
WebApp::<app::ReviewState, _>::new(app::ReviewScreen)
.with_env(i18n::create_env())
.with_sync_env(i18n::sync_env)
.mount("#fission-web-mount")
.run()
.map_err(|error| JsValue::from_str(&error.to_string()))
}
{"id":"fission-tabs-1","index":6,"label":"i18n/en-US.yaml","value":"i18n-en-us-yaml"}
review.heading: "Review a handover note"
review.explanation: "Write a note, review it in a dialog and confirm the version you want to keep for this session. Animation is optional."
review.motion_off: "Turn interface animation off"
review.motion_on: "Enable interface animation"
review.note: "Handover note"
review.open: "Review this note"
review.dialog_title: "Review before confirming"
review.dialog_help: "Confirming keeps a snapshot in memory. It does not send the note to another person."
review.keep_editing: "Keep editing"
review.confirm: "Confirm this version"
review.approved: "Confirmed version"
review.session: "Kept for this session only; nothing has been sent or saved to disk."
language.english: "English"
language.spanish: "Español"
{"id":"fission-tabs-1","index":7,"label":"i18n/es-ES.yaml","value":"i18n-es-es-yaml"}
review.heading: "Revisar una nota de relevo"
review.explanation: "Escribe una nota, revísala en un diálogo y confirma la versión que quieres conservar para esta sesión. La animación es opcional."
review.motion_off: "Desactivar la animación de la interfaz"
review.motion_on: "Activar la animación de la interfaz"
review.note: "Nota de relevo"
review.open: "Revisar esta nota"
review.dialog_title: "Revisar antes de confirmar"
review.dialog_help: "Confirmar conserva una copia en memoria. No envía la nota a otra persona."
review.keep_editing: "Seguir editando"
review.confirm: "Confirmar esta versión"
review.approved: "Versión confirmada"
review.session: "Conservada solo para esta sesión; no se ha enviado ni guardado nada en disco."
language.english: "Inglés"
language.spanish: "Español"
{"id":"fission-tabs-1"}