Skip to content

Commit

Permalink
Merge pull request #858 from etn-ccis/bug/blui-5306-sync-appbar
Browse files Browse the repository at this point in the history
appbar out of sync check animating is finished
  • Loading branch information
surajeaton authored Feb 27, 2024
2 parents c42e58d + cd31838 commit 21fee0a
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions components/src/core/AppBar/AppBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -161,15 +161,16 @@ const AppBarRender: React.ForwardRefRenderFunction<unknown, AppBarProps> = (prop
const previousExpandedHeight = usePrevious(expandedHeight);
const [scrolling, setScrolling] = useState(false);
const [animating, setAnimating] = useState(false);
const previousAnimating = usePrevious(animating);
const [endScrollHandled, setEndScrollHandled] = useState(false);
const [height, setHeight] = useState(
variant === 'collapsed'
? collapsedHeight
: variant === 'expanded'
? expandedHeight
: scrollTop > scrollThreshold
? collapsedHeight
: expandedHeight
? expandedHeight
: scrollTop > scrollThreshold
? collapsedHeight
: expandedHeight
);
const isExpanded = height === expandedHeight;

Expand Down Expand Up @@ -267,7 +268,15 @@ const AppBarRender: React.ForwardRefRenderFunction<unknown, AppBarProps> = (prop
setOffset(scrollTop);
setEndScrollHandled(true);
}
}, [scrolling, animating, offset, endScrollHandled]);
}, [scrolling, offset, endScrollHandled]);

// listen for animating to finish and update scroll position
useEffect(() => {
if (previousAnimating && !animating) {
setEndScrollHandled(false);
handleScroll();
}
}, [previousAnimating, animating, handleScroll]);

// This function listens for scroll events on the window and sets the scrolling variable to true
useEffect(() => {
Expand Down

0 comments on commit 21fee0a

Please sign in to comment.