Skip to content

Commit

Permalink
fix(v2): reinit hideable header position when page switched (#2160)
Browse files Browse the repository at this point in the history
* fix(v2): reinit hideable header position when page switched

* fix(v2): fix CI

* refactor(v2): use react-router-dom hook instead plugin API
  • Loading branch information
lex111 authored and yangshun committed Jan 3, 2020
1 parent c494e93 commit de57ab1
Show file tree
Hide file tree
Showing 3 changed files with 161 additions and 0 deletions.
154 changes: 154 additions & 0 deletions packages/docusaurus-theme-classic/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/docusaurus-theme-classic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"infima": "0.2.0-alpha.3",
"parse-numeric-range": "^0.0.2",
"prism-react-renderer": "^1.0.2",
"react-router-dom": "^5.1.2",
"react-toggle": "^4.1.1"
},
"peerDependencies": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

import {useState, useCallback, useEffect} from 'react';
import {useLocation} from 'react-router-dom';

const useHideableNavbar = hideOnScroll => {
const [isNavbarVisible, setIsNavbarVisible] = useState(true);
Expand All @@ -16,6 +17,7 @@ const useHideableNavbar = hideOnScroll => {
setNavbarHeight(node.getBoundingClientRect().height);
}
}, []);
const location = useLocation();

const handleScroll = () => {
const scrollTop = window.pageYOffset || document.documentElement.scrollTop;
Expand Down Expand Up @@ -47,6 +49,10 @@ const useHideableNavbar = hideOnScroll => {
};
}, [lastScrollTop, navbarHeight]);

useEffect(() => {
setIsNavbarVisible(true);
}, [location]);

return {
navbarRef,
isNavbarVisible,
Expand Down

0 comments on commit de57ab1

Please sign in to comment.