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

[BUG] [Mobile] [Web] Jump to the bottom of next page when scrolling forward #1634

Open
Te-Z opened this issue Mar 27, 2024 · 3 comments
Open
Assignees

Comments

@Te-Z
Copy link
Contributor

Te-Z commented Mar 27, 2024

Reproduce steps:

  • In a room, jump to a pinned message or to the last unread message
  • Scroll forward
  • load next page

Actual:

Jump to the bottom of next page, so the user has to scroll backward to continue where he left

Expected:

Next page loads without moving the scroll position

Capture.video.du.27-03-2024.06.41.10.webm
screen-20240327-070619.mp4
@Te-Z
Copy link
Contributor Author

Te-Z commented Apr 15, 2024

The problem is we need to know the position (in px) of the item at index 0 before scrolling forward. This way when new items will be inserted starting from this index, the UI won't move.

I tried with infinite_pagination_list (#1681) but couldn't achieve to load correctly the data. But I have a functional POC: https://github.com/Te-Z/flutter_biderectional_pagination .

Solution found here: EdsonBueno/infinite_scroll_pagination#56 (comment)

@Te-Z
Copy link
Contributor Author

Te-Z commented Apr 15, 2024

I also tried with a custom scroll physic, but I'm struggling a bit to find the good way to calculate the good position to keep since every item can have a different size.

See this branch: https://github.com/linagora/twake-on-matrix/tree/TW-1634/custom_scroll_physics

import 'package:flutter/material.dart';

class PositionRetainedScrollPhysics extends ScrollPhysics {
  final bool shouldRetain;
  const PositionRetainedScrollPhysics(
      {ScrollPhysics? parent, this.shouldRetain = true})
      : super(parent: parent);

  @override
  PositionRetainedScrollPhysics applyTo(ScrollPhysics? ancestor) {
    return PositionRetainedScrollPhysics(
      parent: buildParent(ancestor),
      shouldRetain: shouldRetain,
    );
  }

  @override
  double adjustPositionForNewDimensions({
    required ScrollMetrics oldPosition,
    required ScrollMetrics newPosition,
    required bool isScrolling,
    required double velocity,
  }) {
    final position = super.adjustPositionForNewDimensions(
      oldPosition: oldPosition,
      newPosition: newPosition,
      isScrolling: isScrolling,
      velocity: velocity,
    );

    final diff = newPosition.maxScrollExtent - oldPosition.maxScrollExtent;
    if (oldPosition.pixels == 0 && newPosition.pixels == 0) {
      if (newPosition.maxScrollExtent > oldPosition.maxScrollExtent &&
          diff > 0 &&
          shouldRetain) {
        return diff;
      } else {
        return position;
      }
    } else {
      return position;
    }
  }
}

@Te-Z
Copy link
Contributor Author

Te-Z commented Apr 15, 2024

removing this ticket from In Progresscolumn for now since no solutions worked at the moment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant