Files
AFFiNE/packages/frontend/mobile/AGENTS.md
T

6.2 KiB

Working in packages/frontend/mobile/ (for agents)

packages/frontend/mobile/ (affine-mobile) is the L4 pure-Rust mobile product shell inside the client workspace rooted at packages/frontend/Cargo.toml.

Scope and integration boundary

  • affine-mobile owns the interactive 4-TabBar product shell (Home, Explorer, Journals, Search), 10-group Settings (with the Experimental sheet), WorkspaceDrawer (with its typed filter), Page header (Breadcrumb, Read-only / Editing toggle, the journal week strip of a journal, DocActions sheet with the Page | Edgeless view switch and Default to Edgeless mode, View Info, Location & Trail, Table of contents, and same-day journal conflict sheets, independent Backlinks pill/sheet), embedded live Entity<playground::PlaygroundView> (hide_chrome = true, WorkspaceDocDirectory injection, the document's primary mode or the session's view mode, Page and Database edits gated by page_readonly for trashed docs and the Read-only toggle, Edgeless edits gated also by enable_mobile_edgeless_editing), MobileBackCoordinator, and frame-1 AccessibilityTree publication.
  • Live affine-store / affine-client SQLite WAL persistence and SpaceSync bridge attach via workspace_bridge/ (for Rust workspace sessions; native iOS and Android thin hosts currently mount playground::PlaygroundView + SqliteWorkspaceStore bridges directly); showcase::seed_showcase_state supplies deterministic in-memory workspaces for offline harness verification and preview galleries.

Domain boundaries and invariants

  • Keep #![forbid(unsafe_code)] at the crate root.
  • Depend only on workspace crates allowed by packages/frontend/scripts/check-invariants.sh (ui-tokens, ui, ui-kit, affine-store, affine-legacy-import, affine-client, and blocksuite/crates/*). Never depend on packages/frontend/hosts/* or packages/frontend/desktop.
  • Use logical inline geometry (ui_kit::LogicalEdges, ui_kit::LogicalStyled, ui_kit::SafeArea, inline_start, inline_end) instead of physical left/right layout helpers so ar/fa/ur locales mirror cleanly.
  • Drive all transitions from closed-form scheduler time (ui::Motion, ui_kit::Sheet, ui_kit::evaluate_micro_icon). Never call system wall clocks (Instant::now, SystemTime::now, Zoned::now, Timestamp::now).
  • Keep Settings aligned with the 10-section mobile contract and never expose enable_editor_rtl in Experimental settings. A row without a backing service shows a read-only value (the workspace sync status, where the workspace is stored) instead of a switch that changes nothing.
  • The Search query and the WorkspaceDrawer filter take text through the one EntityInputHandler of MobileShellView and the shared state::TextFieldMut edit rules. A line longer than its field scrolls (state::FieldScroll) only as far as it must to keep the caret, or the end of the IME composition, in view. One ShapedLine for the whole field preserves bidirectional clusters and joining glyphs. Painting, scroll, IME bounds, and touch offsets use this layout and the same transform. The line sits at the start edge of the locale when it fits and scrolls when it is wider than the field.
  • The bottom TabBar shows on the four tab routes only while the software keyboard is down (MobileRoute::shows_tabbar), as 0.27.5 AppTabs hides itself while VirtualKeyboardService.visible$ is true. The accessibility tree follows the same rule.
  • On the Page route the embedded editor in Page mode owns the bottom edge: the shell pads no bottom safe area or keyboard inset, and passes its resolved keyboard height to the editor (set_host_ime_bottom), so the KeyboardToolbar sits directly on the keyboard. In Edgeless mode the shell keeps the bottom padding, because the canvas places its controls inside the bounds it gets. An overlay sheet over the page (all sheets except WorkspaceDrawer) moves the focus from the editor to the shell, so the keyboard goes down. Hosts that draw the selection UI natively set it with MobileShellView::set_native_selection_ui; the default (NativeSelectionUi::default()) keeps the GPU caret, handles, and menu for Web and tests.
  • Flush a workspace_bridge/ session through SqliteWorkspaceStore::flush_session_mutations (MobileWorkspaceBridge::flush_session_mutations) so that local clocks, deletion tombstones, and pushed_clock advances commit together. MobileShellView::connect_workspace binds the transport and starts a one-second UI scheduler timer. The shell flushes SQLite off the UI thread, projects the result into the binding that ran the tick, repaints only when the projection changed what the shell shows, and delivers sync events to the host. The shell commits pending local changes to the old SQLite store before it replaces or detaches a connected bridge. A page that leaves the root document leaves the shell with its cached bytes, while shell-only drafts stay.
  • Keep Backlinks outside the Navigation("Breadcrumb") landmark and synchronize AccessibilityTree on frame 1 in production builds (without harness feature gates in shipping views).
  • Change documents only through WorkspaceData::docs_mut, doc_mut, set_doc_crdt_update, and remove_doc_crdt_update. Their process-wide revision stamps key the cached search hits, drawer sections, Explorer rows, editor directory snapshot, and bridge sync, so a direct write would leave them stale.
  • Explorer and Home document lists mount only the rows that row_window / row_window_overscan puts inside the viewport plus overscan, and the accessibility tree publishes rows from the same cached models and windows.
  • Keep every .rs file at or below 800 non-test lines, zero super::super::, and zero is_headless branches.

Verification

Run inside packages/frontend/ with root NAPI flags cleared:

CARGO_ENCODED_RUSTFLAGS="" cargo check --locked -p affine-mobile --target wasm32-unknown-unknown
CARGO_ENCODED_RUSTFLAGS="" cargo test --locked -p affine-mobile --all-targets
CARGO_ENCODED_RUSTFLAGS="" cargo run --locked -p affine-mobile --features harness --bin mobile-harness -- audit-matrix
CARGO_ENCODED_RUSTFLAGS="" cargo run --locked -p affine-mobile --features harness --bin mobile-harness -- fps-replay
./scripts/check-invariants.sh