-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Collectionview infinite scrolling upwards #10269
Comments
We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process. |
@FM1973 You can subscribe to ItemAppearing command of CollectionView which executes for every row displayed when scrolling, detect last item appeared then load more data at zero index |
@FM1973
In android I had to put this renderer:
I hope it works for you. |
@angelru |
I think that the rendering was because in some version of android the scroll did not work well, check the version 8,9 and 10 of android. Then your list has to be sorted backwards just like the group list. |
but how to scroll up? |
I use the 'Loaded' event on the item view from the CollectionView and then check from the codes whether the item is the first one in the collection and if so I load more objects:
|
But you don't scroll up, do you? |
Of course I do scroll up. |
but you have not rotated the CollectionView 180? can you upload a small sample? |
Just created the sample for you :) |
@Engisan Nice solution. I will give it a try. Although I will do this in my viewmodel. Thanks! |
Sure, this one was just a sample, I did not bother with view models etc. I just wanted to show how I do it. Enjoy! :) |
@Engisan Another alternative to rotating the CollectionView! thank you! |
Rotating did not work for me because it rotated the contents as well, so my texts were upside down etc. (.NET 7). I could not rly use it... Did you manage to get it work? |
Yes, I managed to rotate everything. The problem is, this only works on Android and ends up in a ton of calculation exceptions on IOS |
You also have to rotate the list |
@Engisan So I changed my strategy and I am now using the scrolled event of the collectionview (with an EventToCommandBehavior). If the delta and/or the offset are positive I just return and do nothing. Even if the number of messages equals the total number of messages I do nothing. This works pretty well. I can´t understand why I haven´t thought of solving the problem like this before. You guided my to the right track. Thanks @Engisan! |
Better solution than rotated CollectionView right? can you provide a small sample with dummy data? |
@angelru |
@angelru @FM1973 I tried Scrolled event and using vertical delta and the vertical offset as well. |
@FM1973 Well, I did not try that on iOS, not yet. I would expect it to work, the Loaded event should be fired once you get the item into the visible scrolling area (it does not need to happen once you reach the top but once you scroll up so the item is processed by the system) and since it is the first item in the collection, you should be able to trigger new items loading... Weird. But as I said, I did not try that yet on iOS. |
By the way, the Scrolled event also contains property "FirstVisibleItemIndex" so whenever this is 0, it means you are at the top level... this works great on android, I will check the iOS version later. |
In flutter this is what is used:
pixels: current position in pixels |
@Engisan "FirstVisibleItemIndex" is great, but in my tests you get index 0 a couple of times - even when loading the initial data. Even if you got i.e. a property "loading" which is set to true before loading the initial data and to false after loading, it can happen that you get index 0 a couple of times. Therefore I combinded this with vertical delta and the vertical offset. The delta is being used to check in which direction the user scrolls and the offset for checking if the top has been reached, |
@FM1973 maybe it depends on how you initially fill in the ObservableCollection... I just tested the soluition with Scrolled event and handling the FirstVisibleItemIndex and it works the best out of all solutions we had here (in my opinion). It works nicely even in iOS so I will stick with this one for now. |
@Engisan Yes. This may be. How do you fill it initially? I thought about using something like ObervableRangeCollection and adding the initial data using "AddRange". I will test this out. I then would add another function to ObervableRangeCollection. Something like AddRangeAtIndex - so I can add a list of items to index 0 before the property (Collection) notifies the ui that it has changed. There is a known bug though - #7237. You can get around this bug by adding a Task.Delay(xxx) before calling AddRange. |
It would be nice to leave an example of the last used way that works better, thanks! |
@angelru I´m working on it. |
@angelru You will find a small simple sample in the following repo. Just open the repo and try the last button on the main screen ('chat sample'). On Android this works pretty well. On IOS we have to scroll to the last visible message after inserting the new items. If you have any questions, let me know. @Engisan Anything I could do better? |
Nice sample, I see it works well, so do you think this is better than the rotate list/collectionview trick? |
@angelru good question. At least there is no need for Maui to do the rotation calculation. I think we could enhance the sample using the ObservableRangeCollection. If I find time I will enhance the sample using this type of collection. But my vacation is near, so I´m not sure if I will find time to do the enhanced version. At least you can use this version for Android and IOS while the rotation trick doesn´t work on IOS at all. There are a lot of calculation errors on IOS which result in a crash. |
@FM1973 nice, works fine. I do not see anything rly suspicious. And visually it is rly fine. |
@Engisan @FM1973 I haven't tried chat with rotation for a long time, since the app where it implements it doesn't exist. |
Rotate the contents as well |
Description
Collectionview is currenty only working top-down. I mean if you are using infininte scolling, this only works at the end of the list.
We have a "chat-section" in our app. In chat applications the last message is being shown at the bottom of the list an if you scroll up, older messages are being loaded.
Sorry, if this is already possible, we didn´t find a way to do so (except using 3rd party controls).
Public API Changes
Intended Use-Case
We want to use this for a chat application. The last item is being shown at the bottom and if the users scrolls up, older items are being loaded.
The text was updated successfully, but these errors were encountered: