CarouselViewHandler2 InvalidCastException for MauiMediaElement.macios.cs when using CollectionViewHandler2 and CarouselViewHandler2#2926
Conversation
ne0rrmatrix
left a comment
There was a problem hiding this comment.
Looks good. I am currently testing it. Have you thought about adding a sample to sample app to track behavior?
That's the weird thing! Maui/samples/CommunityToolkit.Maui.Sample/MauiProgram.cs Lines 78 to 81 in b0c8ca6 However, when I debug the sample app and load the |
ne0rrmatrix
left a comment
There was a problem hiding this comment.
My only suggestion at this point is to create a new page for media element that uses CarouselView that supports Mac/iOS. Currently we have a CarouselView page but it only supports Windows/Android and uses multiple itemViews which is not currently supported on Mac/iOS. If we include that I would be happy to approve this. As far as I can tell it works. I tested the PR branch on my pac in a simulator and it works.
Good catch btw. If you feel we do not need that page go ahead and merge this as it does exactly what we need it to. It works.
|
Thanks! I say we defer the sample app updates since you've already opened a PR to implement the fix for multiple ItemsViews: #2807 |
Description of Change
This PR fixes a typo I made when adding support for
ItemsViewController2<T>inMauiMediaElement.macios.cs.When a developer is using an
ItemsViewController2<T>, we were incorrectly casting it toItemsViewController<T>instead of aItemsViewController2<T>, causing theInvalidCastException.Linked Issues
MediaElementinCollectionViewHandler2andCarouselViewHandler2#2925PR Checklist
approved(bug) orChampioned(feature/proposal)mainat time of PRAdditional information
The bug was due to a copy/paste error when I created the following two methods side-by-side:
static ItemsViewController<TItemsView> GetInternalControllerForItemsView<TItemsView>(ItemsViewHandler<TItemsView>) where TItemsView : ItemsViewstatic ItemsViewController2<TItemsView> GetInternalControllerForItemsView2<TItemsView>(ItemsViewHandler2<TItemsView>) where TItemsView : ItemsViewThis bug was not caught earlier because the Controller we need from .NET MAUI is a
protected internalproperty, forcing us to use reflection to retrieve it. If the property was public we could rely on C# type-safety.