From 28581a39573273bef4b1135f1a617f4a8138ba97 Mon Sep 17 00:00:00 2001 From: Alex Andreev Date: Wed, 23 Dec 2020 10:19:00 +0300 Subject: [PATCH] Avoid autoscrolling while user is scrolling Signed-off-by: Alex Andreev --- src/renderer/components/dock/pod-log-list.tsx | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/renderer/components/dock/pod-log-list.tsx b/src/renderer/components/dock/pod-log-list.tsx index 60bd1a1050..3d17c61f13 100644 --- a/src/renderer/components/dock/pod-log-list.tsx +++ b/src/renderer/components/dock/pod-log-list.tsx @@ -47,11 +47,13 @@ export class PodLogList extends React.Component { return; } + if (logs == prevProps.logs || !this.virtualListDiv.current) return; + const newLogsLoaded = prevProps.logs.length < logs.length; const scrolledToBeginning = this.virtualListDiv.current.scrollTop === 0; - if (this.isLastLineVisible) { + if (this.isLastLineVisible || prevProps.logs.length == 0) { this.scrollToBottom(); // Scroll down to keep user watching/reading experience return; @@ -129,7 +131,6 @@ export class PodLogList extends React.Component { @action scrollToBottom = () => { if (!this.virtualListDiv.current) return; - this.isJumpButtonVisible = false; this.virtualListDiv.current.scrollTop = this.virtualListDiv.current.scrollHeight; }; @@ -137,7 +138,13 @@ export class PodLogList extends React.Component { this.virtualListRef.current.scrollToItem(index, align); }; - onScroll = debounce((props: ListOnScrollProps) => { + onScroll = (props: ListOnScrollProps) => { + if (!this.virtualListDiv.current) return; + this.isLastLineVisible = false; + this.onScrollDebounced(props); + }; + + onScrollDebounced = debounce((props: ListOnScrollProps) => { if (!this.virtualListDiv.current) return; this.setButtonVisibility(props); this.setLastLineVisibility(props);