2. Add a theme override without replacing system scaling
None means use the host's appearance; Some(Light) or Some(Dark) is the user's app-specific override. That makes precedence explicit. Switching the device theme must not defeat a deliberate override, and choosing the device appearance again must remove that override.
The picker changes state through reducers. The existing shell callback selects one complete generated theme, including component recipes, instead of replacing just the page background.
{"id":"fission-tabs-1","tabs":[{"index":0,"label":"src/appearance_picker.rs","value":"src-appearance-picker-rs"},{"index":1,"label":"src/app.rs","value":"src-app-rs"},{"index":2,"label":"src/lib.rs","value":"src-lib-rs"},{"index":3,"label":"preview/lib.rs","value":"preview-lib-rs"}]}
{"id":"fission-tabs-1","index":0,"label":"src/appearance_picker.rs","value":"src-appearance-picker-rs"}
use fission::prelude::*;
use crate::presentation::ReadingState;
fission_component! {
pub AppearancePicker<ReadingState> {}
view(_picker, state, cx) {
let tokens = &cx.view.env().theme.tokens;
} =>
Column(gap: tokens.spacing.s, children: [
Text(cx.tr("appearance.title")).weight(tokens.typography.font_weight_semibold),
Wrap(spacing: tokens.spacing.s, children: [
Button(
child: Text(cx.tr("appearance.system")),
key: "appearance-system",
disabled: state.theme_override.is_none(),
on_press: reduce { state.theme_override = None; },
).semantics_identifier("appearance.system"),
Button(
child: Text(cx.tr("appearance.light")),
key: "appearance-light",
disabled: state.theme_override == Some(DesignMode::Light),
on_press: reduce { state.theme_override = Some(DesignMode::Light); },
).semantics_identifier("appearance.light"),
Button(
child: Text(cx.tr("appearance.dark")),
key: "appearance-dark",
disabled: state.theme_override == Some(DesignMode::Dark),
on_press: reduce { state.theme_override = Some(DesignMode::Dark); },
).semantics_identifier("appearance.dark"),
]),
])
}
{"id":"fission-tabs-1","index":1,"label":"src/app.rs","value":"src-app-rs"}
use fission::prelude::*;
use crate::presentation::ReadingState;
use crate::appearance_picker::AppearancePicker;
fission_component! {
pub HandoverNotes<ReadingState> {
state { note: String = String::new() }
}
view(notes, _state, cx) {
let tokens = &cx.view.env().theme.tokens;
} =>
SafeArea(
child: Scroll(
child: Container(
child: Column(gap: tokens.spacing.l, children: [
Text(cx.tr("reading.title")).size(tokens.typography.heading2_size),
Text(cx.tr("reading.context")),
AppearancePicker(),
TextInput(
label: Some(cx.tr("reading.note").into()),
helper_text: Some(cx.tr("reading.note_help").into()),
multiline: true,
bind: notes.note,
semantics_identifier: "reading.note".to_string(),
),
if notes.note.trim().is_empty() {
EmptyState(
title: cx.tr("reading.empty"),
description: cx.tr("reading.empty_help"),
)
} else {
Card(child: Column(gap: tokens.spacing.s, children: [
Text(cx.tr("reading.preview")).weight(tokens.typography.font_weight_semibold),
Text(notes.note.clone()),
]))
},
]),
).padding_all(tokens.spacing.l).bg(tokens.colors.background),
),
)
}
{"id":"fission-tabs-1","index":2,"label":"src/lib.rs","value":"src-lib-rs"}
pub mod app;
mod presentation;
mod appearance_picker;
mod translations;
use app::HandoverNotes;
use presentation::ReadingState;
use fission::prelude::*;
#[cfg(not(any(target_arch = "wasm32", target_os = "android", target_os = "ios")))]
pub fn run_desktop() -> anyhow::Result<()> {
DesktopApp::<ReadingState, _>::new(HandoverNotes::new())
.with_env(translations::create_env())
.with_design_system::<FissionDefaultDesignSystem>(DesignMode::Light)
.with_sync_env(presentation::sync_env)
.run()
}
#[cfg(any(target_os = "android", target_os = "ios"))]
fn mobile_app() -> MobileApp<ReadingState, HandoverNotes> {
let app = MobileApp::<ReadingState, _>::new(HandoverNotes::new())
.with_env(translations::create_env())
.with_design_system::<FissionDefaultDesignSystem>(DesignMode::Light)
.with_sync_env(presentation::sync_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::<ReadingState, _>::new(HandoverNotes::new())
.with_env(translations::create_env())
.with_design_system::<FissionDefaultDesignSystem>(DesignMode::Light)
.with_sync_env(presentation::sync_env)
.run()
.map_err(|error| wasm_bindgen::JsValue::from_str(&error.to_string()))
}
{"id":"fission-tabs-1","index":3,"label":"preview/lib.rs","value":"preview-lib-rs"}
mod app;
mod presentation;
mod appearance_picker;
mod translations;
use fission::prelude::*;
use wasm_bindgen::prelude::*;
#[wasm_bindgen(start)]
pub fn run() -> Result<(), JsValue> {
console_error_panic_hook::set_once();
WebApp::<presentation::ReadingState, _>::new(app::HandoverNotes::new())
.with_env(translations::create_env())
.with_design_system::<FissionDefaultDesignSystem>(DesignMode::Light)
.with_sync_env(presentation::sync_env)
.mount("#fission-web-mount")
.run()
.map_err(|error| JsValue::from_str(&error.to_string()))
}
{"id":"fission-tabs-1"}
Choose Dark, then Light, then the device appearance. Your note should remain intact and input, button and card styling should agree with the selected theme. Change Android's appearance whilst using the device mode and repeat whilst an explicit override is selected.
Changing theme does not change the text-scale preference. The unit test checks that the environment synchroniser preserves the host's scaler.
Show the app previewHide the app preview
Show the app preview
Hide the app preview