Get started
Introduction
Installation
Your first app
Tutorials
Fission tutorials
Make an Android layout adapt to phones, tablets and changing window sizes
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 →

Make an Android layout adapt to phones, tablets and changing window sizes

Build a recipe editor that stacks on a phone and sits beside its reading view on wider screens, without duplicating the draft or cloning retained trees.
Android

What you will build

Keep one user-authored recipe draft visible and editable across independently constructed compact and wide layouts.
Keep recipe content in one shared state model
Choose compact or wide composition with the active design-system breakpoint
Construct an independent component tree for each responsive branch
Check resize, keyboard and larger-text behaviour without losing the draft
A tablet is not simply a larger phone, and a phone does not always have its full display available. Rotation, split-screen and a keyboard change the space the app can use. Choose a layout from that available space rather than from a list of device names.
Here, we build a recipe editor with a reading view. On a narrow screen, the editor comes first and the card follows below. With more room they sit side by side. Both arrangements edit the same draft, so changing the layout cannot create a second recipe or discard what the user typed.
Start from a new project (optional)

Create the Android project

Complete Android SDK/NDK setup, then prepare an emulator or connect a phone.
cargo install cargo-fission
fission init android-make-an-android-layout-adapt-to-phones-tablets-and-changing-window-sizes
cd android-make-an-android-layout-adapt-to-phones-tablets-and-changing-window-sizes
fission add-target android --project-dir .
cargo add serde_yaml
Keep the generated src/main.rs. Shared draft state, the editor, reading card and layout components have separate modules. Native and Web shells below launch the same app from the first step.

Run the finished example

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

1. Make the narrow layout useful first

The app starts with an empty recipe, not a demonstration work order. Inputs bind to the shared draft and the reading card observes those values. The screen is scrollable and respects safe-area insets, so adding a long recipe or opening the keyboard does not require a fixed-height card.
The draft is in GlobalState because both layout branches must observe the same content. A row-local draft in each branch would create two independent editors; matching their labels would not make their state shared.
{"id":"fission-tabs-1","tabs":[{"index":0,"label":"src/state.rs","value":"src-state-rs"},{"index":1,"label":"src/editor.rs","value":"src-editor-rs"},{"index":2,"label":"src/recipe_preview.rs","value":"src-recipe-preview-rs"},{"index":3,"label":"src/compact.rs","value":"src-compact-rs"},{"index":4,"label":"src/app.rs","value":"src-app-rs"},{"index":5,"label":"src/translations.rs","value":"src-translations-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"},{"index":8,"label":"src/lib.rs","value":"src-lib-rs"},{"index":9,"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, Default)]
pub struct RecipeState {
    pub title: String,
    pub ingredients: String,
    pub instructions: String,
}
impl GlobalState for RecipeState {}
{"id":"fission-tabs-1","index":1,"label":"src/editor.rs","value":"src-editor-rs"}
use fission::prelude::*;
use crate::state::RecipeState;

fission_component! {
    pub RecipeEditor<RecipeState> {}
    view(_editor, state, cx) {
        let tokens = &cx.view.env().theme.tokens;
    } =>
    Card(child: Column(gap: tokens.spacing.m, children: [
        Text(cx.tr("recipe.edit")).weight(tokens.typography.font_weight_semibold),
        TextInput(
            label: Some(cx.tr("recipe.name").into()),
            bind: state.title,
        ),
        TextInput(
            label: Some(cx.tr("recipe.ingredients").into()),
            multiline: true,
            bind: state.ingredients,
        ),
        TextInput(
            label: Some(cx.tr("recipe.instructions").into()),
            multiline: true,
            bind: state.instructions,
        ),
    ]))
}
{"id":"fission-tabs-1","index":2,"label":"src/recipe_preview.rs","value":"src-recipe-preview-rs"}
use fission::prelude::*;
use crate::state::RecipeState;

fission_component! {
    pub RecipePreview<RecipeState> {}
    view(_preview, state, cx) {
        let tokens = &cx.view.env().theme.tokens;
    } =>
    Card(child: Column(gap: tokens.spacing.m, children: [
        Text(cx.tr("recipe.preview")).weight(tokens.typography.font_weight_semibold),
        if state.title.trim().is_empty()
            && state.ingredients.trim().is_empty()
            && state.instructions.trim().is_empty()
        {
            EmptyState(
                title: cx.tr("recipe.empty"),
                description: cx.tr("recipe.empty_help"),
            )
        } else {
            Column(gap: tokens.spacing.m, children: [
                Text(if state.title.trim().is_empty() {
                    cx.tr("recipe.untitled")
                } else { state.title.clone() }).size(tokens.typography.heading2_size),
                Text(cx.tr("recipe.ingredients")).weight(tokens.typography.font_weight_semibold),
                Text(state.ingredients.clone()),
                Text(cx.tr("recipe.instructions")).weight(tokens.typography.font_weight_semibold),
                Text(state.instructions.clone()),
            ])
        },
    ]))
}
{"id":"fission-tabs-1","index":3,"label":"src/compact.rs","value":"src-compact-rs"}
use fission::prelude::*;
use crate::{editor::RecipeEditor, recipe_preview::RecipePreview, state::RecipeState};

fission_component! {
    pub CompactRecipeLayout<RecipeState> {}
    view(_layout, _state, cx) {
        let tokens = &cx.view.env().theme.tokens;
    } =>
    Column(gap: tokens.spacing.m, children: [
        RecipeEditor(),
        RecipePreview(),
    ])
}
{"id":"fission-tabs-1","index":4,"label":"src/app.rs","value":"src-app-rs"}
use fission::prelude::*;
use crate::{compact::CompactRecipeLayout, state::RecipeState};

fission_component! {
    pub RecipeWorkbench<RecipeState> {}
    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("recipe.title")).size(tokens.typography.heading2_size),
                    Text(cx.tr("recipe.scope")),
                    CompactRecipeLayout(),
                ]),
            ).padding_all(tokens.spacing.l),
        ),
    )
}
{"id":"fission-tabs-1","index":5,"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":6,"label":"i18n/en-US.yaml","value":"i18n-en-us-yaml"}
recipe.title: "Draft a recipe card"
recipe.scope: "Edit your own recipe and read the card alongside it when space allows. This draft is in memory only; it is not saved."
recipe.edit: "Recipe draft"
recipe.name: "Recipe name"
recipe.ingredients: "Ingredients"
recipe.instructions: "Instructions"
recipe.preview: "Reading view"
recipe.empty: "Your recipe card is empty"
recipe.empty_help: "Add a name, ingredients or instructions in the editor."
recipe.untitled: "Untitled recipe"
{"id":"fission-tabs-1","index":7,"label":"i18n/es-ES.yaml","value":"i18n-es-es-yaml"}
recipe.title: "Preparar una ficha de receta"
recipe.scope: "Edita tu receta y lee la ficha a su lado cuando haya espacio. El borrador solo está en memoria; no se guarda."
recipe.edit: "Borrador de receta"
recipe.name: "Nombre de la receta"
recipe.ingredients: "Ingredientes"
recipe.instructions: "Instrucciones"
recipe.preview: "Vista de lectura"
recipe.empty: "La ficha de receta está vacía"
recipe.empty_help: "Añade un nombre, ingredientes o instrucciones en el editor."
recipe.untitled: "Receta sin título"
{"id":"fission-tabs-1","index":8,"label":"src/lib.rs","value":"src-lib-rs"}
pub mod app;
mod state;
mod editor;
mod recipe_preview;
mod compact;
mod translations;

use app::RecipeWorkbench;
use state::RecipeState;
use fission::prelude::*;

#[cfg(not(any(target_arch = "wasm32", target_os = "android", target_os = "ios")))]
pub fn run_desktop() -> anyhow::Result<()> {
    DesktopApp::<RecipeState, _>::new(RecipeWorkbench)
        .with_env(translations::create_env())
        .run()
}
#[cfg(any(target_os = "android", target_os = "ios"))]
fn mobile_app() -> MobileApp<RecipeState, RecipeWorkbench> {
    let app = MobileApp::<RecipeState, _>::new(RecipeWorkbench)
        .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::<RecipeState, _>::new(RecipeWorkbench)
        .with_env(translations::create_env())
        .run()
        .map_err(|error| wasm_bindgen::JsValue::from_str(&error.to_string()))
}
{"id":"fission-tabs-1","index":9,"label":"preview/lib.rs","value":"preview-lib-rs"}
mod app;
mod state;
mod editor;
mod recipe_preview;
mod compact;
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::RecipeState, _>::new(app::RecipeWorkbench)
        .with_env(translations::create_env())
        .mount("#fission-web-mount")
        .run()
        .map_err(|error| JsValue::from_str(&error.to_string()))
}
{"id":"fission-tabs-1"}
Enter your recipe name, a few ingredients and several lines of instructions. The reading view should update from the same values. On a narrow screen, scroll between the form and card without losing the draft.
Show the app preview
Hide the app preview

2. Choose independent layouts around a design-system breakpoint

Responsive owns the width rule. The app does not scatter viewport comparisons through the editor and preview. The breakpoint comes from the active design system; test whether that threshold gives these two panes enough room rather than assuming it suits every design.
The identity-aware constructor builds each branch under a different retained scope. Supply component values which construct independent trees, not clones of a prebuilt Widget. The editor and preview implementations are still shared code; their mounted widget instances are separate.
{"id":"fission-tabs-1","tabs":[{"index":0,"label":"src/wide.rs","value":"src-wide-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/wide.rs","value":"src-wide-rs"}
use fission::prelude::*;
use crate::{editor::RecipeEditor, recipe_preview::RecipePreview, state::RecipeState};

fission_component! {
    pub WideRecipeLayout<RecipeState> {}
    view(_layout, _state, cx) {
        let tokens = &cx.view.env().theme.tokens;
    } =>
    Row(gap: tokens.spacing.m, align_items: ir_op::AlignItems::Start, children: [
        Container(child: RecipeEditor(), width: 0.0, min_width: 0.0, flex_grow: 1.0),
        Container(child: RecipePreview(), width: 0.0, min_width: 0.0, flex_grow: 1.0),
    ])
}
{"id":"fission-tabs-1","index":1,"label":"src/app.rs","value":"src-app-rs"}
use fission::prelude::*;
use crate::{compact::CompactRecipeLayout, state::RecipeState};
use crate::wide::WideRecipeLayout;
fission_component! {
    pub RecipeWorkbench<RecipeState> {}
    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("recipe.title")).size(tokens.typography.heading2_size),
                    Text(cx.tr("recipe.scope")),
                    Responsive::new_with_id(
                        WidgetId::explicit("recipe.layout"),
                        || WideRecipeLayout,
                    ).case_max_width_with(
                        tokens.breakpoints.medium_max,
                        || CompactRecipeLayout,
                    ),
                ]),
            ).padding_all(tokens.spacing.l),
        ),
    )
}
{"id":"fission-tabs-1","index":2,"label":"src/lib.rs","value":"src-lib-rs"}
pub mod app;
mod state;
mod editor;
mod recipe_preview;
mod compact;
mod wide;
mod translations;

use app::RecipeWorkbench;
use state::RecipeState;
use fission::prelude::*;

#[cfg(not(any(target_arch = "wasm32", target_os = "android", target_os = "ios")))]
pub fn run_desktop() -> anyhow::Result<()> {
    DesktopApp::<RecipeState, _>::new(RecipeWorkbench)
        .with_env(translations::create_env())
        .run()
}
#[cfg(any(target_os = "android", target_os = "ios"))]
fn mobile_app() -> MobileApp<RecipeState, RecipeWorkbench> {
    let app = MobileApp::<RecipeState, _>::new(RecipeWorkbench)
        .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::<RecipeState, _>::new(RecipeWorkbench)
        .with_env(translations::create_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 state;
mod editor;
mod recipe_preview;
mod compact;
mod wide;
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::RecipeState, _>::new(app::RecipeWorkbench)
        .with_env(translations::create_env())
        .mount("#fission-web-mount")
        .run()
        .map_err(|error| JsValue::from_str(&error.to_string()))
}
{"id":"fission-tabs-1"}
Type a recipe, widen the window until the panes sit side by side, then make it narrow again. The same draft must remain visible. Below the maximum-width threshold the compact branch applies; at the threshold and above, the wide fallback applies.
The responsive widget constructs and lowers its branches even when only one is visible. Hidden content is not an authorisation or resource-startup boundary. Keep effects out of component conversion and use ProtectedRoute when access must prevent constructing a tree.
Show the app preview
Hide the app preview

3. Check width changes whilst the app is in use

fission doctor android --project-dir .
fission run --target android --project-dir .
fission test --target android --project-dir .
fission build --target android --project-dir . --release
On an emulator and a phone, rotate whilst a field is focused, open the keyboard, use a narrow split-screen window and increase Android's text size. The reading view and inputs should remain reachable without horizontal clipping. Focus and selection also need native checks; shared draft values alone do not prove those interactions survive every layout transition.
Test immediately below, at and above the chosen breakpoint, with a long Spanish label and a long recipe. A wide screenshot with short English text does not qualify the compact branch.
This example uses viewport width because it chooses the page layout. A reusable widget embedded in a narrower panel can use Responsive::container_query() instead. Do not select a phone layout merely because its parent happens to be an Android shell.
The editor now has two arrangements and one draft authority. Layout adapts to space, components use design tokens and the native shell supplies safe-area and text-scale inputs. Persistence is deliberately not implemented, so restarting the app clears the recipe.

Current references