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

Slightly simpler scrollTo logic for foldable components. #7345

Merged
merged 1 commit into from
Jan 5, 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
13 changes: 3 additions & 10 deletions pkg/web_app/lib/src/foldable.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ void _setEventForFoldable() {
return;
}

num scrollDiff = 0;
if (scrollContainer != null) {
// Wait one animation frame before measurements.
await window.animationFrame;
Expand All @@ -50,18 +49,12 @@ void _setEventForFoldable() {
final screenLimit = scrollContainerHeight - buttonHeight;

/// Scroll the smaller amount of the two.
scrollDiff = max(0, min(screenLimit, outsideViewDiff));
final scrollDiff = max(0, min(screenLimit, outsideViewDiff));

/// Do not scroll if the difference is small, otherwise scroll in small
/// steps synchronized to the animation frames.
/// Do not scroll if the difference is small.
if (scrollDiff > 8) {
final originalScrollTop = scrollContainer.scrollTop;
final maxSteps = 20;
for (var i = 1; i <= maxSteps; i++) {
if (i > 1) await window.animationFrame;
final nextPos = originalScrollTop + (scrollDiff * i / maxSteps);
scrollContainer.scrollTo(0, nextPos);
}
scrollContainer.scrollTo(0, originalScrollTop + scrollDiff);
}
}
}
Expand Down