BottomSheet icon indicating copy to clipboard operation
BottomSheet copied to clipboard

Snapping issues when reloading the tableView

Open sergeysmagleev opened this issue 7 years ago • 1 comments

Hello Simon! Nice repo, it's working great and I like it. I've been using the same approach in one of the projects I've been working on and it turns out that there's one problem I'd like to talk to you about. This solution works very well as the tableView is static. However, if you have to reload the tableView at some point during the scrolling animation, it can lead to unexpected visual bugs. In order to reproduce the issue, the following conditions should be met:

  1. The data in the tableView should change (i.e. set a different number of rows)
  2. reloadData should be called during the scrolling animation

As the result, one of the following can happen:

  1. (rare) tableView stops scrolling and its contentOffset is stuck in between the two snapping points;
  2. (common) tableView abruptly jumps back to its previous position or to zero offset

Here it is visualized: bug 1 bug 2

The obvious solution that comes to mind is to defer the reloading until the moment the scrolling is finished, e.g. call reloadData at scrollViewDidEndDecelerating or scrollViewDidEndScrollingAnimation, but I've tried this and it still won't work.

I would like to know if you have any ideas on this topic.

Cheers!

sergeysmagleev avatar Aug 28 '18 15:08 sergeysmagleev

Hey, thanks a lot for this well written issue! Sorry for not getting back sooner. I unfortunately don't have any suggestions at this time. In the app where I used this technique, we had no need to reload the data. The only idea I can think of is what you already wrote, to wait for did end decelerating or similar. Weird that it doesn't work.

I hope to get around writing a follow-up blog post at some point and mention problems with this approach, I'll be sure to mention this then.

skagedal avatar Sep 06 '18 08:09 skagedal