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 an issue with comment scrolling offset #1639

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
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
Fix an issue with comment scrolling offset
  • Loading branch information
micahmo committed Dec 13, 2024
commit bf3e2e4b46e807bf0d994e9ea64ccf81a376275e
3 changes: 3 additions & 0 deletions lib/post/pages/legacy_post_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 99,8 @@ class _PostPageState extends State<PostPage> {
final theme = Theme.of(context);
final ThunderState thunderState = context.watch<ThunderBloc>().state;
final AppLocalizations l10n = AppLocalizations.of(context)!;
final double statusBarHeight = MediaQuery.of(context).padding.top;

enableFab = thunderState.enablePostsFab;

bool enableBackToTop = thunderState.postFabEnableBackToTop;
Expand Down Expand Up @@ -267,6 269,7 @@ class _PostPageState extends State<PostPage> {
maxIndex: state.comments.length,
scrollController: _scrollController,
listController: _listController,
statusBarHeight: thunderState.hideTopBarOnScroll ? statusBarHeight : 0,
),
),
),
Expand Down
2 changes: 2 additions & 0 deletions lib/post/pages/post_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 113,7 @@ class _PostPageState extends State<PostPage> {
final theme = Theme.of(context);
final l10n = AppLocalizations.of(context)!;
final thunderState = context.read<ThunderBloc>().state;
final double statusBarHeight = MediaQuery.of(context).padding.top;

originalUser ??= context.read<AuthBloc>().state.account;

Expand Down Expand Up @@ -155,6 156,7 @@ class _PostPageState extends State<PostPage> {
scrollController: scrollController,
listController: listController,
comments: flattenedComments,
statusBarHeight: thunderState.hideTopBarOnScroll ? statusBarHeight : 0,
),
),
),
Expand Down
28 changes: 24 additions & 4 deletions lib/shared/comment_navigator_fab.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 21,17 @@ class CommentNavigatorFab extends StatefulWidget {
/// The maximum index that can be scrolled to
final int maxIndex;

/// The height of the OS status bar, needed to calculate an offset for scrolling comments to the top
final double statusBarHeight;

const CommentNavigatorFab({
super.key,
this.initialIndex = 0,
this.maxIndex = 0,
required this.scrollController,
required this.listController,
this.comments,
required this.statusBarHeight,
});

@override
Expand Down Expand Up @@ -130,10 134,14 @@ class _CommentNavigatorFabState extends State<CommentNavigatorFab> {

setState(() => currentIndex = previousIndex);

// Calculate alignment
final double screenHeight = MediaQuery.of(context).size.height;
final double alignmentOffset = widget.statusBarHeight / screenHeight;

widget.listController.animateToItem(
index: previousIndex,
scrollController: widget.scrollController,
alignment: 0,
alignment: alignmentOffset,
duration: (estimatedDistance) => const Duration(milliseconds: 450),
curve: (estimatedDistance) => Curves.easeInOutCubicEmphasized,
);
Expand Down Expand Up @@ -169,10 177,14 @@ class _CommentNavigatorFabState extends State<CommentNavigatorFab> {

setState(() => currentIndex = parentCommentIndex);

// Calculate alignment
final double screenHeight = MediaQuery.of(context).size.height;
final double alignmentOffset = widget.statusBarHeight / screenHeight;

widget.listController.animateToItem(
index: parentCommentIndex,
scrollController: widget.scrollController,
alignment: 0,
alignment: alignmentOffset,
duration: (estimatedDistance) => const Duration(milliseconds: 450),
curve: (estimatedDistance) => Curves.easeInOutCubicEmphasized,
);
Expand All @@ -186,10 198,14 @@ class _CommentNavigatorFabState extends State<CommentNavigatorFab> {

setState(() => currentIndex = nextIndex);

// Calculate alignment
final double screenHeight = MediaQuery.of(context).size.height;
final double alignmentOffset = widget.statusBarHeight / screenHeight;

widget.listController.animateToItem(
index: nextIndex,
scrollController: widget.scrollController,
alignment: 0,
alignment: alignmentOffset,
duration: (estimatedDistance) => const Duration(milliseconds: 450),
curve: (estimatedDistance) => Curves.easeInOutCubicEmphasized,
);
Expand Down Expand Up @@ -224,10 240,14 @@ class _CommentNavigatorFabState extends State<CommentNavigatorFab> {

setState(() => currentIndex = parentCommentIndex);

// Calculate alignment
final double screenHeight = MediaQuery.of(context).size.height;
final double alignmentOffset = widget.statusBarHeight / screenHeight;

widget.listController.animateToItem(
index: parentCommentIndex,
scrollController: widget.scrollController,
alignment: 0,
alignment: alignmentOffset,
duration: (estimatedDistance) => const Duration(milliseconds: 450),
curve: (estimatedDistance) => Curves.easeInOutCubicEmphasized,
);
Expand Down
Loading