Fix Crash on iOS when using MediaElement inside a CarouselView (again) #2245
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description of Change
We initially fixed #1903 in PR #2187. However, it is back in iOS 18 (see screenshot).
The underlying bug is still the same: we need to add the
AVPlayerViewController
used byMediaElement
as a childUIViewController
to theMauiMediaElement
UIView.However, testing on iOS 18 shows that iOS has changed how it adds children to the UIViewControllerHierarchy, invalidating our previous work-around which was to wait for the DataTemplate to be initialized on the ItemsView event and then retrieve the
ItemsViewController
fromItemsView.Handler
.In this PR, we retrieve the
ItemsViewController
by traversing the Descendants of the current visible page, accomplishing the same goal.Linked Issues
PR Checklist
approved
(bug) orChampioned
(feature/proposal)main
at time of PRAdditional information
This new approach has two downsides:
ItemsView
controls, we are unable to determine whichItemsView
contains ourMediaElement
Window
s, we are unable to determine which window contains ourMediaElement
I believe both of these can be resolved with a bit more effort + time, and I've added a
TODO
for both scenarios in the code base.However, these two scenarios are rare; I estimate that the vast majority of our users will not encounter this scenario. Therefore, I'd like to merge this bug fix now, and we can add the unsupported scenarios in a future PR.
However, since these two scenarios are very rare, I'd like to merge this as a hot fix today and then we can focus on fixing the edge cases.