Get started
Introduction
Installation
Your first app
Tutorials
Fission tutorials
Give repeated Android list rows stable identity
Core concepts
Components
State and effects
Protected routes
Server-side rendering
Styling
Testing
Deployment
Reference
API reference
Cookbook
Fission 0.16.0
Documentation version
Read the changelog →

Give repeated Android list rows stable identity

Build a searchable packing list where actions follow the intended record after reordering, while transient row state remains distinct from saved packing truth.
Android

What you will build

Create and filter packing records without moving a checked status or row action onto another item when the list order changes.
Allocate a record ID once rather than use its current list position
Key repeated components and explicit widget identities from that record ID
Keep packed status in shared state and a transient reminder in local row state
Distinguish reordering from removing a row and pruning its local state

Keep identity with the item, not its position

A row's position tells us where it is displayed. It does not tell us which record it represents. That difference becomes important as soon as a list can be searched or reordered: the first visible item is no longer necessarily the first item that was created.
Here, we build a packing list from items the user enters. Each record receives an ID once. The record owns its packed state in GlobalState, whilst the row owns only a temporary expanded reminder. This separates two concerns which are easy to confuse: stable identity prevents state moving to another mounted row; it does not make unmounted local state permanent.
Start from a new project (optional)

Create the Android project

Complete Android SDK/NDK setup, then start an emulator or connect a phone.
fission init android-give-repeated-android-list-rows-stable-identity
cd android-give-repeated-android-list-rows-stable-identity
fission add-target android --project-dir .
cargo add serde_yaml
Keep the generated src/main.rs. The shared state, reusable row and screen have separate modules. Both native and Web shells run that same screen rather than a different preview app.

Run the finished example

fission run --target android --project-dir .

1. Build a list with real records

The allocator below is enough for records created during one app run. An app that loads shared or persisted records should use those records' durable IDs instead. Never generate a new row ID during every build or derive it from translated text.
The row receives explicit props and the parent supplies key: item.id. That key establishes the Compose component's retained scope. The explicit WidgetId also names the rendered row; setting an ID after constructing an unkeyed component is not a replacement for the Compose key.
{"id":"fission-tabs-1","tabs":[{"index":0,"label":"src/state.rs","value":"src-state-rs"},{"index":1,"label":"src/row.rs","value":"src-row-rs"},{"index":2,"label":"src/app.rs","value":"src-app-rs"},{"index":3,"label":"src/translations.rs","value":"src-translations-rs"},{"index":4,"label":"i18n/en-US.yaml","value":"i18n-en-us-yaml"},{"index":5,"label":"i18n/es-ES.yaml","value":"i18n-es-es-yaml"},{"index":6,"label":"src/lib.rs","value":"src-lib-rs"},{"index":7,"label":"preview/lib.rs","value":"preview-lib-rs"}]}
{"id":"fission-tabs-1","index":0,"label":"src/state.rs","value":"src-state-rs"}
use fission::prelude::*;

#[derive(Debug, Clone, PartialEq, Eq)]
pub struct PackingItem {
    pub id: u64,
    pub description: String,
    pub packed: bool,
}

#[derive(Debug)]
pub struct PackingState {
    pub items: Vec<PackingItem>,
    next_id: u64,
}

impl Default for PackingState {
    fn default() -> Self { Self { items: Vec::new(), next_id: 1 } }
}
impl GlobalState for PackingState {}

impl PackingState {
    pub fn add(&mut self, description: &str) -> bool {
        let description = description.trim();
        if description.is_empty() { return false; }
        let Some(next) = self.next_id.checked_add(1) else { return false; };
        self.items.push(PackingItem {
            id: self.next_id,
            description: description.to_owned(),
            packed: false,
        });
        self.next_id = next;
        true
    }

    pub fn toggle_packed(&mut self, id: u64) {
        if let Some(item) = self.items.iter_mut().find(|item| item.id == id) {
            item.packed = !item.packed;
        }
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn identity_is_allocated_once_and_actions_target_the_id() {
        let mut state = PackingState::default();
        assert!(!state.add(" "));
        assert!(state.add("USB charger"));
        assert!(state.add("Rain jacket"));
        let first_id = state.items[0].id;
        let second_id = state.items[1].id;
        state.items.reverse();
        state.toggle_packed(first_id);
        assert!(state.items.iter().find(|item| item.id == first_id).unwrap().packed);
        assert!(!state.items.iter().find(|item| item.id == second_id).unwrap().packed);
        state.toggle_packed(999); // An old event cannot recreate a removed record.
        assert_eq!(state.items.len(), 2);
    }
}
{"id":"fission-tabs-1","index":1,"label":"src/row.rs","value":"src-row-rs"}
use fission::prelude::*;
use crate::state::PackingState;

fission_component! {
    pub PackingRow<PackingState> {
        props {
            item_id: u64,
            description: String,
            packed: bool,
        }
        state { expanded: bool = false }
    }
    view(row, state, cx) {
        let tokens = &cx.view.env().theme.tokens;
    } =>
    Card(
        child: Column(gap: tokens.spacing.s, children: [
            Text(row.description.clone()).weight(tokens.typography.font_weight_bold),
            Text(cx.tr(if row.packed { "packing.packed" } else { "packing.unpacked" })),
            Wrap(spacing: tokens.spacing.s, children: [
                Button(
                    child: Text(cx.tr(if row.packed { "packing.unpack" } else { "packing.pack" })),
                    key: "toggle-packed",
                    on_press: reduce { state.toggle_packed(row.item_id); },
                ).semantics_identifier(format!("packing.{}.toggle", row.item_id)),
                Button(
                    child: Text(cx.tr(if row.expanded { "packing.close" } else { "packing.details" })),
                    key: "toggle-details",
                    on_press: reduce { row.expanded = !row.expanded; },
                ).semantics_identifier(format!("packing.{}.details", row.item_id)),
            ]),
            if row.expanded {
                Text(cx.tr("packing.details_help"))
            },
        ]),
    )
}
{"id":"fission-tabs-1","index":2,"label":"src/app.rs","value":"src-app-rs"}
use fission::prelude::*;
use crate::row::PackingRow;
use crate::state::PackingState;

fission_component! {
    pub PackingApp<PackingState> {
        state {
            draft: String = String::new(),
            invalid: bool = false,
        }
    }
    view(app, state, cx) {
        let tokens = &cx.view.env().theme.tokens;
    } =>
    SafeArea(
        child: Scroll(
            child: Container(
                child: Column(gap: tokens.spacing.m, children: [
                    Text(cx.tr("packing.title")).size(tokens.typography.heading2_size),
                    Text(cx.tr("packing.scope")),
                    TextInput(
                        label: Some(cx.tr("packing.new_item").into()),
                        bind: app.draft,
                        semantics_identifier: "packing.draft".to_string(),
                    ),
                    Button(
                        child: Text(cx.tr("packing.add")),
                        key: "add-item",
                        on_press: reduce {
                            if state.add(&app.draft) {
                                app.draft.clear();
                                app.invalid = false;
                            } else {
                                app.invalid = true;
                            }
                        },
                    ).semantics_identifier("packing.add"),
                    if app.invalid { Text(cx.tr("packing.invalid")) },
                    if state.items.is_empty() { Text(cx.tr("packing.empty")) },
                    for item in &state.items {
                        PackingRow(
                            item.id,
                            item.description.clone(),
                            item.packed,
                            key: item.id,
                        ).id(WidgetId::explicit(&format!("packing-row.{}", item.id)))
                    },
                ]),
            ).padding_all(tokens.spacing.l),
        ),
    )
}
{"id":"fission-tabs-1","index":3,"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":4,"label":"i18n/en-US.yaml","value":"i18n-en-us-yaml"}
packing.title: "Pack for a trip"
packing.scope: "Add your own items. This list lasts for the current app run; it is not saved yet."
packing.new_item: "Item to pack"
packing.add: "Add item"
packing.invalid: "Enter an item description."
packing.empty: "Your packing list is empty. Add the first item."
packing.no_matches: "No items match the current search. Clear it to see the full list."
packing.packed: "Packed"
packing.unpacked: "Not packed"
packing.pack: "Mark packed"
packing.unpack: "Mark not packed"
packing.details: "Packing reminder"
packing.close: "Hide reminder"
packing.details_help: "Check that this item is in the bag, not just ready to pack."
packing.search: "Find an item"
packing.reverse: "Reverse list order"
{"id":"fission-tabs-1","index":5,"label":"i18n/es-ES.yaml","value":"i18n-es-es-yaml"}
packing.title: "Preparar el equipaje"
packing.scope: "Añade tus propios artículos. Esta lista dura mientras la aplicación está abierta; todavía no se guarda."
packing.new_item: "Artículo para llevar"
packing.add: "Añadir artículo"
packing.invalid: "Escribe una descripción del artículo."
packing.empty: "La lista está vacía. Añade el primer artículo."
packing.no_matches: "Ningún artículo coincide con la búsqueda. Bórrala para ver la lista completa."
packing.packed: "Guardado en la maleta"
packing.unpacked: "Sin guardar"
packing.pack: "Marcar como guardado"
packing.unpack: "Marcar como no guardado"
packing.details: "Recordatorio"
packing.close: "Ocultar recordatorio"
packing.details_help: "Comprueba que el artículo esté dentro de la maleta, no solo preparado."
packing.search: "Buscar un artículo"
packing.reverse: "Invertir el orden"
{"id":"fission-tabs-1","index":6,"label":"src/lib.rs","value":"src-lib-rs"}
pub mod app;
mod row;
mod state;
mod translations;

use app::PackingApp;
use state::PackingState;
use fission::prelude::*;

#[cfg(not(any(target_arch = "wasm32", target_os = "android", target_os = "ios")))]
pub fn run_desktop() -> anyhow::Result<()> {
    DesktopApp::<PackingState, _>::new(PackingApp::new())
        .with_env(translations::create_env())
        .run()
}
#[cfg(any(target_os = "android", target_os = "ios"))]
fn mobile_app() -> MobileApp<PackingState, PackingApp> {
    let app = MobileApp::<PackingState, _>::new(PackingApp::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::<PackingState, _>::new(PackingApp::new())
        .with_env(translations::create_env())
        .run()
        .map_err(|error| wasm_bindgen::JsValue::from_str(&error.to_string()))
}
{"id":"fission-tabs-1","index":7,"label":"preview/lib.rs","value":"preview-lib-rs"}
mod app;
mod row;
mod state;
mod translations;

use fission::prelude::*;
use wasm_bindgen::prelude::*;

#[wasm_bindgen(start)]
pub fn run() -> Result<(), JsValue> {
    console_error_panic_hook::set_once();
    WebApp::<state::PackingState, _>::new(app::PackingApp::new())
        .with_env(translations::create_env())
        .mount("#fission-web-mount")
        .run()
        .map_err(|error| JsValue::from_str(&error.to_string()))
}
{"id":"fission-tabs-1"}
Add two different items, mark only one packed and open its reminder. The packed status is record data; the open reminder is row-local presentation state. Neither should change the other record.
Show the app preview
Hide the app preview

2. Filter and reorder without changing record identity

Search changes the visible collection, not the records. Reversing that collection changes presentation order without allocating new IDs. A button still targets the record ID captured by its row, rather than whichever item now occupies an old position.
Replace only the screen. State, row and shell modules stay as they were.
{"id":"fission-tabs-1","tabs":[{"index":0,"label":"src/app.rs","value":"src-app-rs"}]}
{"id":"fission-tabs-1","index":0,"label":"src/app.rs","value":"src-app-rs"}
use fission::prelude::*;
use crate::row::PackingRow;
use crate::state::PackingState;

fission_component! {
    pub PackingApp<PackingState> {
        state {
            draft: String = String::new(),
            invalid: bool = false,
            query: String = String::new(),
            reverse: bool = false,
        }
    }
    view(app, state, cx) {
        let tokens = &cx.view.env().theme.tokens;
        let query = app.query.trim().to_lowercase();
        let mut visible: Vec<_> = state.items.iter()
            .filter(|item| item.description.to_lowercase().contains(&query))
            .collect();
        if app.reverse { visible.reverse(); }
    } =>
    SafeArea(
        child: Scroll(
            child: Container(
                child: Column(gap: tokens.spacing.m, children: [
                    Text(cx.tr("packing.title")).size(tokens.typography.heading2_size),
                    Text(cx.tr("packing.scope")),
                    TextInput(
                        label: Some(cx.tr("packing.new_item").into()),
                        bind: app.draft,
                        semantics_identifier: "packing.draft".to_string(),
                    ),
                    Button(
                        child: Text(cx.tr("packing.add")),
                        key: "add-item",
                        on_press: reduce {
                            if state.add(&app.draft) {
                                app.draft.clear();
                                app.invalid = false;
                            } else {
                                app.invalid = true;
                            }
                        },
                    ).semantics_identifier("packing.add"),
                    if app.invalid { Text(cx.tr("packing.invalid")) },
                    TextInput(
                        label: Some(cx.tr("packing.search").into()),
                        bind: app.query,
                        semantics_identifier: "packing.search".to_string(),
                    ),
                    Button(
                        child: Text(cx.tr("packing.reverse")),
                        key: "reverse-items",
                        on_press: reduce { app.reverse = !app.reverse; },
                    ).semantics_identifier("packing.reverse"),
                    if visible.is_empty() { Text(cx.tr("packing.no_matches")) },
                    for item in visible {
                        PackingRow(
                            item.id,
                            item.description.clone(),
                            item.packed,
                            key: item.id,
                        ).id(WidgetId::explicit(&format!("packing-row.{}", item.id)))
                    },
                ]),
            ).padding_all(tokens.spacing.l),
        ),
    )
}
{"id":"fission-tabs-1"}
Add at least three items. Open a reminder and reverse the list: the open reminder should stay with the same mounted row. Mark that item packed, filter it out, then clear the search. The packed status must remain because the record still exists in shared state.
The reminder may close after filtering the row out. Fission discards local component state when that component is no longer active. If a draft or selection must survive removal from the tree, keep it in shared state keyed by the record ID, not only in the row's local state.
Show the app preview
Hide the app preview

3. Check the transitions on Android

cargo test
fission doctor android --project-dir .
fission run --target android --project-dir .
fission test --target android --project-dir .
fission build --target android --project-dir . --release
Repeat insertion, search and reverse on an emulator and a phone. Use the semantic identifiers packing.search, packing.reverse and packing.<id>.toggle when driving the app with LiveTest. Include duplicate descriptions: two items with the same name still have different IDs and must not share state.
These commands check source, host startup and packaging separately. They do not establish the interaction result; run the sequence above and inspect which record changed.
The list now has one authority for each fact: the record owns packed status; the parent owns the search and order controls; each mounted row owns its reminder. A stable key connects those boundaries without treating a list position as identity.
The list is in memory only. Persistent or multi-device IDs and storage are separate requirements, not something a widget ID supplies.

Current references