Mobile UI#
Overview#
Trilium's mobile interface is a fully separate layout from the desktop app, activated server-side by user-agent detection and overridable by query parameter (?mobile) or the trilium-device cookie. On the client side, when window.glob.device === "mobile", the entry point loads mobile.js which instantiates MobileLayout to build the widget tree.
Key entry points:
- Layout:
apps/client/src/layouts/mobile_layout.tsx - Root container / keyboard detection:
apps/client/src/widgets/containers/root_container.ts - Launch bar:
apps/client/src/widgets/launch_bar/LauncherContainer.tsx - Editor toolbar:
apps/client/src/widgets/type_widgets/text/mobile_editor_toolbar.tsx - Sidebar drag:
apps/client/src/widgets/mobile_widgets/sidebar_container.ts
Layout Architecture#
MobileLayout.getRootWidget() builds a three-part vertical stack inside a RootContainer with the .horizontal-layout class:
#mobile-sidebar-container— a flex column reserved for auxiliary sidebar content.#mobile-rest-container— a flex row containing two responsive panels:#mobile-sidebar-wrapper(SidebarContainer): hostsQuickSearchandMobileNoteNavigator; responsive Bootstrap columns (col-12on phones,col-sm-5/col-md-4/col-lg-3on wider screens).#detail-container(ScreenContainer): holds the note wrapper with a title row (toggle sidebar button, icon, title, badges,MobileDetailMenu), a scrolling content area (NoteDetail,NoteList,SearchResult),MobileEditorToolbar, andFindWidget.
#mobile-bottom-bar— a fixed-height (53 px) flex row containingLauncherContainerandGlobalMenuWidget.
RootContainer sets height: 100dvh to keep the layout anchored to the dynamic viewport height, which is critical for correct behavior when the virtual keyboard appears.
Tablet Layout (992px and wider)#
At 992px and wider, the mobile layout adjusts for tablet screens:
- Launch bar positioning:
column-reverseon the root flex container moves#mobile-bottom-barto the top of the screen. The bottom padding that clears the navigation bar shifts from the launch bar itself to the tree and note panes (#mobile-sidebar-wrapperand#detail-container). When the keyboard is open, the panes drop this padding, matching phone behavior. - Safe area handling: All layout elements and popups respect the device's safe-area insets (notch, status bar, navigation bar). On tablets the navigation bar is at the bottom; the panes extend their padding to clear it while the keyboard is closed.
Launch Bar#
The mobile launch bar is rendered by LauncherContainer placed inside #mobile-bottom-bar with isHorizontalLayout={true}. It reads launcher configuration from the _lbMobileRoot hidden subtree note — distinct from the desktop _lbRoot — and also references _lbMobileVisibleLaunchers / _lbMobileAvailableLaunchers for per-item visibility control.
Each child note maps to a <Launcher> component whose launcherType label (command, note, script, customWidget, builtinWidget) determines rendering. On mobile, launch bar tooltips are repositioned to the "top" (rather than desktop's "bottom" or "right") via the getTitlePosition(isHorizontalLayout) helper, and keyboard shortcuts are suppressed in the Button component.
Virtual Keyboard Detection#
Detection is centralised in RootContainer#onMobileResize(), which is wired to window.visualViewport.resize on mobile at render time.
The key challenge is that on iOS, window.innerHeight shrinks when the keyboard opens (unlike Android), so the implementation stores the pre-keyboard height at construction. The detection logic is:
originalWindowHeight = window.innerHeight
windowHeight = Math.max(window.innerHeight, originalWindowHeight)
isKeyboardOpened = windowHeight − viewportHeight > 150
When the keyboard is detected as open, the class virtual-keyboard-opened is toggled on #root-widget. Downstream CSS and the iOS toolbar hook consume this signal to adjust layout. This approach was introduced in PR #8832 to fix iOS-specific keyboard detection regressions.
Mobile Editor Toolbar#
MobileEditorToolbar uses platform-divergent strategies for repositioning the CKEditor toolbar when the virtual keyboard appears:
- iOS: The
usePositioningOniOS()hook computeswindow.innerHeight - viewport.height - viewport.offsetTopand applies it as an inlinebottomstyle, using a baseline offset captured before the keyboard opens. When the keyboard closes, the inline style is removed and CSS takes over. - Android: No JavaScript repositioning; the global CSS class
.virtual-keyboard-openedon#root-widgethandles the layout shift through stylesheets.
iOS is identified at runtime via isIOS(), and RootContainer#setDeviceSpecificClasses() adds body.ios at startup so CSS can branch on platform. The split-pane dimming rule (#root-widget.virtual-keyboard-opened .note-split:not(.active)) explicitly excludes iOS via body:not(.ios) to avoid conflicting with the hook's absolute positioning.
A MutationObserver inside the toolbar watches for CKEditor dropdown aria-expanded changes to manage dropdown visibility state.
Menus#
In the mobile layout, menus adapt to screen width:
- Below 992px (phone): Dropdowns (note menu, etc.) appear as bottom sheets across the full width with top-only rounding; context menus open as sheets up to 90% of screen height. The
.mobile-bottom-menurules pin them to the bottom over a dimmed page. - At 992px and wider (tablet): Dropdowns and context menus open beside what triggered them, positioned by Floating UI with a 260px minimum width. Their height is capped to the available room, with rows scrolling. Menu rows keep their touch sizing (
body.mobilerules) but gain proper placement and overflow handling at tablet widths.
The breakpoint is defined by isNarrowLayout() in services/utils.ts, which must match the max-width: 991px media query around the .mobile-bottom-menu rules in style.css. Menus track the layout and close if a tablet rotates across the breakpoint while open.
Sidebar Drag & Mobile Detail Menu#
Sidebar#
SidebarContainer manages the swipe-to-open/close sidebar using touch events (touchstart, touchmove, touchend). The drag is RTL-aware: the closed state uses translateX(-100%) for LTR and translateX(100%) for RTL. The DRAG_OPENED_START_THRESHOLD is 100 px (raised from 80 px in PR #8769 to reduce accidental sidebar triggers).
Mobile Detail Menu#
MobileDetailMenu provides modal-based access to note meta-features that desktop surfaces in sidebars or context menus. It lives in the note title row and exposes:
- Backlinks
- Note paths
- Note info
- Similar notes
- Code language / MIME type switcher (for code notes)
Modals are portal-rendered to document.body. Introduced in PR #8615.
Safe Area Insets and Popups#
All popups are kept clear of device safe areas (notch, status bar, navigation bar). placeFloating() in Popup.tsx measures the insets via a probe element (tn-safe-area-probe) that reads the --safe-area-inset-* CSS environment variables, then extends Floating UI's viewport padding by 5px past each inset. This ensures dropdowns, context menus, and other popups flip, shift, and cap their height without being obscured by system bars.
A debug mode for simulating safe-area insets in desktop browsers is available by setting VITE_DEBUG_SAFE_AREA_INSETS in apps/client/.env (e.g., "0 0 48 0" for a 48px navigation bar). At startup the client applies the insets as CSS custom properties and draws a translucent red overlay over the covered area. The debug module is imported dynamically and tree-shaken from production builds.