fix(v2): reinit hideable header position when page switched (#2160)

* fix(v2): reinit hideable header position when page switched

* fix(v2): fix CI

* refactor(v2): use react-router-dom hook instead plugin API
This commit is contained in:
Alexey Pyltsyn 2020-01-03 06:04:15 +03:00 committed by Yangshun Tay
parent c494e93564
commit de57ab1b7d
3 changed files with 161 additions and 0 deletions

View file

@ -6,6 +6,7 @@
*/
import {useState, useCallback, useEffect} from 'react';
import {useLocation} from 'react-router-dom';
const useHideableNavbar = hideOnScroll => {
const [isNavbarVisible, setIsNavbarVisible] = useState(true);
@ -16,6 +17,7 @@ const useHideableNavbar = hideOnScroll => {
setNavbarHeight(node.getBoundingClientRect().height);
}
}, []);
const location = useLocation();
const handleScroll = () => {
const scrollTop = window.pageYOffset || document.documentElement.scrollTop;
@ -47,6 +49,10 @@ const useHideableNavbar = hideOnScroll => {
};
}, [lastScrollTop, navbarHeight]);
useEffect(() => {
setIsNavbarVisible(true);
}, [location]);
return {
navbarRef,
isNavbarVisible,