From 677dce97217666332e72590b50e4341d010a27d7 Mon Sep 17 00:00:00 2001 From: Fedor Katurov Date: Mon, 26 Oct 2020 11:47:22 +0700 Subject: [PATCH] fixed some scroll issues --- src/containers/flow/FlowLayout/index.tsx | 6 ++++++ src/containers/main/MainRouter/index.tsx | 25 ++++++++++++++---------- src/containers/node/NodeLayout/index.tsx | 4 ++++ 3 files changed, 25 insertions(+), 10 deletions(-) diff --git a/src/containers/flow/FlowLayout/index.tsx b/src/containers/flow/FlowLayout/index.tsx index ed92ea74..a694776e 100644 --- a/src/containers/flow/FlowLayout/index.tsx +++ b/src/containers/flow/FlowLayout/index.tsx @@ -36,6 +36,8 @@ const FlowLayoutUnconnected: FC = ({ flowLoadMoreSearch, }) => { const onLoadMore = useCallback(() => { + (window as any).flowScrollPos = window.scrollY; + const pos = window.scrollY + window.innerHeight - document.body.scrollHeight; if (is_loading || pos < -600) return; @@ -54,6 +56,10 @@ const FlowLayoutUnconnected: FC = ({ return () => window.removeEventListener('scroll', onLoadMore); }, [onLoadMore]); + useEffect(() => { + window.scrollTo(0, (window as any).flowScrollPos || 0); + }, []); + return (
diff --git a/src/containers/main/MainRouter/index.tsx b/src/containers/main/MainRouter/index.tsx index 13f6d7ad..c0098b21 100644 --- a/src/containers/main/MainRouter/index.tsx +++ b/src/containers/main/MainRouter/index.tsx @@ -15,17 +15,22 @@ const MainRouter: FC = () => { return ( - - - - - - - + { + // disabled for scroll restoration + // + } + + + + + + - - - + + + { + // + } ); }; diff --git a/src/containers/node/NodeLayout/index.tsx b/src/containers/node/NodeLayout/index.tsx index 0418f42f..1e6d7ec0 100644 --- a/src/containers/node/NodeLayout/index.tsx +++ b/src/containers/node/NodeLayout/index.tsx @@ -134,6 +134,10 @@ const NodeLayoutUnconnected: FC = memo( return () => nodeSetCoverImage(null); }, [nodeSetCoverImage, node.cover]); + useEffect(() => { + window.scrollTo(0, 0); + }, [id]); + return ( <> {createNodeBlock(head)}