2. Send the haptic request through Fission
Keep work-order state in GlobalState because it may be read by other screens. The reducer marks the inspection complete synchronously, then requests an optional success haptic. The separate completion reducers update the message after the host responds.
{"id":"fission-tabs-1","tabs":[{"index":0,"label":"src/app.rs","value":"src-app-rs"},{"index":1,"label":"src/lib.rs","value":"src-lib-rs"},{"index":2,"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::*;
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
enum FeedbackState {
#[default]
Optional,
Sending,
Complete,
Unavailable,
}
#[derive(Debug, Default, PartialEq)]
pub struct InspectionState {
pub complete: bool,
feedback: FeedbackState,
haptic_error: Option<String>,
}
impl GlobalState for InspectionState {}
fn complete_inspection(state: &mut InspectionState, ctx: &mut ReducerContext<InspectionState>) {
if state.complete {
return;
}
state.complete = true;
state.feedback = FeedbackState::Sending;
state.haptic_error = None;
let ok = ctx.effects.bind(HapticCompleted, reduce_with!(on_haptic_completed));
let err = ctx.effects.bind(HapticUnavailable, reduce_with!(on_haptic_unavailable));
ctx.effects
.haptics()
.notification(HapticNotificationRequest {
kind: HapticNotificationKind::Success,
})
.on_ok(ok)
.on_err(err);
}
#[fission_reducer(HapticCompleted)]
fn on_haptic_completed(state: &mut InspectionState, ctx: &mut ReducerContext<InspectionState>) {
if ctx.input.capability_ok(HAPTIC_NOTIFICATION).is_some() {
state.feedback = FeedbackState::Complete;
} else {
state.feedback = FeedbackState::Unavailable;
}
}
#[fission_reducer(HapticUnavailable)]
fn on_haptic_unavailable(state: &mut InspectionState, ctx: &mut ReducerContext<InspectionState>) {
state.haptic_error = ctx
.input
.capability_error_message(HAPTIC_NOTIFICATION)
.map(str::to_owned);
state.feedback = FeedbackState::Unavailable;
}
fission_component! {
pub InspectionCompletion<InspectionState> {}
view(_inspection, state, cx) {
let tokens = &cx.view.env().theme.tokens;
let feedback = if let Some(error) = &state.haptic_error {
format!("{}: {error}", cx.tr("inspection.haptic_unavailable"))
} else {
match state.feedback {
FeedbackState::Optional => cx.tr("inspection.optional"),
FeedbackState::Sending => cx.tr("inspection.sending"),
FeedbackState::Complete => cx.tr("inspection.haptic_complete"),
FeedbackState::Unavailable => cx.tr("inspection.haptic_unavailable"),
}
};
let status = if state.complete {
cx.tr("inspection.done")
} else {
cx.tr("inspection.status_progress")
};
} =>
SemanticsRegion(
identifier: Some("inspection-completion".into()),
label: Some(cx.tr("inspection.screen_title")),
child: Container(Column(gap: tokens.spacing.m, children: [
Row(gap: tokens.spacing.m, align_items: ir_op::AlignItems::Center, children: [
Column(gap: tokens.spacing.xs, flex_grow: 1.0, children: [
Text(cx.tr("inspection.site")).weight(tokens.typography.font_weight_bold),
Text(cx.tr("inspection.work_order")).color(tokens.colors.text_secondary),
]),
Badge(text: status),
]),
Divider(),
Text(cx.tr("inspection.summary")),
Button(
child: Text(if state.complete { cx.tr("inspection.done") } else { cx.tr("inspection.action") }),
key: "complete-inspection",
disabled: state.complete,
on_press: reduce { complete_inspection(state, cx); },
),
if state.feedback == FeedbackState::Sending {
Spinner(motion: Some(SpinnerMotion::Default), label: cx.tr("inspection.sending"))
},
Text(feedback).color(tokens.colors.text_secondary),
]))
.padding_all(tokens.spacing.l)
.bg(tokens.colors.surface)
.border(tokens.colors.border, 1.0)
.border_radius(tokens.radii.large),
)
}
{"id":"fission-tabs-1","index":1,"label":"src/lib.rs","value":"src-lib-rs"}
pub mod app;
mod i18n;
use app::InspectionCompletion;
use fission::prelude::*;
#[cfg(not(any(target_arch = "wasm32", target_os = "android", target_os = "ios")))]
pub fn run_desktop() -> anyhow::Result<()> {
DesktopApp::<app::InspectionState, _>::new(InspectionCompletion)
.with_env(i18n::create_env())
.run()
}
#[cfg(any(target_os = "android", target_os = "ios"))]
fn mobile_app() -> MobileApp<app::InspectionState, InspectionCompletion> {
let app = MobileApp::<app::InspectionState, _>::new(InspectionCompletion)
.with_env(i18n::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::<app::InspectionState, _>::new(InspectionCompletion)
.with_env(i18n::create_env())
.run()
.map_err(|error| wasm_bindgen::JsValue::from_str(&error.to_string()))
}
{"id":"fission-tabs-1","index":2,"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::InspectionState, _>::new(app::InspectionCompletion::new())
.with_env(i18n::create_env())
.with_title("Northbank compressor inspection")
.mount("#fission-web-mount")
.run()
.map_err(|error| JsValue::from_str(&error.to_string()))
}
{"id":"fission-tabs-1"}
The preview leaves Fission's actual Web host in place. Pressing the action requests feedback from that host; an unsupported or unavailable result is handled by the same error reducer. It does not substitute an in-memory success for a device result.
The completed flag here lasts for the current app run. In a work-order app that promises saved completion, persist or submit that change and confirm it before requesting the success haptic. An optional vibration is not an acknowledgement from the server.
The complete Haptics guide explains configuration and platform behaviour. On a physical Android device, verify the actual vibration too. If the host reports haptics are unavailable, the inspection should still be marked complete and the screen should still explain what happened.
Keep platform-specific code behind Fission’s typed provider boundary; the shared component describes the work and handles outcomes without calling an Android API directly.
Press “Complete inspection”. Completion stays visible whether the host accepts the haptic request or reports it unavailable. A successful request means the host accepted it; it does not prove the user felt a vibration.
Show the app previewHide the app preview
Show the app preview
Hide the app preview