From ced20390eb7efcc36443f5037a1698778892576a Mon Sep 17 00:00:00 2001 From: Tanner Collin Date: Sat, 4 Jan 2020 23:36:24 +0000 Subject: [PATCH] Fix back/forward scroll jump issue --- webclient/src/ScrollToTop.js | 13 +++++++++++-- webclient/src/Style-light.css | 1 + webclient/src/utils.js | 14 ++++++++++---- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/webclient/src/ScrollToTop.js b/webclient/src/ScrollToTop.js index 0dade11..dd4e735 100644 --- a/webclient/src/ScrollToTop.js +++ b/webclient/src/ScrollToTop.js @@ -3,9 +3,18 @@ import { withRouter } from 'react-router-dom'; class ScrollToTop extends React.Component { componentDidUpdate(prevProps) { - if (this.props.location.pathname !== prevProps.location.pathname) { - window.scrollTo(0, 0); + //console.log(this.props.location.pathname, prevProps.location.pathname); + + if (this.props.location.pathname === prevProps.location.pathname) { + return; } + + if (localStorage.getItem('scrollLock') === 'True') { + localStorage.setItem('scrollLock', 'False'); + return; + } + + window.scrollTo(0, 0); } render() { diff --git a/webclient/src/Style-light.css b/webclient/src/Style-light.css index 98d61c4..6d53516 100644 --- a/webclient/src/Style-light.css +++ b/webclient/src/Style-light.css @@ -181,6 +181,7 @@ span.source { } .forwardDot { + cursor: pointer; position: fixed; bottom: 1rem; right: 1rem; diff --git a/webclient/src/utils.js b/webclient/src/utils.js index e0dc2f2..a81aa29 100644 --- a/webclient/src/utils.js +++ b/webclient/src/utils.js @@ -38,13 +38,19 @@ export class ToggleDot extends React.Component { } export class ForwardDot extends React.Component { + goForward() { + localStorage.setItem('scrollLock', 'True'); + window.history.forward(); + } + render() { + const isMobile = /iPhone|iPad|iPod|Android/i.test(navigator.userAgent); + if (!isMobile) return null; + return ( -
+
- window.history.forward()}> -  - + 
);