Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: feed scroll to top on scroll up (#601)
## Description This issue is related to blocking. When a feed cell is about to be rendered, we watch the provider to check if the author is blocked/blocking to determine if we want to show the cell. The default value inside cell is `true`, so that when the provider is still loading, we don’t show the cell. Later, after the provider is loaded and it returns `false`, we know that the author is not blocked/blocking and we show the cell. Then, when user scrolls through the feed, some of the cells are getting out of the viewport, they are getting disposed of and their block checking provider is getting disposed, because nothing else is listening to it. Now, when user scrolls back, these cells try to render again. Provider was disposed, so it is recreated and starts loading. When it’s loading, we use the default `true` value. This causes the cell to just return an empty SizedBox, so the feed listview sees it has enough space to render the next cell. Then the next cell is not rendering because it’s waiting for it’s provider to load so the listview tries to render the next one. And the cycle continues for all cells up to the top. By the time they are loaded correctly, listview assumes it reached the top of the scroll view, because everything is rendered so it updates it’s scroll metrics. Now after a split second when all these cells are properly rendered because the providers are properly loaded , user stays at the top of the scroll view and all the content is pushed down, giving an impression that the feed was scrolled to the top. The problem here is that the data about wether or not the cell is blocked is disposed each time it gets out of the viewport. We should keep it in memory. There are in my eyes two ways to do that: 1. Make the provider responsible for blocked/blocking checking `keepAlive`, but that could mean a lot of providers alive at the same time, if for example user scrolls through 1k of cells 2. Create a Map<String, bool> with `useState` inside the `EntitiesList` to keep a single map of the ids of entities and their blocked/blocking status and pass it to every cell it builds. This way, when a certain cell builds a second time, it uses the value from the map as an initial value and then after it’s provider is loaded, updates it if needed ## Type of Change - [x] Bug fix - [ ] New feature - [ ] Breaking change - [x] Refactoring - [ ] Documentation - [ ] Chore ## Screenshots (if applicable) <!-- Include screenshots to demonstrate any UI changes. --> <!-- <img width="180" alt="image" src="image_url_here"> -->
- Loading branch information