Skip to content

Build your personal knowledge base with Trilium Notes

fix(mobile): keep iOS dialogs from flipping between sheet shapes

Elian Doran5477bf4e7765
diff --git a/apps/client/src/stylesheets/style.css b/apps/client/src/stylesheets/style.css
index c15007ad3b..9df9d02a70 100644
--- a/apps/client/src/stylesheets/style.css
+++ b/apps/client/src/stylesheets/style.css
@@ -1878,7 +1878,6 @@ pre.code-embed-editor.read-only .cm-activeLine {
padding-bottom: calc(max(var(--menu-padding-size), var(--safe-area-inset-bottom, env(safe-area-inset-bottom)))) !important;
}
- /* The tree lies under the note, which `SidebarContainer` slides away to reveal it. */
#mobile-rest-container {
overflow: clip;
position: relative;
diff --git a/apps/client/src/stylesheets/theme-next/base.css b/apps/client/src/stylesheets/theme-next/base.css
index b2423ef512..76a75c9530 100644
--- a/apps/client/src/stylesheets/theme-next/base.css
+++ b/apps/client/src/stylesheets/theme-next/base.css
@@ -148,7 +148,6 @@ body {
user-select: text;
}
-/* The edge and top highlight of a glass surface, drawn without a border, and its drop shadow. */
:root {
--glass-edge:
inset 0 0 0 1px var(--glass-edge-color),
diff --git a/apps/client/src/stylesheets/theme-next/ios.css b/apps/client/src/stylesheets/theme-next/ios.css
index 130893c317..38d061a5a0 100644
--- a/apps/client/src/stylesheets/theme-next/ios.css
+++ b/apps/client/src/stylesheets/theme-next/ios.css
@@ -9,7 +9,6 @@ body.mobile.ios {
--mobile-sheet-margin: 8px;
--mobile-sheet-radius: 28px;
- /* The formatting toolbar: a capsule, with its buttons spaced out. */
--mobile-toolbar-border: 0px;
--mobile-toolbar-gap: 10px;
--mobile-toolbar-radius: calc(var(--mobile-toolbar-height) / 2);
@@ -18,7 +17,6 @@ body.mobile.ios {
--mobile-toolbar-item-gap: 14px;
--mobile-toolbar-items-inset: 8px;
- /* A menu in the keyboard's place stands a gap below the toolbar, as the keyboard does. */
--keyboard-panel-rise: 0px;
--keyboard-panel-margin: var(--mobile-sheet-margin);
@@ -32,7 +30,6 @@ body.mobile.ios {
--mobile-menu-group-radius: 12px;
}
- /* The note tree, as an inset grouped list. */
#mobile-rest-container > #mobile-sidebar-wrapper {
background: var(--grouped-background-color);
}
@@ -123,7 +120,6 @@ body.mobile.ios {
}
}
- /* Sheets, including the toolbar's menu in the keyboard's place. */
:is(
.tn-dropdown-portal:is(.global-menu, .right-dropdown-widget) > .dropdown-menu,
.dropdown-menu.mobile-bottom-menu
@@ -147,7 +143,6 @@ body.mobile.ios {
padding-bottom: var(--menu-padding-size) !important;
}
- /* The title row and the launcher bar float over the note, which scrolls beneath them. */
#mobile-bottom-bar {
position: relative;
z-index: 999;
@@ -186,7 +181,6 @@ body.mobile.ios {
scroll-padding-bottom: var(--mobile-bottom-bar-height);
}
- /* With no keyboard, the formatting toolbar stands above the launch bar. */
.classic-toolbar-island {
bottom: calc(var(--tn-layout-overhang, 0px) + var(--mobile-bottom-bar-height));
}
@@ -227,8 +221,6 @@ body.mobile.ios {
scroll-padding-top: var(--mobile-title-row-height);
}
- /* Dialogs: a short one floats as a glass sheet, a tall one is an opaque sheet attached to
- the screen's edges. */
.modal-dialog:not(.modal-dialog-full-page-on-mobile) > .modal-content {
border: 0;
border-radius: var(--mobile-sheet-radius) var(--mobile-sheet-radius) 0 0;
@@ -256,8 +248,7 @@ body.mobile.ios {
}
}
- /* The title is centered on the sheet: it starts as far from the leading edge as the buttons
- after it reach from the trailing one, each a 40px circle with an 8px margin. */
+ /* Each button after the title is a 40px circle with the 8px margin from dialogs.css. */
.modal .modal-header {
--modal-header-trailing-width: 48px;
diff --git a/apps/client/src/widgets/react/Modal.spec.tsx b/apps/client/src/widgets/react/Modal.spec.tsx
index f6bc9de1a7..663f034f3d 100644
--- a/apps/client/src/widgets/react/Modal.spec.tsx
+++ b/apps/client/src/widgets/react/Modal.spec.tsx
@@ -266,9 +266,22 @@ describe("Modal", () => {
act(() => onResize());
expect(dialog?.classList).toContain("modal-dialog-tall");
+ // Going tall widens the dialog, which can rewrap it a little shorter.
+ height = 380;
+ act(() => onResize());
+ expect(dialog?.classList).toContain("modal-dialog-tall");
+
height = 300;
act(() => onResize());
expect(dialog?.classList).not.toContain("modal-dialog-tall");
+
+ // The screen can change height without the dialog changing size.
+ height = 380;
+ act(() => onResize());
+ expect(dialog?.classList).not.toContain("modal-dialog-tall");
+ vi.stubGlobal("innerHeight", 700);
+ act(() => { window.dispatchEvent(new Event("resize")); });
+ expect(dialog?.classList).toContain("modal-dialog-tall");
vi.unstubAllGlobals();
});
diff --git a/apps/client/src/widgets/react/Modal.tsx b/apps/client/src/widgets/react/Modal.tsx
index 7d91c22867..6e51e27056 100644
--- a/apps/client/src/widgets/react/Modal.tsx
+++ b/apps/client/src/widgets/react/Modal.tsx
@@ -349,16 +349,22 @@ export function ScriptModal(props: ModalProps) {
/**
* Whether the dialog takes up more than half the screen. iOS shows such a dialog as an opaque sheet
- * attached to the screen's edges, and a shorter one as a floating glass sheet.
+ * attached to the screen's edges, and a shorter one as a floating glass sheet. A tall dialog turns
+ * short again only below 45%, since the wider tall sheet can rewrap its content a little shorter.
*/
function useIsTallerThanHalfScreen(dialog: HTMLElement | null) {
const [ isTall, setIsTall ] = useState(false);
useEffect(() => {
if (!dialog) return;
- const observer = new ResizeObserver(() => setIsTall(dialog.offsetHeight > window.innerHeight / 2));
+ const update = () => setIsTall((wasTall) => dialog.offsetHeight > window.innerHeight * (wasTall ? 0.45 : 0.5));
+ const observer = new ResizeObserver(update);
observer.observe(dialog);
- return () => observer.disconnect();
+ window.addEventListener("resize", update);
+ return () => {
+ observer.disconnect();
+ window.removeEventListener("resize", update);
+ };
}, [ dialog ]);
return isTall;