Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit a49b510

Browse files
authored
Merge pull request #4914 from matrix-org/travis/room-list/perf/anim-frame-headers
Try using requestAnimationFrame if available for sticky headers
2 parents 652b443 + baccabe commit a49b510

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/components/structures/LeftPanel2.tsx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ export default class LeftPanel2 extends React.Component<IProps, IState> {
6969
private listContainerRef: React.RefObject<HTMLDivElement> = createRef();
7070
private tagPanelWatcherRef: string;
7171
private focusedElement = null;
72+
private isDoingStickyHeaders = false;
7273

7374
constructor(props: IProps) {
7475
super(props);
@@ -113,6 +114,23 @@ export default class LeftPanel2 extends React.Component<IProps, IState> {
113114
};
114115

115116
private handleStickyHeaders(list: HTMLDivElement) {
117+
// TODO: Evaluate if this has any performance benefit or detriment.
118+
// See https://github.com/vector-im/riot-web/issues/14035
119+
120+
if (this.isDoingStickyHeaders) return;
121+
this.isDoingStickyHeaders = true;
122+
if (window.requestAnimationFrame) {
123+
window.requestAnimationFrame(() => {
124+
this.doStickyHeaders(list);
125+
this.isDoingStickyHeaders = false;
126+
});
127+
} else {
128+
this.doStickyHeaders(list);
129+
this.isDoingStickyHeaders = false;
130+
}
131+
}
132+
133+
private doStickyHeaders(list: HTMLDivElement) {
116134
const rlRect = list.getBoundingClientRect();
117135
const bottom = rlRect.bottom;
118136
const top = rlRect.top;

0 commit comments

Comments
 (0)