Skip to content

Fix iOS MediaElement support for multiple ItemsViews and windows#3222

Open
ne0rrmatrix wants to merge 5 commits into
CommunityToolkit:mainfrom
ne0rrmatrix:FixItemsViewController
Open

Fix iOS MediaElement support for multiple ItemsViews and windows#3222
ne0rrmatrix wants to merge 5 commits into
CommunityToolkit:mainfrom
ne0rrmatrix:FixItemsViewController

Conversation

@ne0rrmatrix
Copy link
Copy Markdown
Member

Summary

  • fix MediaElement parent view controller attachment on iOS/MacCatalyst by resolving the actual UIKit responder-chain parent instead of guessing from page/item view state
  • add shared current-page enumeration across windows to support multi-window scenarios
  • add unit coverage for multi-window page resolution in ParentWindowTests

Why

MediaElement was throwing in templated iOS/MacCatalyst scenarios when:

  • a page contained multiple ItemsView controls
  • an app used multiple windows

Using the actual rendered UIKit hierarchy avoids the brittle handler-selection logic that caused both failures.

Fixes #2247
Fixes #2249

Validation

  • ran focused MediaElement unit tests (ParentWindowTests, MediaElementTests): 14 passed
  • verified in the simulator

Copilot AI review requested due to automatic review settings May 21, 2026 06:38
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes iOS/MacCatalyst MediaElement failures in templated and multi-window scenarios by attaching AVPlayerViewController using the actual UIKit responder-chain parent view controller (instead of inferring it from MAUI page/items-view state), and adds shared helpers/tests for resolving current pages across multiple windows.

Changes:

  • Update iOS/MacCatalyst MauiMediaElement to attach/detach AVPlayerViewController based on the UIKit responder chain (supporting multiple ItemsViews and multiple windows).
  • Add a shared TryGetCurrentPages helper to enumerate the “current page” per window.
  • Add unit coverage validating multi-window current-page resolution.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
src/CommunityToolkit.Maui.UnitTests/Views/MediaElement/ParentWindowTests.cs Adds a unit test asserting current-page resolution across multiple windows.
src/CommunityToolkit.Maui.MediaElement/Views/MauiMediaElement.macios.cs Reworks iOS/MacCatalyst parent view controller attachment logic to use the UIKit responder chain.
src/CommunityToolkit.Maui.MediaElement/Extensions/PageExtensions.shared.cs Adds multi-window current-page enumeration and updates parent-window current-page resolution.

Comment thread src/CommunityToolkit.Maui.MediaElement/Views/MauiMediaElement.macios.cs Outdated
Comment thread src/CommunityToolkit.Maui.MediaElement/Extensions/PageExtensions.shared.cs Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants