VirtualScroll + InfiniteScroll scrolls top when reaching list bottom
Short description of the problem:
When the bottom of virtual list is reached, infinite scroll is triggered, items are loaded and displayed all ok, but after that the scroll jumps straight to top.
Tested in:
- Opera/Chrome via ionic serve
- Nexus 4 Android 5.1
- Samsung Galaxy S5 Android 5.1
New to Ionic, don't know are they supposed to work together at all? Tried simple ion-list + infiniteScroll and works fine.
What behavior are you expecting?
The scroll should not jump to top when infinite scroll is triggered.
Also you can see an image flicker when scrolling. Don't know how correctly to explain it, but sometimes when u scroll and an image comes in viewport, it displays an image that don't belong to item, after some time, the correct image is displayed, and this change(flicker) is visible.
Which Ionic Version? 2.x
Plunker that shows an example of your issue
http://plnkr.co/edit/jNJBgEqPJlxttsHTRdmR?p=preview
Run ionic info from terminal/cmd prompt: (paste output below)
Cordova CLI: 6.1.1 Gulp version: CLI version 0.4.0 Gulp local: Local version 3.9.1 Ionic Framework Version: 2.0.0-beta.6 Ionic CLI Version: 2.0.0-beta.25 Ionic App Lib Version: 2.0.0-beta.15 OS: Node Version: v4.2.1
Hello! Thanks for opening an issue with us! Virtualscroll is meant to increase scrolling performance with large lists as it only renders enough data to fill the viewport as you scroll. InfiniteScroll allows you to do an action once a user scrolls to the bottom of a list. Most devs normally use this for loading more data once a user scrolls through the page. It is not recommended that you use them together, so that is why you are seeing issues. VirtualScroll should be used if you have a large list that you need a user to scroll through (like maybe a list of all the employees at a big company). It will help keep your app's scrolling smooth even on low end phones. I would use infintescroll for something like search results where when the user scrolls to the bottom It would pull the next "page" of results. Hope this all makes sense!
@jgw96 Thanks for answer! I saw this article, and i thought it will be a legit way to do it. I will use ion-cards with infiniteScroll then. But how do I deal with the situation when a user scrolls down alot meaning that with the time the app will have a big list loaded? I did that, and after ~100 items(big cards with a big image) the scroll doesn't fell so smooth already. Should i write something custom? I will really appreciate your suggestion, i'm new to app developing.
@InfinityOne Ahh ok, i will work my way through that article today or tonight and update this post with my results (: What devices are you testing with if you don't mind me asking? So to ensure performant scrolling with huge lists i would probably not use ion-card's. Although ion-card's are beautiful and for "average" size lists they work fine, once you get to 100's of items in your lists you can start to see performance issues on older android devices. Ion-card's use the box-shadow css property to give them the "elevated/floating" look. Unfortunately this can cause the webview to do alot of repaints which can kill performance. I would use just standard ion-items if i was gonna have a list with 100's of entries as they do not have any box-shadow styling. Hope this helps you!
@jgw96 Switched to ion-item and tested with ~1000 items loaded with infiniteScroll on iPhone 6s & 5s. Works fine, smooth scrolling, no problem. Tested on Galaxy S5 & Nexus 4 (both on Android 5.1), after 100 items even with ion-item scroll is dying slowly, as I load more items. Will look for more performant Android device to test.
I have the same problem. I'm using ion-card and after 20 items, notice that the scroll is slow. There are other solutions with the union of infiniteScroll and virtualScroll.
Now I am in doubt whether I use cards with pagination or smaller items with infiniteScroll.
@dudafreitasrj did you try setting the approxItemHeight input to the virtual scroll? it helps because the default height is 40px http://ionicframework.com/docs/v2/api/components/virtual-scroll/VirtualScroll/#input-properties
@jgw96 Im having a hard time to understand why vritualscroll and infinitscroll aren't meant to be used together? For me it look like very common use case. Think about News feed (like in facebook). You wouldn't like to load all the feed because that will take ages and probably kill you server, so you need inifinitscroll. You also don't want to display all the item above the current view of the user because he might have scroll down so much that he already viewed 1000 items.
And second question regarding the ion-card, removing the shadow-box property will increase the performance?
@royipressburger I don't understand too, why virtualScroll and infiniteScroll can't work together. When I saw this 2 components, I thought that there will be very easy to do something like social network's feed.
You also don't want to display all the item above the current view of the user because he might have scroll down so much that he already viewed 1000 items.
Absolutely agree with you!
I believe that there is a problem right now with virtualScroll that Ionic team can't solve. That's why it can't work with infiniteScroll. Hope that in near future, they will fix it, and virtualScroll + infiniteScroll will become base of any other Ionic2 app. Let's just understand that this is still beta, and devs still have a lot of work. But they should hear us and understand that this 2 components need to work together, to deliver an 'as close as possible native feeling' to the app. Mobile users are used already with such kind of scrolling, replacing this for example with pagination, in 2016, looks lame, in my opinion.
Also related to #6342.
This is really a great feature, if virtualScroll can update it's dataset and calculate a new transformation matrix upon insert of new records.
Any feed implementation today should handle both infinite and virtual scrolling logic.
Perhaps it can be a new ionic component, e.g ion-feed?
+1 on this issue, and pull to refresh not working correctly for VirtualScroll.
After getting data a few times with infinite scroll, a list can become quite long and cause lots of perfomance issues, VirtualScroll & Infinite scroll together would make sense to me.
+1 on this issue
Yes, virtual scroll is not very well implemented.
The scrolling to top part ist caused by: https://github.com/driftyco/ionic/blob/de12a4e9057e2f77536911b2ae891a7d81dba04c/src/components/virtual-scroll/virtual-scroll.ts#L378-L382
I've implemented a quick fix, but needs tests. I'm also only using this for inserting new elements. Restoring the position should probably also consider, elements could have been removed.
This issue has quite some tracktion:
- https://forum.ionicframework.com/t/virtual-scroll-remove-or-hide-item-without-reset-lost-scroll-position/54024/11
Update: This will not work on iOS, as the scroll positions are calculated differently. Maybe we can use content.getTop() instead of nativeElement.scrollTop, but it gives me slightly different values which messes up the positions.
+1
I also face the same issue and I also think virtual list and endless scrolling fit perfectly together. I'm also interested in any workaround or fix which works cross-browser, since jumping to top is really not acceptable. I think this will be a major issue for many ioni2 apps...
+1
An idea: If trying to combine infiniteScroll and virtualScroll to load more data on arriving at the bottom, you could save the scrollTop value of the content before loading more data and scroll back to this value manually after loading it. See https://github.com/driftyco/ionic/issues/8037#issuecomment-251479768 for more info.
Just tried a solution here #8037 need some comments about performance.
Any update on this?
Any updates on this?