Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug/5758 auto adjust scrollable bug #122

Merged
merged 2 commits into from
Aug 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/pages/detail-page/subpages/tab-panels/NavigatablePanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const PANEL_VISIBLE_HEIGHT = 1480;

// the delay milliseconds for resizing the panel after scrolling. May change in
// the future if users feel it is too slow / too fast.
const RESIZE_DELAY = 400;
const RESIZE_DELAY = 300;

const DEBOUNCE_DELAY = 100;

Expand Down Expand Up @@ -53,7 +53,7 @@ const NavigatablePanel: React.FC<NavigatablePanelProps> = ({
}, [scrollDistance]);

// For better scrolling animation, resizing happens after scrolling
const lateResize = useCallback((toReSize: number) => {
const laybackDeductSize = useCallback((toReSize: number) => {
setTimeout(() => {
setSupplimentaryHeight((prevHeight) => prevHeight + toReSize);
}, RESIZE_DELAY);
Expand All @@ -79,10 +79,14 @@ const NavigatablePanel: React.FC<NavigatablePanelProps> = ({
useEffect(() => {
debounceScrollHandler.current = _.debounce((scrollPosition: number) => {
setPosition(scrollPosition);
const differenceInPosition = scrollPosition - position;
if (differenceInPosition < 0) {
laybackDeductSize(differenceInPosition);
}
}, DEBOUNCE_DELAY);

return () => debounceScrollHandler.current?.cancel();
}, []);
}, [laybackDeductSize, position]);

const handleScroll = (event: React.UIEvent<HTMLDivElement, UIEvent>) => {
const scrollPosition = event.currentTarget.scrollTop;
Expand Down Expand Up @@ -158,7 +162,7 @@ const NavigatablePanel: React.FC<NavigatablePanelProps> = ({
if (neededHeight >= 0) {
setSupplimentaryHeight((prevHeight) => prevHeight + neededHeight);
} else {
lateResize(neededHeight);
laybackDeductSize(neededHeight);
}
setScrollDistance(targetPosition);
};
Expand Down
Loading