Skip to content

fix(ObjectPage): slightly improve scroll performance #4970

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export const styles = {
},
contentContainer: {
extend: ResponsiveContainerPadding,
paddingTop: '1rem',
paddingBlockStart: '1rem',
boxSizing: 'border-box',
width: '100%',
height: 'auto',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ export const DynamicPageHeaderStyles = {
backgroundColor: ThemingParameters.sapObjectHeader_Background,
position: 'sticky',
zIndex: 1,
paddingTop: '1rem',
paddingBottom: '1rem',
paddingBlockStart: '1rem',
paddingBlockEnd: '1rem',
display: `var(${DynamicPageCssVariables.headerDisplay})`,
overflow: 'hidden'
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ export const DynamicPageTitleStyles = {
flex: '1 1 100%',
backgroundColor: ThemingParameters.sapObjectHeader_Background,
minHeight: '3rem',
paddingTop: '0.5rem',
paddingBottom: '0.5rem',
paddingBlockStart: '0.5rem',
paddingBlockEnd: '0.5rem',
display: 'flex',
flexDirection: 'column',
justifyContent: 'space-between',
Expand Down Expand Up @@ -44,7 +44,7 @@ export const DynamicPageTitleStyles = {
fontFamily: ThemingParameters.sapObjectHeader_Title_FontFamily,
color: ThemingParameters.sapObjectHeader_Title_TextColor,
fontSize: `var(${DynamicPageCssVariables.titleFontSize})`,
paddingTop: '0.3125rem',
paddingBlockStart: '0.3125rem',
overflowWrap: 'break-word',
hyphens: 'auto',
'& > *': {
Expand Down
6 changes: 3 additions & 3 deletions packages/main/src/components/ObjectPage/ObjectPage.jss.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,7 @@ export const styles = {
zIndex: 2,
'& [data-component-name="DynamicPageTitle"]': {
gridColumn: 2,
paddingLeft: 0,
paddingRight: 0
paddingInline: 0
},
cursor: 'pointer'
},
Expand Down Expand Up @@ -136,5 +135,6 @@ export const styles = {
'&::part(content)': {
padding: 0
}
}
},
titleInHeader: { padding: 0 }
};
37 changes: 17 additions & 20 deletions packages/main/src/components/ObjectPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,19 @@ const ObjectPage = forwardRef<HTMLDivElement, ObjectPagePropTypes>((props, ref)
threshold: [0]
}
);
// Fallback when scrolling faster than the IntersectionObserver can observe (in most cases faster than 60fps)

sections.forEach((el) => {
observer.observe(el);
});

return () => {
observer.disconnect();
};
}, [children, totalHeaderHeight, setInternalSelectedSectionId, isProgrammaticallyScrolled]);

// Fallback when scrolling faster than the IntersectionObserver can observe (in most cases faster than 60fps)
useEffect(() => {
const sections = objectPageRef.current?.querySelectorAll('section[data-component-name="ObjectPageSection"]');
if (isAfterScroll) {
let currentSection = sections[sections.length - 1];
let currentIndex;
Expand All @@ -582,22 +594,7 @@ const ObjectPage = forwardRef<HTMLDivElement, ObjectPagePropTypes>((props, ref)
}
setIsAfterScroll(false);
}

sections.forEach((el) => {
observer.observe(el);
});

return () => {
observer.disconnect();
};
}, [
objectPageRef.current,
children,
totalHeaderHeight,
setInternalSelectedSectionId,
isProgrammaticallyScrolled,
isAfterScroll
]);
}, [isAfterScroll]);

const titleHeaderNotClickable =
(alwaysShowContentHeader && !headerContentPinnable) ||
Expand All @@ -616,18 +613,18 @@ const ObjectPage = forwardRef<HTMLDivElement, ObjectPagePropTypes>((props, ref)

const renderTitleSection = useCallback(
(inHeader = false) => {
const titleStyles = { ...(inHeader ? { padding: 0 } : {}), ...(headerTitle?.props?.style ?? {}) };
const titleInHeaderClass = inHeader ? classes.titleInHeader : undefined;

if (headerTitle?.props && headerTitle.props?.showSubHeaderRight === undefined) {
return cloneElement(headerTitle, {
showSubHeaderRight: true,
style: titleStyles,
className: clsx(titleInHeaderClass, headerTitle?.props?.className),
'data-not-clickable': titleHeaderNotClickable,
onToggleHeaderContentVisibility: onTitleClick
});
}
return cloneElement(headerTitle, {
style: titleStyles,
className: clsx(titleInHeaderClass, headerTitle?.props?.className),
'data-not-clickable': titleHeaderNotClickable,
onToggleHeaderContentVisibility: onTitleClick
});
Expand Down