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

Fix partial comment navigation #1366

Merged
merged 1 commit into from
May 15, 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
26 changes: 18 additions & 8 deletions lib/shared/comment_navigator_fab.dart
Original file line number Diff line number Diff line change
Expand Up @@ -114,34 +114,44 @@ class _CommentNavigatorFabState extends State<CommentNavigatorFab> {
}

void navigateUp() {
if (currentIndex == 0) return;
var unobstructedVisibleRange = widget.listController.unobstructedVisibleRange;

int nextIndex = currentIndex - 1;
if (unobstructedVisibleRange?.$1 != null && unobstructedVisibleRange!.$1 != currentIndex) {
nextIndex = unobstructedVisibleRange.$1;
} else if (currentIndex != 0) {
nextIndex = unobstructedVisibleRange!.$1 - 1;
}

widget.listController.animateToItem(
index: currentIndex - 1,
index: nextIndex,
scrollController: widget.scrollController,
alignment: 0,
duration: (estimatedDistance) => const Duration(milliseconds: 250),
duration: (estimatedDistance) => const Duration(milliseconds: 450),
curve: (estimatedDistance) => Curves.easeInOutCubicEmphasized,
);

setState(() {
currentIndex = currentIndex - 1;
currentIndex = nextIndex;
});
}

void navigateDown() {
if (currentIndex == widget.maxIndex) return;
var unobstructedVisibleRange = widget.listController.unobstructedVisibleRange;

int nextIndex = currentIndex + 1;
if (unobstructedVisibleRange?.$1 != null) nextIndex = unobstructedVisibleRange!.$1 + 1;

widget.listController.animateToItem(
index: currentIndex + 1,
index: nextIndex,
scrollController: widget.scrollController,
alignment: 0,
duration: (estimatedDistance) => const Duration(milliseconds: 250),
duration: (estimatedDistance) => const Duration(milliseconds: 450),
curve: (estimatedDistance) => Curves.easeInOutCubicEmphasized,
);

setState(() {
currentIndex = currentIndex + 1;
currentIndex = nextIndex;
});
}
}
Loading