Xamarin.Forms
Xamarin.Forms copied to clipboard
[Bug] Scrolling of ListView is not working on an iOS device - Xamarin.Forms
Description
Hi! I've been having an issue with the ListView in Xamarin.Forms not implementing their own default scrolling properly on iOS devices. I have created an application that has a ListView and has lots of items inside it. But the list view is not allowing scrolling and I am not able to scroll all the items and not able to see or access all the items of the list especially the last elements of the list view. Whenever I try to scroll along with not allowing me to scroll it also jumps back to the top of the screen when I take my finger off the screen.
This issue is only happening on iOS devices only with any iOS version and Xamrin.Forms of the latest version that is 5.0.0 SR8. I have also checked to see if any of the previous versions of Xamrin.Forms did not have this issue. But seems like almost all the versions have this issue.
Steps to Reproduce
- Create an app using the Xamarin.Forms
- Create a ListView and put lots of items inside the List view, at least so many that you will need to scroll the list to see all items depending on the screen size.
- Run app on device/ simulator with iOS at least greater than 12.0
- Start scrolling the list view
Expected Behavior
The ListView that you have implemented should be scrollable and should be able to scroll the entire list and see all the items of the list on an iOS device. The scrolling behaviour should be normal as anywhere else the scrolling would work and should not jump back to the starting or top of the list.
Actual Behavior
The List view does not implement or allow its default scrolling to work and because of this, I am not able to scroll all the items in the list. When I try to scroll down it scrolls partially and when I remove my finger from the screen it jumps back to the start/top of the list.
Basic Information
- Version with issue: Xamarin forms 5.0.0.2291
- Affected Devices: All devices with iOS greater than 12.0
Environment
I currently have this setup: Xamarin forms last stable version 5.0.0.2291 Xcode version 13.1 (13A1030d) Visual studio for Mac version 8.10.11 (build 8)
Screenshots and Recordings
This video clip shows the behaviour of an iPhone simulator running an iOS 15.0/ or iOS device. So irrespective of the physical device or simulator the behaviours is the same where the entire list of items is not scrollable on the ListView.
There are around 17 items in the list view shown in the below video and I am just able to see around 10 without any issue. When I try to scroll I am not able to scroll till the bottom also it takes them to the top of the screen again when I stop trying to scroll https://drive.google.com/drive/folders/1F-ZSZlO9AFi14gX5SSqXq8-hfEoRF-Kg?usp=sharing
Workaround
I have tried putting the ListView inside the scrollView that definitely works and solves the issue I have and allows proper scrolling, but according to the document https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/listview/performance#listview-performance-suggestions it says that the Listview should not be nested and since the ListView has its own scrolling behaviour, there is no need to put that inside a ScrollView. So If I do this workaround there is a high chance that what I am trying to achieve now might cause other issues for me in future.
Hey there, thank you for the detailed report, however without any relevant code or a reproduction it's near to impossible to see what is going on. If the ListView is indeed broken then we would be buried under reports which is not the case, so I'm expecting that there is something specific to your case that causes this. Please add any details you might have in that regard.
Hello, Thank you for getting in touch with me and letting me know about this. I understand what you are trying to say I am currently working on it to give you a zip file or some source code to replicate that issue I will soon be adding that to the bug ticket I have created. I will try to give you more details making sure I am not exposing a lot or a major part of the project which I am not supposed to.
I understand that you can't just send me the project and even if you could, I can't look at it because of the potential legal issues :)
That is why I would ask you to either share relevant snippets of code, for example: how is your layout built up? Or try to start a new Xamarin.Forms app and start copy and pasting things into that new app one by one until you see the problem happening. That can also help you understand when and why a problem arises and maybe even fix it yourself or, if you can't figure it out yourself, you now have a reproducible project that you can show us :)
Sure, that works for me.
I can start in that direction. I can see if I can somehow create a new template app and modify the app just enough to reproduce the issue. I will post that to the bug as soon as I am ready with it.
The time you take won't matter, of course other than: as long as I don't have a reproduction I won't be able to look at it. If we do have the reproduction, I can't make any solid promises. Since it seems to be very specific to you and you're the only one impacted the priority might not be that high. But make sure to ping me and I will try to have a look asap :)
@pavni1579boosa not sure if this is your scenario, but I've seen this behavior before when the ItemsSource data is not an ObaservableCollection and you add items after the bound property is set, for instance:
<ListView ItemsSource="{Binding Items}">
...
Ans your view model does something like this:
Items = new List<string>(); // PropertyChange is risen here
Items.Add("one");
Items.Add("two");
One could imagine that the ListView wouldn't show any cells but in iOS it does, as long as the Adds happen right after the property is set. The problem is that the the ListView's height is not properly calculated since it thinks it has no rows provoking the same scrolling issue the ListView has in your video.
The proper way of doing this is setting the bound property at the end:
var list = new List<string>();
list.Add("one");
list.Add("two");
Items = list; // PropertyChange is risen here
Or use an ObservableCollection if your scenario requires one.
Hope this helps!
@dirivero thanks for the information that looks promising. Will try that out.
@pavni1579boosa, Do you have solution?
@jfversluis, you can reproduce this bug if you use listview inside refreshview
same issue , any solutions please ?
@jfversluis, you can reproduce this bug if you use listview inside refreshview
same issue , any solutions please ?