Skip to content

Build your personal knowledge base with Trilium Notes

feat(options/mobile): add back transition and stabilize the title bar

Elian Doran79c2ade646d5
diff --git a/apps/client/src/widgets/dialogs/OptionsDialog.css b/apps/client/src/widgets/dialogs/OptionsDialog.css
index 5e76e828fc..a228c56d38 100644
--- a/apps/client/src/widgets/dialogs/OptionsDialog.css
+++ b/apps/client/src/widgets/dialogs/OptionsDialog.css
@@ -44,75 +44,104 @@ body.desktop .modal.options-dialog .note-detail-content-widget-content.options {
padding-top: var(--options-first-item-top-margin);
}
-/* On mobile the sidebar and the page become a master-detail flow instead: the dialog first shows
- only the full-height list of pages (replacing the generic bottom-strip sidebar layout from
- style.css), and tapping an entry reveals the page with a back button in the header. */
-body.mobile .modal.options-dialog .modal-content {
+/* On mobile the dialog becomes a master-detail flow instead of the sidebar layout: the page
+ selector is rendered as a pane inside the modal body (the Modal sidebar is unused), so the list
+ and the page can slide over each other when switching between them. */
+body.mobile .modal.options-dialog .modal-dialog .modal-content .modal-body {
+ position: relative;
+ height: auto;
+ padding: 0;
+ /* The panes scroll themselves; this also keeps the sliding panes contained. */
+ overflow: hidden;
+}
+
+body.mobile .modal.options-dialog .options-mobile-nav {
height: 100%;
+ overflow: auto;
}
-body.mobile .modal.options-dialog .modal-body {
- height: auto;
- flex: 1 1 0;
+body.mobile .modal.options-dialog .options-mobile-nav .settings-navigation {
+ padding: 8px 25px;
}
-body.mobile .modal.options-dialog .modal-sidebar {
- height: auto;
- flex: 1 1 0;
- min-height: 0;
- border-bottom: none;
+body.mobile .modal.options-dialog .note-detail {
+ height: 100%;
+ overflow: auto;
}
-body.mobile .modal.options-dialog .modal-sidebar .settings-navigation {
- width: auto;
- padding-inline: 25px;
+/* At rest only the active pane is displayed; during a transition both stay visible so the
+ outgoing pane can slide away as the incoming one slides in. */
+body.mobile .modal.options-dialog.mobile-view-list:not(.mobile-transition-to-list) .note-detail {
+ display: none;
}
-body.mobile .modal.options-dialog.mobile-view-list .modal-body {
+body.mobile .modal.options-dialog.mobile-view-page:not(.mobile-transition-to-page) .options-mobile-nav {
display: none;
}
-/* With the body hidden, collapse the main pane to just its header (the generic layout gives it
- flex-grow: 1, which would leave it occupying half the dialog) so the list takes the full height. */
-body.mobile .modal.options-dialog.mobile-view-list {
- .modal-main {
- flex-grow: 0;
+/* The back button + page title in the custom header replace the static "Options" title. */
+body.mobile .modal.options-dialog .modal-header > .modal-title {
+ display: none;
+}
+
+/* Directional slide mirroring the setup wizard's page animation: opening a page, the list slides
+ out towards the start side while the page slides in from the end side; going back reverses the
+ directions. The page pane stacks above the list, and `forwards` holds the outgoing pane at its
+ off-screen position until the transition classes are removed after animationend. The global
+ `motion-disabled` rule suppresses the animations entirely; the dialog then switches views
+ directly without entering a transition. */
+body.mobile .modal.options-dialog.mobile-transition-to-page,
+body.mobile .modal.options-dialog.mobile-transition-to-list {
+ .options-mobile-nav,
+ .note-detail {
+ position: absolute;
+ inset: 0;
+ background-color: var(--modal-background-color);
}
- .modal-sidebar {
- background: transparent;
+ .note-detail {
+ z-index: 1;
}
}
-body.mobile .modal.options-dialog.mobile-view-page .modal-sidebar {
- display: none;
-}
+body.mobile .modal.options-dialog.mobile-transition-to-page {
+ .note-detail {
+ animation: options-slide-in-end 0.35s ease-in-out forwards;
+ }
-/* In page view the back button + page title replace the static "Options" title. */
-body.mobile .modal.options-dialog.mobile-view-page .modal-header > .modal-title {
- display: none;
+ .options-mobile-nav {
+ animation: options-slide-out-start 0.35s ease-in-out forwards;
+ }
}
-/* Sliding transition between the two views, mirroring the setup wizard's page animation: the page
- slides in from the end side, the list back in from the start side. Becoming displayed restarts
- the animation, so the incoming pane animates exactly when the view switches. The
- `animate-view-switch` class is only present once the user switched views within the open dialog,
- keeping the initial view from sliding when the dialog opens. The global `motion-disabled` rule
- suppresses these when animations are turned off in the settings. */
-body.mobile .modal.options-dialog.animate-view-switch.mobile-view-page .modal-body {
- animation: options-slide-in-end 0.35s ease-in-out;
-}
+body.mobile .modal.options-dialog.mobile-transition-to-list {
+ .note-detail {
+ animation: options-slide-out-end 0.35s ease-in-out forwards;
+ }
-body.mobile .modal.options-dialog.animate-view-switch.mobile-view-list .modal-sidebar {
- animation: options-slide-in-start 0.35s ease-in-out;
+ .options-mobile-nav {
+ animation: options-slide-in-start 0.35s ease-in-out forwards;
+ }
}
-body[dir=rtl].mobile .modal.options-dialog.animate-view-switch.mobile-view-page .modal-body {
- animation-name: options-slide-in-start;
+body[dir=rtl].mobile .modal.options-dialog.mobile-transition-to-page {
+ .note-detail {
+ animation-name: options-slide-in-start;
+ }
+
+ .options-mobile-nav {
+ animation-name: options-slide-out-end;
+ }
}
-body[dir=rtl].mobile .modal.options-dialog.animate-view-switch.mobile-view-list .modal-sidebar {
- animation-name: options-slide-in-end;
+body[dir=rtl].mobile .modal.options-dialog.mobile-transition-to-list {
+ .note-detail {
+ animation-name: options-slide-out-start;
+ }
+
+ .options-mobile-nav {
+ animation-name: options-slide-in-end;
+ }
}
@keyframes options-slide-in-end {
@@ -125,6 +154,16 @@ body[dir=rtl].mobile .modal.options-dialog.animate-view-switch.mobile-view-list
to { transform: translateX(0); opacity: 1; }
}
+@keyframes options-slide-out-end {
+ from { transform: translateX(0); opacity: 1; }
+ to { transform: translateX(100%); opacity: 0; }
+}
+
+@keyframes options-slide-out-start {
+ from { transform: translateX(0); opacity: 1; }
+ to { transform: translateX(-100%); opacity: 0; }
+}
+
.options-mobile-page-header {
display: flex;
align-items: center;
diff --git a/apps/client/src/widgets/dialogs/OptionsDialog.tsx b/apps/client/src/widgets/dialogs/OptionsDialog.tsx
index 14f154891e..f2fdda749a 100644
--- a/apps/client/src/widgets/dialogs/OptionsDialog.tsx
+++ b/apps/client/src/widgets/dialogs/OptionsDialog.tsx
@@ -33,12 +33,25 @@ export default function OptionsDialog() {
const [ lastSection, setLastSection ] = useState<string | null>(null);
// Which half of the mobile master-detail flow is visible; has no effect on desktop.
const [ mobileView, setMobileView ] = useState<"list" | "page">("list");
- // Whether the user switched views since the dialog was opened. Gates the slide animation so
- // that only actual list/page switches animate, not the initial view when the dialog opens.
- const [ viewSwitched, setViewSwitched ] = useState(false);
+ // Direction of the in-flight slide between the two mobile views, or null when at rest. While
+ // set, both panes stay rendered so the outgoing one can slide away as the incoming one slides
+ // in; cleared when the slide animation finishes.
+ const [ mobileTransition, setMobileTransition ] = useState<"to-list" | "to-page" | null>(null);
const modalRef = useRef<HTMLDivElement>(null);
const isMobile = utils.isMobile();
+ // Switches between the mobile master/detail views with a slide. The initial view on open is
+ // set directly (without animating) by the showOptions handler instead.
+ const switchMobileView = useCallback((view: "list" | "page") => {
+ if (view === mobileView) return;
+ setMobileView(view);
+ // With animations globally disabled there is no animationend to clear the transition,
+ // so switch directly.
+ if (!document.body.classList.contains("motion-disabled")) {
+ setMobileTransition(view === "page" ? "to-page" : "to-list");
+ }
+ }, [ mobileView ]);
+
useTriliumEvent("showOptions", async ({ section }) => {
const noteContext = new NoteContext("_options-dialog");
await noteContext.setNote(section ?? lastSection ?? DEFAULT_SECTION, { keepActiveDialog: true });
@@ -48,41 +61,51 @@ export default function OptionsDialog() {
setNoteContext(noteContext);
// Requesting a specific section (e.g. "set up a password") skips the mobile master list.
setMobileView(section ? "page" : "list");
- setViewSwitched(false);
+ setMobileTransition(null);
setShown(true);
});
// Bootstrap adds its own classes (e.g. `show`) to the modal element at runtime, so the
// className prop must stay static — rewriting it from a render would wipe them and visually
- // dismiss the dialog. Toggle the mobile view class directly on the element instead.
+ // dismiss the dialog. Toggle the mobile view classes directly on the element instead.
useEffect(() => {
modalRef.current?.classList.toggle("mobile-view-list", mobileView === "list");
modalRef.current?.classList.toggle("mobile-view-page", mobileView === "page");
- modalRef.current?.classList.toggle("animate-view-switch", viewSwitched);
- }, [ mobileView, viewSwitched ]);
+ modalRef.current?.classList.toggle("mobile-transition-to-list", mobileTransition === "to-list");
+ modalRef.current?.classList.toggle("mobile-transition-to-page", mobileTransition === "to-page");
+ }, [ mobileView, mobileTransition ]);
+
+ // End the view transition once the slide finishes (animationend bubbles up from the panes).
+ useEffect(() => {
+ const modalElement = modalRef.current;
+ if (!modalElement) return;
+ function onAnimationEnd(e: AnimationEvent) {
+ if (e.animationName.startsWith("options-slide")) {
+ setMobileTransition(null);
+ }
+ }
+ modalElement.addEventListener("animationend", onAnimationEnd);
+ return () => modalElement.removeEventListener("animationend", onAnimationEnd);
+ }, []);
// Keep navigation between settings pages (sidebar entries, "Related settings" links) inside the
// dialog; links to regular notes open in the quick-edit popup instead.
useContainedLinkNavigation(modalRef, useCallback((notePath, viewScope) => {
if (notePath.split("/").at(-1)?.startsWith("_options")) {
void noteContext.setNote(notePath, { viewScope, keepActiveDialog: true });
- setMobileView("page");
- setViewSwitched(true);
+ switchMobileView("page");
} else {
void appContext.triggerCommand("openInPopup", { noteIdOrPath: notePath });
}
- }, [ noteContext ]));
+ }, [ noteContext, switchMobileView ]));
return (
<NoteContextContext.Provider value={noteContext}>
<Modal
modalRef={modalRef}
title={t("options.title")}
- header={isMobile && mobileView === "page" ? <MobilePageHeader onBack={() => {
- setMobileView("list");
- setViewSwitched(true);
- }} /> : undefined}
- sidebar={<SettingsSidebar />}
+ header={isMobile && (mobileView === "page" ? <MobilePageHeader onBack={() => switchMobileView("list")} /> : <MobilePageHeader />)}
+ sidebar={isMobile ? undefined : <SettingsSidebar />}
isFullPageOnMobile
customTitleBarButtons={[{
iconClassName: "bx-expand-alt",
@@ -105,6 +128,7 @@ export default function OptionsDialog() {
setShown(false);
}}
>
+ {isMobile && <div className="options-mobile-nav"><SettingsSidebar /></div>}
<NoteDetail />
</Modal>
</NoteContextContext.Provider>
@@ -127,7 +151,7 @@ function SettingsSidebar() {
* Replaces the "Options" title in the mobile page view: a back button returning to the master list
* of pages, followed by the title of the page in view (the static title is hidden via CSS).
*/
-function MobilePageHeader({ onBack }: { onBack: () => void }) {
+function MobilePageHeader({ onBack }: { onBack?: () => void }) {
const { note } = useNoteContext();
return (
<div className="options-mobile-page-header">
@@ -135,6 +159,7 @@ function MobilePageHeader({ onBack }: { onBack: () => void }) {
icon="bx bx-chevron-left"
text={t("options.back")}
onClick={onBack}
+ style={{ visibility: onBack ? "visible" : "hidden" }}
/>
<h5 className="options-mobile-page-title">{note?.title}</h5>
</div>