Skip to content

Commit

Permalink
Merge pull request #679 from pangeachat/handle-header-overflow
Browse files Browse the repository at this point in the history
added header height to overflow calculations when scrolling overlay t…
  • Loading branch information
ggurdin authored Sep 13, 2024
2 parents ee70ccb + a40c86a commit 82c95e4
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions lib/pangea/widgets/chat/message_selection_overlay.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class MessageSelectionOverlayState extends State<MessageSelectionOverlay>
screenHeight - messageOffset!.dy - messageSize!.height;

final bool hasHeaderOverflow =
messageOffset!.dy < AppConfig.toolbarMaxHeight;
messageOffset!.dy < (AppConfig.toolbarMaxHeight + headerHeight);
final bool hasFooterOverflow = footerHeight > currentBottomOffset;

if (!hasHeaderOverflow && !hasFooterOverflow) return;
Expand All @@ -75,19 +75,27 @@ class MessageSelectionOverlayState extends State<MessageSelectionOverlay>
double animationEndOffset = 0;

final midpoint = (headerBottomOffset + footerBottomOffset) / 2;
if (hasHeaderOverflow) {

// if the overlay would have a footer overflow for this message,
// check if shifting the overlay up could cause a header overflow
final bottomOffsetDifference = footerHeight - currentBottomOffset;
final newTopOffset = messageOffset!.dy - bottomOffsetDifference;
final bool upshiftCausesHeaderOverflow = hasFooterOverflow &&
newTopOffset < (headerHeight + AppConfig.toolbarMaxHeight);

if (hasHeaderOverflow || upshiftCausesHeaderOverflow) {
animationEndOffset = midpoint - messageSize!.height;
final totalTopOffset =
animationEndOffset + messageSize!.height + AppConfig.toolbarMaxHeight;
final remainingSpace = screenHeight - totalTopOffset;
if (remainingSpace < headerHeight) {
// the overlay could run over the header, so it needs to be shifted down
animationEndOffset -= (headerHeight - remainingSpace);
}
scrollOffset = animationEndOffset - currentBottomOffset;
} else if (hasFooterOverflow) {
scrollOffset = footerHeight - currentBottomOffset;
animationEndOffset = footerHeight;

final bottomOffsetDifference = footerHeight - currentBottomOffset;
final newTopOffset = messageOffset!.dy - bottomOffsetDifference;
if (newTopOffset < (headerHeight + AppConfig.toolbarMaxHeight)) {
animationEndOffset = midpoint - messageSize!.height;
scrollOffset = animationEndOffset - currentBottomOffset;
}
}

_overlayPositionAnimation = Tween<double>(
Expand Down

0 comments on commit 82c95e4

Please sign in to comment.