File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -29,18 +29,27 @@ const useMediaQuery = (query: string) => {
2929 return matches ;
3030} ;
3131
32+ const STICKY_THRESHOLD = 80 ;
33+
3234export const Overview = ( pr : PullRequest ) => {
3335 const isSingleColumnLayout = useMediaQuery ( '(max-width: 768px)' ) ;
3436 const [ isSticky , setIsSticky ] = React . useState ( false ) ;
3537
3638 React . useEffect ( ( ) => {
39+ let ticking = false ;
40+
3741 const handleScroll = ( ) => {
38- // Make header sticky when scrolled past 80px
39- const scrolled = window . scrollY > 80 ;
40- setIsSticky ( scrolled ) ;
42+ if ( ! ticking ) {
43+ window . requestAnimationFrame ( ( ) => {
44+ const scrolled = window . scrollY > STICKY_THRESHOLD ;
45+ setIsSticky ( scrolled ) ;
46+ ticking = false ;
47+ } ) ;
48+ ticking = true ;
49+ }
4150 } ;
4251
43- window . addEventListener ( 'scroll' , handleScroll ) ;
52+ window . addEventListener ( 'scroll' , handleScroll , { passive : true } ) ;
4453 return ( ) => window . removeEventListener ( 'scroll' , handleScroll ) ;
4554 } , [ ] ) ;
4655
You can’t perform that action at this time.
0 commit comments