Skip to content

Commit

Permalink
Slightly simpler scrollTo logic for foldable components. (#7345)
Browse files Browse the repository at this point in the history
  • Loading branch information
isoos authored Jan 5, 2024
1 parent 9dc0a4a commit 21fce19
Showing 1 changed file with 3 additions and 10 deletions.
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

0 comments on commit 21fce19

Please sign in to comment.