Get started
Introduction
Installation
Your first app
Tutorials
Fission tutorials
Make an iOS layout adapt across iPhone and iPad 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 iOS layout adapt across iPhone and iPad sizes

Edit an announcement whilst its independent compact and wide layouts share the same app-owned draft.
iOS

What you will build

Adapt the announcement editor to its available container width without cloning retained widget trees or losing shared draft data.
Construct an independent tree for each responsive branch
Keep the announcement in shared state across branch changes
Test narrow split-screen constraints rather than equating device names with width
A responsive layout changes how a task is presented, not what the user has entered. For an announcement editor, a wide window can show the draft and its preview side by side, whilst a narrow window needs those sections stacked. Neither arrangement should own a separate copy of the announcement.
We will build that editor with real user input. The draft belongs to application state because two independently constructed layout branches read it. Resizing can therefore change the arrangement without replacing the user's work with another branch's empty local state.

Create the project

Complete iOS setup first, then generate the shared app.
cargo install cargo-fission
fission init ios-make-an-ios-layout-adapt-across-iphone-and-ipad-sizes
cd ios-make-an-ios-layout-adapt-across-iphone-and-ipad-sizes
fission add-target ios --project-dir .
cargo add serde_yaml
Keep the generated src/main.rs and replace src/lib.rs with the shared shell wiring below. Native and Web targets then run the same editor rather than a browser-only layout demonstration.

Run the finished example

fission run --target ios --project-dir .

1. Share the task, not one retained widget instance

The editor and preview are named components. Each responsive branch constructs its own instances, whilst both read the same AnnouncementState. Do not construct one Widget and clone it into both branches: retained widget identity and shared application data are not interchangeable.
The breakpoint is a layout choice, not a claim that every iPad is wide. A narrow split-screen window on an iPad should receive the compact arrangement too. The example uses a container query because it must also respond correctly when embedded in the documentation's preview panel.
{"id":"fission-tabs-1","tabs":[{"index":0,"label":"src/app.rs","value":"src-app-rs"},{"index":1,"label":"src/app/state.rs","value":"src-app-state-rs"},{"index":2,"label":"src/app/editor.rs","value":"src-app-editor-rs"},{"index":3,"label":"src/app/preview.rs","value":"src-app-preview-rs"},{"index":4,"label":"src/app/screen.rs","value":"src-app-screen-rs"},{"index":5,"label":"src/i18n.rs","value":"src-i18n-rs"},{"index":6,"label":"src/lib.rs","value":"src-lib-rs"},{"index":7,"label":"preview/lib.rs","value":"preview-lib-rs"},{"index":8,"label":"i18n/en-US.yaml","value":"i18n-en-us-yaml"},{"index":9,"label":"i18n/es-ES.yaml","value":"i18n-es-es-yaml"}]}
{"id":"fission-tabs-1","index":0,"label":"src/app.rs","value":"src-app-rs"}
mod editor;
mod preview;
mod screen;
pub mod state;
pub use screen::AnnouncementScreen;
pub use state::AnnouncementState;
{"id":"fission-tabs-1","index":1,"label":"src/app/state.rs","value":"src-app-state-rs"}
use fission::prelude::*;

#[derive(Clone, Debug, PartialEq, Eq)]
pub struct AnnouncementState {
    pub title: String,
    pub message: String,
    pub locale: Locale,
}

impl Default for AnnouncementState {
    fn default() -> Self {
        Self {
            title: String::new(),
            message: String::new(),
            locale: Locale::from("en-US"),
        }
    }
}

impl GlobalState for AnnouncementState {}
{"id":"fission-tabs-1","index":2,"label":"src/app/editor.rs","value":"src-app-editor-rs"}
use super::state::AnnouncementState;
use fission::prelude::*;

fission_component! {
    pub AnnouncementEditor<AnnouncementState> {}
    view(_editor, state, cx) {
        let tokens = &cx.view.env().theme.tokens;
    } => Column(gap: tokens.spacing.m, children: [
        Text(cx.tr("announcement.edit")).weight(tokens.typography.font_weight_semibold),
        FormControl(
            label: Some(cx.tr("announcement.title")),
            required: true,
            child: TextInput(
                value: state.title.clone(),
                bind(on_input): to(state.title),
            ),
        ),
        TextInput(
            value: state.message.clone(),
            bind(on_input): to(state.message),
            label: Some(TextContent::Key("announcement.message".into())),
            multiline: true,
            keyboard_type: TextInputType::Multiline,
        ),
        Button(
            child: Text(cx.tr("announcement.clear")), key: "clear-draft",
            disabled: state.title.is_empty() && state.message.is_empty(),
            on_press: reduce { state.title.clear(); state.message.clear(); },
        ),
    ])
}
{"id":"fission-tabs-1","index":3,"label":"src/app/preview.rs","value":"src-app-preview-rs"}
use super::state::AnnouncementState;
use fission::prelude::*;

fission_component! {
    pub AnnouncementPreview<AnnouncementState> {}
    view(_preview, state, cx) {
        let tokens = &cx.view.env().theme.tokens;
    } => Container(
        Column(gap: tokens.spacing.m, children: [
            Text(cx.tr("announcement.preview")).color(tokens.colors.text_secondary),
            if state.title.trim().is_empty() && state.message.trim().is_empty() {
                Text(cx.tr("announcement.empty"))
            } else {
                Column(gap: tokens.spacing.s, children: [
                    Text(state.title.clone()).size(tokens.typography.heading2_size),
                    Text(state.message.clone()),
                ])
            },
            Text(cx.tr("announcement.not_sent")).color(tokens.colors.text_secondary),
        ]),
    )
    .padding_all(tokens.spacing.m)
    .border(tokens.colors.border, 1.0)
    .border_radius(tokens.radii.medium)
}
{"id":"fission-tabs-1","index":4,"label":"src/app/screen.rs","value":"src-app-screen-rs"}
use super::{editor::AnnouncementEditor, preview::AnnouncementPreview, state::AnnouncementState};
use fission::prelude::*;

const TWO_PANE_MIN_WIDTH: f32 = 760.0;

fission_component! {
    pub WideAnnouncement<AnnouncementState> {}
    view(_layout, _state, cx) {
        let tokens = &cx.view.env().theme.tokens;
    } => Row(gap: tokens.spacing.l, children: [
        Container(AnnouncementEditor).flex_grow(1.0),
        Container(AnnouncementPreview).flex_grow(1.0),
    ])
}

fission_component! {
    pub CompactAnnouncement<AnnouncementState> {}
    view(_layout, _state, cx) {
        let tokens = &cx.view.env().theme.tokens;
    } => Column(gap: tokens.spacing.l, children: [
        AnnouncementEditor,
        AnnouncementPreview,
    ])
}

fission_component! {
    pub AnnouncementScreen<AnnouncementState> {}
    view(_screen, state, cx) {
        let tokens = &cx.view.env().theme.tokens;
    } => SafeArea(
        child: Scroll(
            child: Container(Column(gap: tokens.spacing.m, children: [
                Text(cx.tr("announcement.heading")).size(tokens.typography.heading2_size),
                Text(cx.tr("announcement.explanation")),
                Row(gap: tokens.spacing.s, children: [
                    Button(
                        child: Text(cx.tr("language.english")), key: "english",
                        on_press: reduce { state.locale = Locale::from("en-US"); },
                    ),
                    Button(
                        child: Text(cx.tr("language.spanish")), key: "spanish",
                        on_press: reduce { state.locale = Locale::from("es-ES"); },
                    ),
                ]),
                Responsive::new_with_id(
                    WidgetId::explicit("announcement.layout"),
                    || WideAnnouncement,
                )
                .case_max_width_with(TWO_PANE_MIN_WIDTH, || CompactAnnouncement)
                .container_query(),
            ]))
            .padding_all(tokens.spacing.l),
        ),
    )
}
{"id":"fission-tabs-1","index":5,"label":"src/i18n.rs","value":"src-i18n-rs"}
use fission::i18n::{Locale, TranslationBundle};
use fission::prelude::*;
use std::collections::HashMap;

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 announcement translations");
        env.i18n.add_bundle(TranslationBundle {
            locale: Locale::from(locale),
            messages,
        });
    }
    env
}

pub fn sync_env(state: &crate::app::AnnouncementState, env: &mut Env) {
    env.locale = state.locale.clone();
}
{"id":"fission-tabs-1","index":6,"label":"src/lib.rs","value":"src-lib-rs"}
pub mod app;
mod i18n;

use app::{AnnouncementScreen, AnnouncementState};
use fission::prelude::*;

#[cfg(not(any(target_arch = "wasm32", target_os = "android", target_os = "ios")))]
pub fn run_desktop() -> anyhow::Result<()> {
    DesktopApp::<AnnouncementState, _>::new(AnnouncementScreen)
        .with_env(i18n::create_env())
        .with_sync_env(i18n::sync_env)
        .run()
}

#[cfg(any(target_os = "android", target_os = "ios"))]
pub fn run_mobile() -> anyhow::Result<()> {
    MobileApp::<AnnouncementState, _>::new(AnnouncementScreen)
        .with_env(i18n::create_env())
        .with_sync_env(i18n::sync_env)
        .run()
}

#[cfg(target_os = "android")]
#[no_mangle]
fn android_main(app_handle: AndroidApp) {
    let _ = MobileApp::<AnnouncementState, _>::new(AnnouncementScreen)
        .with_env(i18n::create_env())
        .with_sync_env(i18n::sync_env)
        .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::<AnnouncementState, _>::new(AnnouncementScreen)
        .with_env(i18n::create_env())
        .with_sync_env(i18n::sync_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 i18n;

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

#[wasm_bindgen(start)]
pub fn run() -> Result<(), JsValue> {
    console_error_panic_hook::set_once();
    WebApp::<app::AnnouncementState, _>::new(app::AnnouncementScreen)
        .with_env(i18n::create_env())
        .with_sync_env(i18n::sync_env)
        .mount("#fission-web-mount")
        .run()
        .map_err(|error| JsValue::from_str(&error.to_string()))
}
{"id":"fission-tabs-1","index":8,"label":"i18n/en-US.yaml","value":"i18n-en-us-yaml"}
announcement.heading: "Prepare a team announcement"
announcement.explanation: "Write a message and review it beside the editor when there is room, or below it on a narrow screen."
announcement.edit: "Edit the announcement"
announcement.title: "Announcement title"
announcement.message: "Message"
announcement.clear: "Clear draft"
announcement.preview: "Message preview"
announcement.empty: "Your announcement will appear here as you write."
announcement.not_sent: "This is a preview. Nothing has been sent or saved to disk."
language.english: "English"
language.spanish: "Español"
{"id":"fission-tabs-1","index":9,"label":"i18n/es-ES.yaml","value":"i18n-es-es-yaml"}
announcement.heading: "Preparar un anuncio para el equipo"
announcement.explanation: "Escribe un mensaje y revísalo junto al editor cuando haya espacio, o debajo en una pantalla estrecha."
announcement.edit: "Editar el anuncio"
announcement.title: "Título del anuncio"
announcement.message: "Mensaje"
announcement.clear: "Borrar borrador"
announcement.preview: "Vista previa del mensaje"
announcement.empty: "Tu anuncio aparecerá aquí mientras escribes."
announcement.not_sent: "Esto es una vista previa. No se ha enviado ni guardado nada en disco."
language.english: "Inglés"
language.spanish: "Español"
{"id":"fission-tabs-1"}
Write an announcement, then resize until the preview moves below the editor. Both fields and the preview must still show your draft. Clear it from either arrangement and confirm that no old copy reappears when you resize again.
Show the app preview
Hide the app preview

2. Choose constraints that describe the component's actual space

Responsive checks its cases in order and uses the fallback when none match. Here the compact case matches below 760 logical units and the fallback takes over at 760. The value is explicit so you can adjust it after checking the two sections' real content; it is not a device-model lookup.
Without .container_query(), the query uses the full viewport. That can be appropriate for an app shell, but it is wrong for an editor inside a smaller panel: a wide browser window does not imply the embedded editor has enough room for two columns.
The identity-aware constructors give each branch its own retained scope. They do not transfer local state from one branch into another, and hidden responsive branches are not an authorization boundary. Keeping the announcement in shared state follows from its ownership; it is not an incidental workaround for resizing.
Switch to Spanish, use a long title and several message paragraphs, and inspect widths on both sides of the breakpoint. The result should remain readable without clipped actions or overlapping text. A breakpoint transition alone is not sufficient evidence that either layout is good.
Show the app preview
Hide the app preview

3. Verify windows rather than device names

fission doctor ios --project-dir .
fission devices --project-dir .
fission run --target ios --project-dir .
fission test --target ios --project-dir .
Follow the simulator guide for selection. Check an iPhone in both orientations and an iPad at full width and a narrow supported multitasking width. Keep a draft open during every transition; that tests ownership as well as layout.
Repeat with larger system text and the keyboard visible. Those settings can expose insufficient space even when the width rule is correct. The generated host smoke test checks launch, not text clipping, focus, keyboard avoidance or draft continuity, so exercise those paths explicitly before calling the screen qualified.
This is an in-memory editor. It intentionally has no Send action or persistence claim; the Store tutorial covers retaining a draft across process restarts.