mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-12-05 11:15:01 +03:00
6.2 KiB
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-mobileowns the interactive 4-TabBar product shell (Home,Explorer,Journals,Search), 10-groupSettings(with theExperimentalsheet),WorkspaceDrawer(with its typed filter),Pageheader (Breadcrumb,Read-only/Editingtoggle, the journal week strip of a journal,DocActionssheet with thePage | Edgelessview switch andDefault to Edgeless mode,View Info,Location & Trail,Table of contents, and same-day journal conflict sheets, independentBacklinkspill/sheet), embedded liveEntity<playground::PlaygroundView>(hide_chrome = true,WorkspaceDocDirectoryinjection, the document's primary mode or the session's view mode, Page and Database edits gated bypage_readonlyfor trashed docs and theRead-onlytoggle, Edgeless edits gated also byenable_mobile_edgeless_editing),MobileBackCoordinator, and frame-1AccessibilityTreepublication.- Live
affine-store/affine-clientSQLite WAL persistence andSpaceSyncbridge attach viaworkspace_bridge/(for Rust workspace sessions; native iOS and Android thin hosts currently mountplayground::PlaygroundView+SqliteWorkspaceStorebridges directly);showcase::seed_showcase_statesupplies 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, andblocksuite/crates/*). Never depend onpackages/frontend/hosts/*orpackages/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 soar/fa/urlocales 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
Settingsaligned with the 10-section mobile contract and never exposeenable_editor_rtlin 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
Searchquery and theWorkspaceDrawerfilter take text through the oneEntityInputHandlerofMobileShellViewand the sharedstate::TextFieldMutedit 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. OneShapedLinefor 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), as0.27.5AppTabshides itself whileVirtualKeyboardService.visible$is true. The accessibility tree follows the same rule. - On the
Pageroute 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 theKeyboardToolbarsits 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 exceptWorkspaceDrawer) moves the focus from the editor to the shell, so the keyboard goes down. Hosts that draw the selection UI natively set it withMobileShellView::set_native_selection_ui; the default (NativeSelectionUi::default()) keeps the GPU caret, handles, and menu for Web and tests. - Flush a
workspace_bridge/session throughSqliteWorkspaceStore::flush_session_mutations(MobileWorkspaceBridge::flush_session_mutations) so that local clocks, deletion tombstones, andpushed_clockadvances commit together.MobileShellView::connect_workspacebinds 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
Backlinksoutside theNavigation("Breadcrumb")landmark and synchronizeAccessibilityTreeon frame 1 in production builds (withoutharnessfeature gates in shipping views). - Change documents only through
WorkspaceData::docs_mut,doc_mut,set_doc_crdt_update, andremove_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_overscanputs inside the viewport plus overscan, and the accessibility tree publishes rows from the same cached models and windows. - Keep every
.rsfile at or below 800 non-test lines, zerosuper::super::, and zerois_headlessbranches.
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