Skip to content

Commit 470fb5d

Browse files
authored
ENG-1766 Fix suggestive mode reflow on first panel open and close (#1049)
* ENG-1766 Fix suggestive mode reflow on first panel open and close Two fixes for the visible width animation when toggling the suggestive mode sidebar at small/medium/large spacing modes: - Use useLayoutEffect for setupSplitView so the flex layout and article wrapper width override land before the browser paints. Avoids the intermediate frame where the panel sits as a block sibling and the wrapper is at default width. - Suppress CSS transitions on .rm-article-wrapper during setup and teardown via a new applyWithoutTransition helper, then restore on the next frame. Roam's stylesheet animates padding/max-width on spacing changes; the same transition fired when we wrote our overrides. Also adds a 1.5rem gap on .roam-body-main so the wrapper does not butt against the panel. * Use tailwind classes for split-view flex/gap
1 parent 56a53fb commit 470fb5d

2 files changed

Lines changed: 39 additions & 9 deletions

File tree

apps/roam/src/components/PanelManager.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
import React, { useEffect, useState, useRef, useCallback } from "react";
1+
import React, {
2+
useEffect,
3+
useLayoutEffect,
4+
useState,
5+
useRef,
6+
useCallback,
7+
} from "react";
28
import ReactDOM from "react-dom";
39
import { Navbar, Alignment, Button } from "@blueprintjs/core";
410
import { OnloadArgs } from "roamjs-components/types/native";
@@ -94,7 +100,7 @@ export const PanelContainer = (): React.ReactElement => {
94100

95101
const [isMinimized, setIsMinimized] = useState(getGlobalIsMinimized());
96102

97-
useEffect(() => {
103+
useLayoutEffect(() => {
98104
const { roamBodyMain, articleWrapper } = getRoamElements();
99105

100106
if (roamBodyMain && articleWrapper && containerRef.current) {

apps/roam/src/utils/suggestiveModeSidebarSizing.ts

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,35 @@ export const cleanupArticleWrapperObserver = (): void => {
8484
articleWrapperObserver = null;
8585
}
8686
};
87+
const applyWithoutTransition = (
88+
element: HTMLElement,
89+
apply: () => void,
90+
): void => {
91+
const previousValue = element.style.getPropertyValue("transition");
92+
const previousPriority = element.style.getPropertyPriority("transition");
93+
element.style.setProperty("transition", "none", "important");
94+
95+
apply();
96+
97+
requestAnimationFrame(() => {
98+
if (previousValue) {
99+
element.style.setProperty("transition", previousValue, previousPriority);
100+
} else {
101+
element.style.removeProperty("transition");
102+
}
103+
});
104+
};
105+
87106
export const setupSplitView = (
88107
roamBodyMain: HTMLElement,
89108
articleWrapper: HTMLElement,
90109
): void => {
91-
roamBodyMain.style.display = "flex";
92-
roamBodyMain.dataset.isSplit = "true";
93-
updateArticleWrapperPadding(articleWrapper);
110+
applyWithoutTransition(articleWrapper, () => {
111+
roamBodyMain.classList.add("flex", "gap-6");
112+
roamBodyMain.dataset.isSplit = "true";
113+
updateArticleWrapperPadding(articleWrapper);
114+
});
115+
94116
cleanupArticleWrapperObserver();
95117
initializeArticleWrapperObserver();
96118
};
@@ -99,8 +121,10 @@ export const teardownSplitView = (
99121
roamBodyMain: HTMLElement,
100122
articleWrapper: HTMLElement,
101123
): void => {
102-
roamBodyMain.removeAttribute("data-is-split");
103-
roamBodyMain.style.display = "";
104-
articleWrapper.style.flex = "";
105-
resetArticleWrapperPadding(articleWrapper);
124+
applyWithoutTransition(articleWrapper, () => {
125+
roamBodyMain.removeAttribute("data-is-split");
126+
roamBodyMain.classList.remove("flex", "gap-6");
127+
articleWrapper.style.flex = "";
128+
resetArticleWrapperPadding(articleWrapper);
129+
});
106130
};

0 commit comments

Comments
 (0)