Skip to content

Commit

Permalink
appbar out of sync check animating is finished
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffGreiner-eaton committed Feb 22, 2024
1 parent f47f62b commit cd31838
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();

Check warning on line 277 in components/src/core/AppBar/AppBar.tsx

View check run for this annotation

Codecov / codecov/patch

components/src/core/AppBar/AppBar.tsx#L276-L277

Added lines #L276 - L277 were not covered by tests
}
}, [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 cd31838

Please sign in to comment.