-
Notifications
You must be signed in to change notification settings - Fork 1.9k
[Bug] [Android] CarouselView.CurrentItem = null Causes App to Crash #13296
Comments
The original reproduction project was fixed in 5.0.0.1874, however if you use |
@ahoefling Any reason you can't update to 5.0? |
The short answer is yes I can upgrade to 5.0, but it wasn't exactly clear if this would work as the preview builds of 5.0 and even the initial stable release caused us problems. When using the <CarouselView
ItemsSource="{Binding Items}"
CurrentItem="{Binding CurrentItem}"
IsSwipeEnabled="True" /> In XF 4.8 by setting When I updated the loop property to <CarouselView
ItemsSource="{Binding Items}"
CurrentItem="{Binding CurrentItem}"
IsSwipeEnabled="True"
Loop="False" /> I spent a couple hours this morning trying to reproduce the in a small scale sample app, but wasn't able to get the same effect. I think my project adds additional moving parts on our specific Android device - Zebra TC70x which uses a custom AOSP fork of Android 8.1 that integrates with a hardware barcode scanner. Each item in the I unfortunately did not have enough concrete data to create another issue for XF 5.0. |
Update - Crashes in XF 5.0@hartez I did some more research on this and it is in fact happening in Xamarin.Forms 5.0. I originally thought this was fixed as the original sample code was crashing in XF 4.8 and working in XF 5.0. When I updated my proprietary code, I noticed I was still getting the crash. This still originated from the statement In short when you null out the <CarouselView
ItemsSource="{Binding Items}"
CurrentItem="{Binding SelectedItem}"
Loop="False"
IsSwipeEnabled="True" /> Items.Clear();
SelectedItem = null; Stacktrace
Reproduction LinkI have created an updated sample project for anyone to take a look at. This uses XF 5.0.0.1874 and the app does crash on clearing out the VersionsXamarin.Forms 5.0.0.1874 |
Workaround
To obtain custom functionality you can customize the ScrollTo-Method |
@nionzion Thanks for the workaround, this does prevent the application from crashing and it is something I was looking at for a potential fix to XF. I believe the problem to be more complex than that as It appears that there is some state management code that happens in the parent class that needs to be reset. Otherwise setting the |
This also affects UWP (#13133 (comment)):
Testing Android 10 - API 29 didn't throw me any errors. All using X.F 5.0.0.1874 |
Hey i can fix the issue of the crash but i m trying to figure out why it doesn't work the 2nd time (clear the items) . Will keep you posted @ahoefling working on it here #13536 |
@nionzion solution also worked for me on IOS. Thank you. Spent days on trying to fix this. |
Description
When using a CarouselView if you attempt to set the
CurrentItem
to null the application crashes. The following code should not cause the application to crash.Steps to Reproduce
Expected Behavior
The app should allow the
CurrentItem
to be set to null as there is no longer a current item. An alternative would be once theItemsSource
is cleared theCurrentItem
is automatically set to null.Actual Behavior
The app crashes
Basic Information
Environment
Show/Hide Visual Studio info
Build Logs
Not Applicable
Screenshots
Not Applicable
Reproduction Link
CVCurrentItemBug.zip
Workaround
My workaround is pretty hacky, but it works. In the ViewModel every time the
SelectedItem
is updated it publishes an event for the UI to update. Since I want to null out theSelectedItem
when theItems
has a length of 0, I can add a check for this. Only publish the event if theItems.Length > 0
. This will allow the state of our ViewModel to properly reflect the data but only communicate to the UI if the it needs to be notified.The text was updated successfully, but these errors were encountered: