Skip to content

Commit b6a8f38

Browse files
committed
fix(ObjectPage): support height change of pinned header
1 parent 3b89dfd commit b6a8f38

File tree

1 file changed

+10
-14
lines changed

1 file changed

+10
-14
lines changed

packages/main/src/internal/useObserveHeights.ts

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,10 @@ export const useObserveHeights = (
6666

6767
// top header
6868
useEffect(() => {
69-
const headerContentResizeObserver = new ResizeObserver(([header]) => {
70-
// Firefox implements `borderBoxSize` as a single content rect, rather than an array
71-
const borderBoxSize = Array.isArray(header.borderBoxSize) ? header.borderBoxSize[0] : header.borderBoxSize;
72-
// Safari doesn't implement `borderBoxSize`
73-
setTopHeaderHeight(borderBoxSize?.blockSize ?? header.target.getBoundingClientRect().height);
69+
const headerContentResizeObserver = new ResizeObserver(([entry]) => {
70+
const { blockSize } = entry.borderBoxSize[0];
71+
console.log('a');
72+
setTopHeaderHeight(blockSize);
7473
});
7574
if (topHeaderRef?.current) {
7675
headerContentResizeObserver.observe(topHeaderRef.current);
@@ -82,14 +81,11 @@ export const useObserveHeights = (
8281

8382
// header content
8483
useEffect(() => {
85-
const headerContentResizeObserver = new ResizeObserver(([headerContent]) => {
86-
if (isIntersecting) {
87-
// Firefox implements `borderBoxSize` as a single content rect, rather than an array
88-
const borderBoxSize = Array.isArray(headerContent.borderBoxSize)
89-
? headerContent.borderBoxSize[0]
90-
: headerContent.borderBoxSize;
91-
// Safari doesn't implement `borderBoxSize`
92-
setHeaderContentHeight(borderBoxSize?.blockSize ?? headerContent.target.getBoundingClientRect().height);
84+
const headerContentResizeObserver = new ResizeObserver(([entry]) => {
85+
if (isIntersecting || fixedHeader) {
86+
const { blockSize } = entry.borderBoxSize[0];
87+
console.log('b');
88+
setHeaderContentHeight(blockSize);
9389
}
9490
});
9591

@@ -99,7 +95,7 @@ export const useObserveHeights = (
9995
return () => {
10096
headerContentResizeObserver.disconnect();
10197
};
102-
}, [isIntersecting]);
98+
}, [isIntersecting, fixedHeader]);
10399
const totalHeaderHeight = noHeader ? 0 : topHeaderHeight + headerContentHeight;
104100

105101
return { topHeaderHeight, headerContentHeight, totalHeaderHeight, headerCollapsed };

0 commit comments

Comments
 (0)