This is the small standalone example used by the embedded preview. In your app, use the screen you already have and retain its public module boundaries. Do not replace an application's GlobalState with () merely because this isolated screen only needs retained local state.
The site name and acknowledgements belong to one preparation form, so the component retains them locally. They are not saved work-order data and do not survive a restart. A production start-visit command would submit or persist the prepared record through an effect before claiming it was saved.
{"id":"fission-tabs-1","tabs":[{"index":0,"label":"src/app.rs","value":"src-app-rs"},{"index":1,"label":"src/translations.rs","value":"src-translations-rs"},{"index":2,"label":"i18n/en-US.yaml","value":"i18n-en-us-yaml"},{"index":3,"label":"i18n/es-ES.yaml","value":"i18n-es-es-yaml"},{"index":4,"label":"src/lib.rs","value":"src-lib-rs"},{"index":5,"label":"preview/lib.rs","value":"preview-lib-rs"}]}
{"id":"fission-tabs-1","index":0,"label":"src/app.rs","value":"src-app-rs"}
use fission::prelude::*;
fission_component! {
pub VisitReadiness<()> {
state {
site: String = String::new(),
access_confirmed: bool = false,
safety_checked: bool = false,
started: bool = false,
}
}
view(visit, _state, cx) {
let tokens = &cx.view.env().theme.tokens;
let can_start = !visit.site.trim().is_empty()
&& visit.access_confirmed && visit.safety_checked;
} =>
Container(SafeArea(child: Scroll(child:
Container(Column(gap: tokens.spacing.m, children: [
Text(cx.tr("visit.title")).size(tokens.typography.heading1_size),
Text(cx.tr("visit.context")).color(tokens.colors.text_secondary),
TextInput(
label: Some(cx.tr("visit.site").into()),
bind: visit.site,
required: true,
read_only: visit.started,
semantics_identifier: "visit.site".to_string(),
),
Checkbox(
label: Some(cx.tr("visit.access")),
checked: visit.access_confirmed,
disabled: visit.started,
bind(on_toggle): to(visit.access_confirmed),
),
Checkbox(
label: Some(cx.tr("visit.safety")),
checked: visit.safety_checked,
disabled: visit.started,
bind(on_toggle): to(visit.safety_checked),
),
Button(
child: Text(cx.tr(if visit.started { "visit.edit" } else { "visit.start" })),
key: "start-visit",
disabled: !can_start,
on_press: reduce { visit.started = !visit.started; },
).semantics_identifier("visit.start"),
Text(cx.tr(if visit.started { "visit.started" } else { "visit.pending" })
.replace("{site}", &visit.site)),
]))
.padding_all(tokens.spacing.l)
.width_length(Length::percent(100.0))
.max_width(720.0),
)))
.height_length(Length::vh(100.0))
}
{"id":"fission-tabs-1","index":1,"label":"src/translations.rs","value":"src-translations-rs"}
use std::collections::HashMap;
use fission::prelude::*;
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 checked-in translations");
env.i18n.add_bundle(TranslationBundle {
locale: Locale::from(locale),
messages,
});
}
env
}
{"id":"fission-tabs-1","index":2,"label":"i18n/en-US.yaml","value":"i18n-en-us-yaml"}
visit.title: "Prepare a service visit"
visit.context: "Confirm access and safety before starting work."
visit.site: "Site name"
visit.access: "Access to the site is confirmed"
visit.safety: "The safety check is complete"
visit.start: "Start visit"
visit.edit: "Edit visit preparation"
visit.started: "Visit started at {site}."
visit.pending: "Enter the site and complete both checks to continue."
{"id":"fission-tabs-1","index":3,"label":"i18n/es-ES.yaml","value":"i18n-es-es-yaml"}
visit.title: "Preparar una visita de servicio"
visit.context: "Confirma el acceso y la seguridad antes de empezar."
visit.site: "Nombre del lugar"
visit.access: "Se ha confirmado el acceso al lugar"
visit.safety: "La comprobación de seguridad está completa"
visit.start: "Iniciar visita"
visit.edit: "Editar la preparación de la visita"
visit.started: "Visita iniciada en {site}."
visit.pending: "Introduce el lugar y completa ambas comprobaciones para continuar."
{"id":"fission-tabs-1","index":4,"label":"src/lib.rs","value":"src-lib-rs"}
pub mod app;
mod translations;
use app::VisitReadiness;
use fission::prelude::*;
#[cfg(not(any(target_arch = "wasm32", target_os = "android", target_os = "ios")))]
pub fn run_desktop() -> anyhow::Result<()> {
DesktopApp::<(), _>::new(VisitReadiness::new())
.with_env(translations::create_env())
.run()
}
#[cfg(any(target_os = "android", target_os = "ios"))]
fn mobile_app() -> MobileApp<(), VisitReadiness> {
let app = MobileApp::<(), _>::new(VisitReadiness::new())
.with_env(translations::create_env());
#[cfg(all(target_os = "android", debug_assertions))]
let app = app.with_test_control_port(48761);
app
}
#[cfg(any(target_os = "android", target_os = "ios"))]
pub fn run_mobile() -> anyhow::Result<()> {
mobile_app().run()
}
#[cfg(target_os = "android")]
#[no_mangle]
fn android_main(app_handle: AndroidApp) {
let _ = mobile_app().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::<(), _>::new(VisitReadiness::new())
.with_env(translations::create_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 translations;
use fission::prelude::*;
use wasm_bindgen::prelude::*;
#[wasm_bindgen(start)]
pub fn run() -> Result<(), JsValue> {
console_error_panic_hook::set_once();
WebApp::<(), _>::new(app::VisitReadiness::new())
.with_env(translations::create_env())
.mount("#fission-web-mount")
.run()
.map_err(|error| JsValue::from_str(&error.to_string()))
}
{"id":"fission-tabs-1"}
The example uses YAML bundles, so a standalone project needs cargo add serde_yaml. An existing app should keep its own checked-in translation format and environment setup instead of installing a second i18n system for Android.