From 80ea6c32639857e3080524980607dc99797be1da Mon Sep 17 00:00:00 2001 From: SuthiYuvaraj <92777079+SuthiYuvaraj@users.noreply.github.com> Date: Tue, 14 Jul 2026 14:11:00 +0530 Subject: [PATCH 01/62] Fix for 33612 --- .../GesturePlatformManager.Windows.cs | 40 +++++++++ .../TestCases.HostApp/Issues/Issue33612.cs | 90 +++++++++++++++++++ .../Tests/Issues/Issue33612.cs | 42 +++++++++ src/Core/src/Platform/Windows/ContentPanel.cs | 8 ++ .../Windows/ContentPanelAutomationPeer.cs | 21 ++++- .../Windows/MauiBorderAutomationPeer.cs | 14 ++- src/Core/src/Platform/iOS/MauiView.cs | 38 ++++++++ .../src/Platform/iOS/SemanticExtensions.cs | 38 +++++++- 8 files changed, 287 insertions(+), 4 deletions(-) create mode 100644 src/Controls/tests/TestCases.HostApp/Issues/Issue33612.cs create mode 100644 src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue33612.cs diff --git a/src/Controls/src/Core/Platform/GestureManager/GesturePlatformManager.Windows.cs b/src/Controls/src/Core/Platform/GestureManager/GesturePlatformManager.Windows.cs index 958acfc53dce..ee3c0f576b9b 100644 --- a/src/Controls/src/Core/Platform/GestureManager/GesturePlatformManager.Windows.cs +++ b/src/Controls/src/Core/Platform/GestureManager/GesturePlatformManager.Windows.cs @@ -316,6 +316,11 @@ void ClearContainerEventHandlers() { if (_container != null) { + if (_container is Microsoft.Maui.Platform.ContentPanel contentPanel) + { + contentPanel.AutomationActivateCallback = null; + } + if ((_subscriptionFlags & SubscriptionFlags.ContainerDragEventsSubscribed) != 0) { _subscriptionFlags &= ~SubscriptionFlags.ContainerDragEventsSubscribed; @@ -986,6 +991,41 @@ void UpdatingGestureRecognizers() } } + // UI Automation has no built-in Invoke pattern for a plain gesture-only element + // (unlike a native Button). Without this, Narrator can neither invoke the element + // (Enter/Narrator-activate) nor announce "double tap to activate", since that hint + // is auto-generated only for peers that support Invoke. Wire an activate callback + // on the ContentPanel so ContentPanelAutomationPeer/MauiBorderAutomationPeer can + // expose IInvokeProvider (mirrors AccessibilityActivateCallback on iOS's MauiView). + // Decoupled from the tap-subscription block above so it also applies when the + // container only has a child-owned tap gesture reached via bubbling. + if (_container is Microsoft.Maui.Platform.ContentPanel activatablePanel && view is not null && + view.HasAccessibleTapGesture()) + { + var weakThis = new WeakReference(this); + + activatablePanel.AutomationActivateCallback = () => + { + if (!weakThis.TryGetTarget(out var manager) || manager.Element is not View v) + { + return false; + } + + if (!v.IsEnabled || v.InputTransparent) + { + return false; + } + + if (v.HasAccessibleTapGesture(out var tapGestureRecognizer)) + { + tapGestureRecognizer.SendTapped(v); + return true; + } + + return false; + }; + } + if (gestures.HasAnyGesturesFor(g => g.NumberOfTapsRequired == 1 || g.NumberOfTapsRequired == 2) || children?.GetChildGesturesFor(g => g.NumberOfTapsRequired == 1 || g.NumberOfTapsRequired == 2).Any() == true) { diff --git a/src/Controls/tests/TestCases.HostApp/Issues/Issue33612.cs b/src/Controls/tests/TestCases.HostApp/Issues/Issue33612.cs new file mode 100644 index 000000000000..6c1ab26fa978 --- /dev/null +++ b/src/Controls/tests/TestCases.HostApp/Issues/Issue33612.cs @@ -0,0 +1,90 @@ +using System.Collections.ObjectModel; + +namespace Maui.Controls.Sample.Issues; + +[Issue(IssueTracker.Github, 33612, "Inconsistent Accessibility Behavior Across Platforms - a container with SemanticProperties.Description/Hint should not collapse its independently-accessible children", PlatformAffected.All)] +public class Issue33612 : ContentPage +{ + public ObservableCollection Items { get; } = new() + { + "First item", + "Second item", + "Third item" + }; + + Label _tappedItemLabel; + + public Issue33612() + { + BindingContext = this; + + _tappedItemLabel = new Label + { + AutomationId = "TappedItemLabel", + Text = "None" + }; + + var itemsLayout = new VerticalStackLayout + { + AutomationId = "SuggestionsItemsLayout" + }; + itemsLayout.SetBinding(BindableLayout.ItemsSourceProperty, new Binding(nameof(Items))); + BindableLayout.SetItemTemplate(itemsLayout, CreateItemTemplate()); + + // Outer structural container: has its own Description ("Suggestions") but must not hide + // the individually-accessible items inside it (root cause of #33612). + var suggestionsContainer = new ContentView + { + AutomationId = "SuggestionsContainer", + Content = new ScrollView { Content = itemsLayout } + }; + SemanticProperties.SetDescription(suggestionsContainer, "Suggestions"); + + Content = new VerticalStackLayout + { + Children = { suggestionsContainer, _tappedItemLabel } + }; + } + + DataTemplate CreateItemTemplate() + { + return new DataTemplate(() => + { + var label = new Label + { + HorizontalOptions = LayoutOptions.Center, + VerticalOptions = LayoutOptions.Center + }; + label.SetBinding(Label.TextProperty, new Binding(".")); + + // Each item is its own actionable unit: it owns a gesture recognizer, so it should + // remain a normal leaf accessibility element carrying its own Description/Hint, + // rather than being treated as a passive structural wrapper. + var border = new Border + { + Padding = 12, + Margin = 6, + Content = label + }; + border.SetBinding(AutomationIdProperty, new Binding(".")); + border.SetBinding(SemanticProperties.DescriptionProperty, new Binding(".")); + SemanticProperties.SetHint(border, "Double tap to activate"); + + var tapGestureRecognizer = new TapGestureRecognizer(); + tapGestureRecognizer.Tapped += OnSuggestionTapped; + border.GestureRecognizers.Add(tapGestureRecognizer); + + return border; + }); + } + + async void OnSuggestionTapped(object sender, TappedEventArgs e) + { + if (sender is Border tappedBorder && tappedBorder.BindingContext is string item) + { + _tappedItemLabel.Text = item; + } + + await DisplayAlert("Suggestion Selected", "is a suggestion tap event", "OK"); + } +} diff --git a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue33612.cs b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue33612.cs new file mode 100644 index 000000000000..7c8a7cd238cc --- /dev/null +++ b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue33612.cs @@ -0,0 +1,42 @@ +using NUnit.Framework; +using UITest.Appium; +using UITest.Core; + +namespace Microsoft.Maui.TestCases.Tests.Issues; + +public class Issue33612 : _IssuesUITest +{ + public Issue33612(TestDevice device) : base(device) { } + + public override string Issue => "Inconsistent Accessibility Behavior Across Platforms - a container with SemanticProperties.Description/Hint should not collapse its independently-accessible children"; + + [Test] + [Category(UITestCategories.Accessibility)] + public void ContainerDescriptionDoesNotHideIndividuallyAccessibleItems() + { + App.WaitForElement("SuggestionsContainer"); + + // Each item must still be individually reachable by automation/accessibility tooling — + // before the fix, a Description/Hint on the outer container collapsed the whole subtree + // into a single opaque element, hiding these nested items entirely. + App.WaitForElement("First item"); + App.WaitForElement("Second item"); + App.WaitForElement("Third item"); + } + + [Test] + [Category(UITestCategories.Accessibility)] + public void TappingSuggestionItemStillInvokesItsOwnGesture() + { + App.WaitForElement("SuggestionsContainer"); + App.WaitForElement("First item"); + + App.Tap("First item"); + + App.WaitForElement("OK"); + App.Tap("OK"); + + var tappedItemText = App.WaitForElement("TappedItemLabel").GetText(); + Assert.That(tappedItemText, Is.EqualTo("First item")); + } +} diff --git a/src/Core/src/Platform/Windows/ContentPanel.cs b/src/Core/src/Platform/Windows/ContentPanel.cs index 7f3ba1235730..664c8a96dbe8 100644 --- a/src/Core/src/Platform/Windows/ContentPanel.cs +++ b/src/Core/src/Platform/Windows/ContentPanel.cs @@ -56,6 +56,14 @@ internal FrameworkElement? Content internal bool IsInnerPath { get; private set; } + /// + /// Optional callback invoked by / + /// when UI Automation invokes this element (e.g. Narrator's Enter/double-tap activation). + /// Set by GesturePlatformManager for elements whose only interaction is a TapGestureRecognizer, + /// which otherwise have no native Invoke pattern (mirrors AccessibilityActivateCallback on iOS). + /// + internal Func? AutomationActivateCallback { get; set; } + protected override global::Windows.Foundation.Size MeasureOverride(global::Windows.Foundation.Size availableSize) { var measured = base.MeasureOverride(availableSize); diff --git a/src/Core/src/Platform/Windows/ContentPanelAutomationPeer.cs b/src/Core/src/Platform/Windows/ContentPanelAutomationPeer.cs index c465382e2b1f..63015912df38 100644 --- a/src/Core/src/Platform/Windows/ContentPanelAutomationPeer.cs +++ b/src/Core/src/Platform/Windows/ContentPanelAutomationPeer.cs @@ -1,10 +1,11 @@ using System.Collections.Generic; using Microsoft.UI.Xaml.Automation; using Microsoft.UI.Xaml.Automation.Peers; +using Microsoft.UI.Xaml.Automation.Provider; namespace Microsoft.Maui.Platform { - internal partial class ContentPanelAutomationPeer : FrameworkElementAutomationPeer + internal partial class ContentPanelAutomationPeer : FrameworkElementAutomationPeer, IInvokeProvider { internal ContentPanelAutomationPeer(ContentPanel owner) : base(owner) { } @@ -16,7 +17,23 @@ protected override AutomationControlType GetAutomationControlTypeCore() => protected override string GetLocalizedControlTypeCore() => HasDescription ? string.Empty : base.GetLocalizedControlTypeCore() ?? string.Empty; + // Suppress children only when this container wraps nothing (avoids duplicate announcement + // for the common single-child wrapper case). A container with real content (e.g. a + // BindableLayout of independently-focusable items) keeps its children reachable — see #33612. protected override IList? GetChildrenCore() => - HasDescription ? null : base.GetChildrenCore(); + HasDescription && Owner is ContentPanel { CrossPlatformLayout: IContentView { PresentedContent: null } } + ? null + : base.GetChildrenCore(); + + // Expose the Invoke pattern only when GesturePlatformManager has wired an activate callback + // (i.e. this element's only interaction is a TapGestureRecognizer). This is what makes + // Narrator announce "double tap to activate" and lets Enter/Narrator-activate fire the tap. + protected override object? GetPatternCore(PatternInterface patternInterface) => + patternInterface == PatternInterface.Invoke && Owner is ContentPanel { AutomationActivateCallback: not null } + ? this + : base.GetPatternCore(patternInterface); + + // IInvokeProvider + public void Invoke() => (Owner as ContentPanel)?.AutomationActivateCallback?.Invoke(); } } diff --git a/src/Core/src/Platform/Windows/MauiBorderAutomationPeer.cs b/src/Core/src/Platform/Windows/MauiBorderAutomationPeer.cs index 6ddbe415578c..12430937e7a5 100644 --- a/src/Core/src/Platform/Windows/MauiBorderAutomationPeer.cs +++ b/src/Core/src/Platform/Windows/MauiBorderAutomationPeer.cs @@ -1,11 +1,12 @@ using Microsoft.UI.Xaml.Automation; using Microsoft.UI.Xaml.Automation.Peers; +using Microsoft.UI.Xaml.Automation.Provider; using Microsoft.UI.Xaml.Controls; namespace Microsoft.Maui.Platform { // TODO: Make this class public in .NET11.0. Issue Link: https://github.com/dotnet/maui/issues/30205 - internal partial class MauiBorderAutomationPeer : FrameworkElementAutomationPeer + internal partial class MauiBorderAutomationPeer : FrameworkElementAutomationPeer, IInvokeProvider { internal MauiBorderAutomationPeer(ContentPanel owner) : base(owner) { } @@ -71,5 +72,16 @@ protected override bool IsContentElementCore() var accessibilityView = panel.ReadLocalValue(AutomationProperties.AccessibilityViewProperty); return accessibilityView is AccessibilityView.Content; } + + // Expose the Invoke pattern only when GesturePlatformManager has wired an activate callback + // (i.e. this Border's only interaction is a TapGestureRecognizer). This is what makes + // Narrator announce "double tap to activate" and lets Enter/Narrator-activate fire the tap. + protected override object? GetPatternCore(PatternInterface patternInterface) => + patternInterface == PatternInterface.Invoke && Owner is ContentPanel { AutomationActivateCallback: not null } + ? this + : base.GetPatternCore(patternInterface); + + // IInvokeProvider + public void Invoke() => (Owner as ContentPanel)?.AutomationActivateCallback?.Invoke(); } } diff --git a/src/Core/src/Platform/iOS/MauiView.cs b/src/Core/src/Platform/iOS/MauiView.cs index 2ba89eb58cf2..c30f10a48de5 100644 --- a/src/Core/src/Platform/iOS/MauiView.cs +++ b/src/Core/src/Platform/iOS/MauiView.cs @@ -998,5 +998,43 @@ public override bool AccessibilityActivate() return base.AccessibilityActivate(); } + + /// + /// Label for a phantom accessibility element announcing this container's own Description + /// as a separate VoiceOver stop (see #33612), without hiding its real children. + /// + internal string? AccessibilityContainerLabel { get; set; } + + /// Hint for the phantom element. See . + internal string? AccessibilityContainerHint { get; set; } + + // Informal protocol member, not a virtual property on UIView; override via selector export. + // Returning null matches UIKit's own default (VoiceOver infers elements from subviews). + [Export("accessibilityElements")] + internal virtual NSObject[]? AccessibilityElements + { + get + { + if (string.IsNullOrEmpty(AccessibilityContainerLabel) && string.IsNullOrEmpty(AccessibilityContainerHint)) + { + return null; + } + + // UIKit recurses into each entry's own accessibility rules, so children stay reachable. + // Created fresh each call (not cached) to avoid holding an NSObject field on this view. + var containerLabelElement = new UIAccessibilityElement(this) + { + IsAccessibilityElement = true, + AccessibilityLabel = AccessibilityContainerLabel, + AccessibilityHint = AccessibilityContainerHint, + AccessibilityFrameInContainerSpace = Bounds, + }; + + var elements = new NSObject[Subviews.Length + 1]; + elements[0] = containerLabelElement; + Array.Copy(Subviews, 0, elements, 1, Subviews.Length); + return elements; + } + } } } diff --git a/src/Core/src/Platform/iOS/SemanticExtensions.cs b/src/Core/src/Platform/iOS/SemanticExtensions.cs index 60cf0efacca0..5700fbf313e4 100644 --- a/src/Core/src/Platform/iOS/SemanticExtensions.cs +++ b/src/Core/src/Platform/iOS/SemanticExtensions.cs @@ -85,7 +85,7 @@ public static void UpdateSemantics(this UIView platformView, IView view) // stops announcing stale content and its children become navigable again. if (semantics is null) { - if (view is ILayout && platformView is not UIControl && platformView.IsAccessibilityElement) + if ((view is ILayout || view is IContentView) && platformView is not UIControl && platformView.IsAccessibilityElement) { platformView.IsAccessibilityElement = false; platformView.AccessibilityLabel = null; @@ -93,6 +93,8 @@ public static void UpdateSemantics(this UIView platformView, IView view) if (platformView is MauiView clearedMauiView) { clearedMauiView.SynthesizeAccessibilityLabelFromChildren = false; + clearedMauiView.AccessibilityContainerLabel = null; + clearedMauiView.AccessibilityContainerHint = null; } } @@ -174,6 +176,40 @@ public static void UpdateSemantics(this UIView platformView, IView view) } } + // IContentView containers (ContentView, Border, Frame, etc.) don't get #35590 synthesis. + // Left alone they'd hit the generic UpdateSemantics below and collapse into one leaf, + // hiding children (root cause of #33612). So never collapse them; instead announce + // Description/Hint via a phantom element (MauiView.AccessibilityElements) while keeping + // children reachable. Skip (fall through to a normal leaf) when empty (Guard 1) or when + // the container owns its own gesture recognizer, i.e. is itself the actionable unit + // (Guard 2). + if (view is IContentView contentView + && view is not ILayout + && contentView.PresentedContent is not null + && platformView.GestureRecognizers is not { Length: > 0 }) + { + platformView.AccessibilityLabel = semantics.Description; + platformView.AccessibilityHint = semantics.Hint; + platformView.IsAccessibilityElement = false; + + if (platformView is MauiView containerMauiView) + { + containerMauiView.AccessibilityContainerLabel = semantics.Description; + containerMauiView.AccessibilityContainerHint = semantics.Hint; + } + + UpdateSemanticsHeading(platformView, semantics); + return; + } + + // Falling through: this container has no content, or owns its own gesture (Guard 2). + // Clear any stale phantom label so it doesn't linger once this view becomes a leaf. + if (platformView is MauiView leafMauiView) + { + leafMauiView.AccessibilityContainerLabel = null; + leafMauiView.AccessibilityContainerHint = null; + } + UpdateSemantics(platformView, semantics); } From 412affa32b4e45d40ae69ada95ca62a51b443e25 Mon Sep 17 00:00:00 2001 From: SuthiYuvaraj <92777079+SuthiYuvaraj@users.noreply.github.com> Date: Tue, 14 Jul 2026 15:58:08 +0530 Subject: [PATCH 02/62] Fix for windows --- src/Core/src/Platform/Windows/ContentPanel.cs | 20 ++++++++++- .../Windows/ContentPanelAutomationPeer.cs | 36 ++++++++++++++++--- .../Windows/MauiBorderAutomationPeer.cs | 28 ++++++++++++++- 3 files changed, 77 insertions(+), 7 deletions(-) diff --git a/src/Core/src/Platform/Windows/ContentPanel.cs b/src/Core/src/Platform/Windows/ContentPanel.cs index 664c8a96dbe8..749a72a0144b 100644 --- a/src/Core/src/Platform/Windows/ContentPanel.cs +++ b/src/Core/src/Platform/Windows/ContentPanel.cs @@ -56,13 +56,31 @@ internal FrameworkElement? Content internal bool IsInnerPath { get; private set; } + Func? _automationActivateCallback; + /// /// Optional callback invoked by / /// when UI Automation invokes this element (e.g. Narrator's Enter/double-tap activation). /// Set by GesturePlatformManager for elements whose only interaction is a TapGestureRecognizer, /// which otherwise have no native Invoke pattern (mirrors AccessibilityActivateCallback on iOS). /// - internal Func? AutomationActivateCallback { get; set; } + /// + /// Setting this also flips -equivalent keyboard-focusability on + /// (via , which is available on any UIElement, not just Control). + /// ContentPanel derives from Panel, so it isn't keyboard-focusable by default; without this, + /// Narrator's Enter/scan-activate never routes to this peer's IInvokeProvider because the + /// automation peer reports itself as not keyboard-focusable (see IsKeyboardFocusableCore on the + /// peers). This mirrors making a gesture-only element behave like a native focusable control. + /// + internal Func? AutomationActivateCallback + { + get => _automationActivateCallback; + set + { + _automationActivateCallback = value; + IsTabStop = value is not null; + } + } protected override global::Windows.Foundation.Size MeasureOverride(global::Windows.Foundation.Size availableSize) { diff --git a/src/Core/src/Platform/Windows/ContentPanelAutomationPeer.cs b/src/Core/src/Platform/Windows/ContentPanelAutomationPeer.cs index 63015912df38..e586a6122b50 100644 --- a/src/Core/src/Platform/Windows/ContentPanelAutomationPeer.cs +++ b/src/Core/src/Platform/Windows/ContentPanelAutomationPeer.cs @@ -17,13 +17,30 @@ protected override AutomationControlType GetAutomationControlTypeCore() => protected override string GetLocalizedControlTypeCore() => HasDescription ? string.Empty : base.GetLocalizedControlTypeCore() ?? string.Empty; - // Suppress children only when this container wraps nothing (avoids duplicate announcement - // for the common single-child wrapper case). A container with real content (e.g. a - // BindableLayout of independently-focusable items) keeps its children reachable — see #33612. - protected override IList? GetChildrenCore() => - HasDescription && Owner is ContentPanel { CrossPlatformLayout: IContentView { PresentedContent: null } } + // Suppress children when this container wraps nothing (Guard 1 — avoids duplicate + // announcement for the common empty wrapper case), or when it owns its own tap gesture, + // i.e. is itself the actionable unit (Guard 2 — mirrors iOS SemanticExtensions.cs). Without + // Guard 2, a tappable ContentView with a single child (e.g. a bound Label) would never + // collapse, so Narrator's cursor lands on the child instead of this peer and never reads its + // HelpText ("Double tap to activate") or discovers its IInvokeProvider. A container with real, + // non-actionable content (e.g. a BindableLayout of independently-focusable items) still keeps + // its children reachable — see #33612. + protected override IList? GetChildrenCore() + { + if (Owner is not ContentPanel panel) + { + return base.GetChildrenCore(); + } + + if (panel.AutomationActivateCallback is not null) + { + return null; + } + + return HasDescription && panel is { CrossPlatformLayout: IContentView { PresentedContent: null } } ? null : base.GetChildrenCore(); + } // Expose the Invoke pattern only when GesturePlatformManager has wired an activate callback // (i.e. this element's only interaction is a TapGestureRecognizer). This is what makes @@ -33,6 +50,15 @@ protected override string GetLocalizedControlTypeCore() => ? this : base.GetPatternCore(patternInterface); + // ContentPanel derives from Panel, not Control, so it has no native Tab-stop/keyboard focus. + // Report this peer as keyboard-focusable whenever it's activatable so Narrator's Enter-key + // activation routes here instead of being swallowed (mirrors IsTabStop set on ContentPanel + // when AutomationActivateCallback is assigned — see ContentPanel.AutomationActivateCallback). + protected override bool IsKeyboardFocusableCore() => + (Owner as ContentPanel)?.AutomationActivateCallback is not null || base.IsKeyboardFocusableCore(); + + protected override void SetFocusCore() => Owner?.Focus(global::Microsoft.UI.Xaml.FocusState.Programmatic); + // IInvokeProvider public void Invoke() => (Owner as ContentPanel)?.AutomationActivateCallback?.Invoke(); } diff --git a/src/Core/src/Platform/Windows/MauiBorderAutomationPeer.cs b/src/Core/src/Platform/Windows/MauiBorderAutomationPeer.cs index 12430937e7a5..2d1b2eb40806 100644 --- a/src/Core/src/Platform/Windows/MauiBorderAutomationPeer.cs +++ b/src/Core/src/Platform/Windows/MauiBorderAutomationPeer.cs @@ -1,4 +1,5 @@ -using Microsoft.UI.Xaml.Automation; +using System.Collections.Generic; +using Microsoft.UI.Xaml.Automation; using Microsoft.UI.Xaml.Automation.Peers; using Microsoft.UI.Xaml.Automation.Provider; using Microsoft.UI.Xaml.Controls; @@ -73,6 +74,22 @@ protected override bool IsContentElementCore() return accessibilityView is AccessibilityView.Content; } + // Once this Border has its own Control-view identity (Name/HelpText/explicit opt-in), treat + // it as a leaf — same as MauiButtonAutomationPeer. Otherwise Narrator's cursor lands on the + // inner content (e.g. a bound Label) instead of the Border, so it never reads this Border's + // HelpText ("Double tap to activate") and never reaches its IInvokeProvider (see #33612). + // Guard against a detached/disposed Owner (e.g. during item recycling) before calling into + // base.GetChildrenCore(), which is not guaranteed to be null-safe in that state. + protected override IList? GetChildrenCore() + { + if (Owner is null) + { + return null; + } + + return IsControlElementCore() ? null : base.GetChildrenCore(); + } + // Expose the Invoke pattern only when GesturePlatformManager has wired an activate callback // (i.e. this Border's only interaction is a TapGestureRecognizer). This is what makes // Narrator announce "double tap to activate" and lets Enter/Narrator-activate fire the tap. @@ -81,6 +98,15 @@ protected override bool IsContentElementCore() ? this : base.GetPatternCore(patternInterface); + // ContentPanel derives from Panel, not Control, so it has no native Tab-stop/keyboard focus. + // Report this peer as keyboard-focusable whenever it's activatable so Narrator's Enter-key + // activation routes here instead of being swallowed (mirrors IsTabStop set on ContentPanel + // when AutomationActivateCallback is assigned — see ContentPanel.AutomationActivateCallback). + protected override bool IsKeyboardFocusableCore() => + (Owner as ContentPanel)?.AutomationActivateCallback is not null || base.IsKeyboardFocusableCore(); + + protected override void SetFocusCore() => Owner?.Focus(global::Microsoft.UI.Xaml.FocusState.Programmatic); + // IInvokeProvider public void Invoke() => (Owner as ContentPanel)?.AutomationActivateCallback?.Invoke(); } From c3787db1dc5aedd15a7237d4bb67ef66326df0ea Mon Sep 17 00:00:00 2001 From: SuthiYuvaraj <92777079+SuthiYuvaraj@users.noreply.github.com> Date: Tue, 14 Jul 2026 17:49:03 +0530 Subject: [PATCH 03/62] reverted windows --- .../GesturePlatformManager.Windows.cs | 40 --------------- src/Core/src/Platform/Windows/ContentPanel.cs | 26 ---------- .../Windows/ContentPanelAutomationPeer.cs | 49 ++----------------- .../Windows/MauiBorderAutomationPeer.cs | 42 +--------------- 4 files changed, 5 insertions(+), 152 deletions(-) diff --git a/src/Controls/src/Core/Platform/GestureManager/GesturePlatformManager.Windows.cs b/src/Controls/src/Core/Platform/GestureManager/GesturePlatformManager.Windows.cs index ee3c0f576b9b..958acfc53dce 100644 --- a/src/Controls/src/Core/Platform/GestureManager/GesturePlatformManager.Windows.cs +++ b/src/Controls/src/Core/Platform/GestureManager/GesturePlatformManager.Windows.cs @@ -316,11 +316,6 @@ void ClearContainerEventHandlers() { if (_container != null) { - if (_container is Microsoft.Maui.Platform.ContentPanel contentPanel) - { - contentPanel.AutomationActivateCallback = null; - } - if ((_subscriptionFlags & SubscriptionFlags.ContainerDragEventsSubscribed) != 0) { _subscriptionFlags &= ~SubscriptionFlags.ContainerDragEventsSubscribed; @@ -991,41 +986,6 @@ void UpdatingGestureRecognizers() } } - // UI Automation has no built-in Invoke pattern for a plain gesture-only element - // (unlike a native Button). Without this, Narrator can neither invoke the element - // (Enter/Narrator-activate) nor announce "double tap to activate", since that hint - // is auto-generated only for peers that support Invoke. Wire an activate callback - // on the ContentPanel so ContentPanelAutomationPeer/MauiBorderAutomationPeer can - // expose IInvokeProvider (mirrors AccessibilityActivateCallback on iOS's MauiView). - // Decoupled from the tap-subscription block above so it also applies when the - // container only has a child-owned tap gesture reached via bubbling. - if (_container is Microsoft.Maui.Platform.ContentPanel activatablePanel && view is not null && - view.HasAccessibleTapGesture()) - { - var weakThis = new WeakReference(this); - - activatablePanel.AutomationActivateCallback = () => - { - if (!weakThis.TryGetTarget(out var manager) || manager.Element is not View v) - { - return false; - } - - if (!v.IsEnabled || v.InputTransparent) - { - return false; - } - - if (v.HasAccessibleTapGesture(out var tapGestureRecognizer)) - { - tapGestureRecognizer.SendTapped(v); - return true; - } - - return false; - }; - } - if (gestures.HasAnyGesturesFor(g => g.NumberOfTapsRequired == 1 || g.NumberOfTapsRequired == 2) || children?.GetChildGesturesFor(g => g.NumberOfTapsRequired == 1 || g.NumberOfTapsRequired == 2).Any() == true) { diff --git a/src/Core/src/Platform/Windows/ContentPanel.cs b/src/Core/src/Platform/Windows/ContentPanel.cs index 749a72a0144b..7f3ba1235730 100644 --- a/src/Core/src/Platform/Windows/ContentPanel.cs +++ b/src/Core/src/Platform/Windows/ContentPanel.cs @@ -56,32 +56,6 @@ internal FrameworkElement? Content internal bool IsInnerPath { get; private set; } - Func? _automationActivateCallback; - - /// - /// Optional callback invoked by / - /// when UI Automation invokes this element (e.g. Narrator's Enter/double-tap activation). - /// Set by GesturePlatformManager for elements whose only interaction is a TapGestureRecognizer, - /// which otherwise have no native Invoke pattern (mirrors AccessibilityActivateCallback on iOS). - /// - /// - /// Setting this also flips -equivalent keyboard-focusability on - /// (via , which is available on any UIElement, not just Control). - /// ContentPanel derives from Panel, so it isn't keyboard-focusable by default; without this, - /// Narrator's Enter/scan-activate never routes to this peer's IInvokeProvider because the - /// automation peer reports itself as not keyboard-focusable (see IsKeyboardFocusableCore on the - /// peers). This mirrors making a gesture-only element behave like a native focusable control. - /// - internal Func? AutomationActivateCallback - { - get => _automationActivateCallback; - set - { - _automationActivateCallback = value; - IsTabStop = value is not null; - } - } - protected override global::Windows.Foundation.Size MeasureOverride(global::Windows.Foundation.Size availableSize) { var measured = base.MeasureOverride(availableSize); diff --git a/src/Core/src/Platform/Windows/ContentPanelAutomationPeer.cs b/src/Core/src/Platform/Windows/ContentPanelAutomationPeer.cs index e586a6122b50..c465382e2b1f 100644 --- a/src/Core/src/Platform/Windows/ContentPanelAutomationPeer.cs +++ b/src/Core/src/Platform/Windows/ContentPanelAutomationPeer.cs @@ -1,11 +1,10 @@ using System.Collections.Generic; using Microsoft.UI.Xaml.Automation; using Microsoft.UI.Xaml.Automation.Peers; -using Microsoft.UI.Xaml.Automation.Provider; namespace Microsoft.Maui.Platform { - internal partial class ContentPanelAutomationPeer : FrameworkElementAutomationPeer, IInvokeProvider + internal partial class ContentPanelAutomationPeer : FrameworkElementAutomationPeer { internal ContentPanelAutomationPeer(ContentPanel owner) : base(owner) { } @@ -17,49 +16,7 @@ protected override AutomationControlType GetAutomationControlTypeCore() => protected override string GetLocalizedControlTypeCore() => HasDescription ? string.Empty : base.GetLocalizedControlTypeCore() ?? string.Empty; - // Suppress children when this container wraps nothing (Guard 1 — avoids duplicate - // announcement for the common empty wrapper case), or when it owns its own tap gesture, - // i.e. is itself the actionable unit (Guard 2 — mirrors iOS SemanticExtensions.cs). Without - // Guard 2, a tappable ContentView with a single child (e.g. a bound Label) would never - // collapse, so Narrator's cursor lands on the child instead of this peer and never reads its - // HelpText ("Double tap to activate") or discovers its IInvokeProvider. A container with real, - // non-actionable content (e.g. a BindableLayout of independently-focusable items) still keeps - // its children reachable — see #33612. - protected override IList? GetChildrenCore() - { - if (Owner is not ContentPanel panel) - { - return base.GetChildrenCore(); - } - - if (panel.AutomationActivateCallback is not null) - { - return null; - } - - return HasDescription && panel is { CrossPlatformLayout: IContentView { PresentedContent: null } } - ? null - : base.GetChildrenCore(); - } - - // Expose the Invoke pattern only when GesturePlatformManager has wired an activate callback - // (i.e. this element's only interaction is a TapGestureRecognizer). This is what makes - // Narrator announce "double tap to activate" and lets Enter/Narrator-activate fire the tap. - protected override object? GetPatternCore(PatternInterface patternInterface) => - patternInterface == PatternInterface.Invoke && Owner is ContentPanel { AutomationActivateCallback: not null } - ? this - : base.GetPatternCore(patternInterface); - - // ContentPanel derives from Panel, not Control, so it has no native Tab-stop/keyboard focus. - // Report this peer as keyboard-focusable whenever it's activatable so Narrator's Enter-key - // activation routes here instead of being swallowed (mirrors IsTabStop set on ContentPanel - // when AutomationActivateCallback is assigned — see ContentPanel.AutomationActivateCallback). - protected override bool IsKeyboardFocusableCore() => - (Owner as ContentPanel)?.AutomationActivateCallback is not null || base.IsKeyboardFocusableCore(); - - protected override void SetFocusCore() => Owner?.Focus(global::Microsoft.UI.Xaml.FocusState.Programmatic); - - // IInvokeProvider - public void Invoke() => (Owner as ContentPanel)?.AutomationActivateCallback?.Invoke(); + protected override IList? GetChildrenCore() => + HasDescription ? null : base.GetChildrenCore(); } } diff --git a/src/Core/src/Platform/Windows/MauiBorderAutomationPeer.cs b/src/Core/src/Platform/Windows/MauiBorderAutomationPeer.cs index 2d1b2eb40806..6ddbe415578c 100644 --- a/src/Core/src/Platform/Windows/MauiBorderAutomationPeer.cs +++ b/src/Core/src/Platform/Windows/MauiBorderAutomationPeer.cs @@ -1,13 +1,11 @@ -using System.Collections.Generic; -using Microsoft.UI.Xaml.Automation; +using Microsoft.UI.Xaml.Automation; using Microsoft.UI.Xaml.Automation.Peers; -using Microsoft.UI.Xaml.Automation.Provider; using Microsoft.UI.Xaml.Controls; namespace Microsoft.Maui.Platform { // TODO: Make this class public in .NET11.0. Issue Link: https://github.com/dotnet/maui/issues/30205 - internal partial class MauiBorderAutomationPeer : FrameworkElementAutomationPeer, IInvokeProvider + internal partial class MauiBorderAutomationPeer : FrameworkElementAutomationPeer { internal MauiBorderAutomationPeer(ContentPanel owner) : base(owner) { } @@ -73,41 +71,5 @@ protected override bool IsContentElementCore() var accessibilityView = panel.ReadLocalValue(AutomationProperties.AccessibilityViewProperty); return accessibilityView is AccessibilityView.Content; } - - // Once this Border has its own Control-view identity (Name/HelpText/explicit opt-in), treat - // it as a leaf — same as MauiButtonAutomationPeer. Otherwise Narrator's cursor lands on the - // inner content (e.g. a bound Label) instead of the Border, so it never reads this Border's - // HelpText ("Double tap to activate") and never reaches its IInvokeProvider (see #33612). - // Guard against a detached/disposed Owner (e.g. during item recycling) before calling into - // base.GetChildrenCore(), which is not guaranteed to be null-safe in that state. - protected override IList? GetChildrenCore() - { - if (Owner is null) - { - return null; - } - - return IsControlElementCore() ? null : base.GetChildrenCore(); - } - - // Expose the Invoke pattern only when GesturePlatformManager has wired an activate callback - // (i.e. this Border's only interaction is a TapGestureRecognizer). This is what makes - // Narrator announce "double tap to activate" and lets Enter/Narrator-activate fire the tap. - protected override object? GetPatternCore(PatternInterface patternInterface) => - patternInterface == PatternInterface.Invoke && Owner is ContentPanel { AutomationActivateCallback: not null } - ? this - : base.GetPatternCore(patternInterface); - - // ContentPanel derives from Panel, not Control, so it has no native Tab-stop/keyboard focus. - // Report this peer as keyboard-focusable whenever it's activatable so Narrator's Enter-key - // activation routes here instead of being swallowed (mirrors IsTabStop set on ContentPanel - // when AutomationActivateCallback is assigned — see ContentPanel.AutomationActivateCallback). - protected override bool IsKeyboardFocusableCore() => - (Owner as ContentPanel)?.AutomationActivateCallback is not null || base.IsKeyboardFocusableCore(); - - protected override void SetFocusCore() => Owner?.Focus(global::Microsoft.UI.Xaml.FocusState.Programmatic); - - // IInvokeProvider - public void Invoke() => (Owner as ContentPanel)?.AutomationActivateCallback?.Invoke(); } } From 386e5b684f0adf8bdc1378d94456e303b20d11c1 Mon Sep 17 00:00:00 2001 From: SuthiYuvaraj <92777079+SuthiYuvaraj@users.noreply.github.com> Date: Wed, 15 Jul 2026 14:02:33 +0530 Subject: [PATCH 04/62] Fix with bounds --- src/Core/src/Platform/iOS/MauiView.cs | 46 ++++++++++++++----- .../PublicAPI/net-ios/PublicAPI.Unshipped.txt | 11 +++-- .../net-maccatalyst/PublicAPI.Unshipped.txt | 13 ++++-- 3 files changed, 50 insertions(+), 20 deletions(-) diff --git a/src/Core/src/Platform/iOS/MauiView.cs b/src/Core/src/Platform/iOS/MauiView.cs index c30f10a48de5..aeb184b1cd38 100644 --- a/src/Core/src/Platform/iOS/MauiView.cs +++ b/src/Core/src/Platform/iOS/MauiView.cs @@ -1008,27 +1008,51 @@ public override bool AccessibilityActivate() /// Hint for the phantom element. See . internal string? AccessibilityContainerHint { get; set; } - // Informal protocol member, not a virtual property on UIView; override via selector export. - // Returning null matches UIKit's own default (VoiceOver infers elements from subviews). + WeakReference? _accessibilityContainerElementRef; + + public override CGRect Bounds + { + get => base.Bounds; + set + { + var sizeChanged = base.Bounds.Size != value.Size; + base.Bounds = value; + + if (sizeChanged + && _accessibilityContainerElementRef is not null + && _accessibilityContainerElementRef.TryGetTarget(out var element)) + { + element.AccessibilityFrameInContainerSpace = new CGRect(0, 0, value.Width, value.Height); + UIAccessibility.PostNotification(UIAccessibilityPostNotification.LayoutChanged, null); + } + } + } + [Export("accessibilityElements")] - internal virtual NSObject[]? AccessibilityElements + public virtual NSObject[]? AccessibilityElements { get { if (string.IsNullOrEmpty(AccessibilityContainerLabel) && string.IsNullOrEmpty(AccessibilityContainerHint)) { + _accessibilityContainerElementRef = null; return null; } - // UIKit recurses into each entry's own accessibility rules, so children stay reachable. - // Created fresh each call (not cached) to avoid holding an NSObject field on this view. - var containerLabelElement = new UIAccessibilityElement(this) + UIAccessibilityElement? containerLabelElement = null; + if (_accessibilityContainerElementRef?.TryGetTarget(out containerLabelElement) != true + || containerLabelElement is null) { - IsAccessibilityElement = true, - AccessibilityLabel = AccessibilityContainerLabel, - AccessibilityHint = AccessibilityContainerHint, - AccessibilityFrameInContainerSpace = Bounds, - }; + containerLabelElement = new UIAccessibilityElement(this) + { + IsAccessibilityElement = true, + AccessibilityFrameInContainerSpace = new CGRect(0, 0, Bounds.Width, Bounds.Height), + }; + _accessibilityContainerElementRef = new WeakReference(containerLabelElement); + } + + containerLabelElement.AccessibilityLabel = AccessibilityContainerLabel; + containerLabelElement.AccessibilityHint = AccessibilityContainerHint; var elements = new NSObject[Subviews.Length + 1]; elements[0] = containerLabelElement; diff --git a/src/Core/src/PublicAPI/net-ios/PublicAPI.Unshipped.txt b/src/Core/src/PublicAPI/net-ios/PublicAPI.Unshipped.txt index 62d80c13a1e1..1bd85c5c0751 100644 --- a/src/Core/src/PublicAPI/net-ios/PublicAPI.Unshipped.txt +++ b/src/Core/src/PublicAPI/net-ios/PublicAPI.Unshipped.txt @@ -1,18 +1,21 @@ #nullable enable +override Microsoft.Maui.Handlers.EditorHandler.PlatformArrange(Microsoft.Maui.Graphics.Rect rect) -> void override Microsoft.Maui.Handlers.LabelHandler.GetDesiredSize(double widthConstraint, double heightConstraint) -> Microsoft.Maui.Graphics.Size override Microsoft.Maui.Handlers.ShapeViewHandler.GetDesiredSize(double widthConstraint, double heightConstraint) -> Microsoft.Maui.Graphics.Size override Microsoft.Maui.Handlers.StepperHandler.GetDesiredSize(double widthConstraint, double heightConstraint) -> Microsoft.Maui.Graphics.Size override Microsoft.Maui.MauiUIApplicationDelegate.ValidateCommand(UIKit.UICommand! command) -> void override Microsoft.Maui.Platform.MauiTextField.LayoutSubviews() -> void -override Microsoft.Maui.Platform.NoCaretField.LayoutSubviews() -> void override Microsoft.Maui.Platform.MauiTextView.TextAlignment.get -> UIKit.UITextAlignment override Microsoft.Maui.Platform.MauiTextView.TextAlignment.set -> void override Microsoft.Maui.Platform.MauiView.AccessibilityActivate() -> bool override Microsoft.Maui.Platform.MauiView.AccessibilityLabel.get -> string? override Microsoft.Maui.Platform.MauiView.AccessibilityLabel.set -> void +override Microsoft.Maui.Platform.MauiView.Bounds.get -> CoreGraphics.CGRect +override Microsoft.Maui.Platform.MauiView.Bounds.set -> void override Microsoft.Maui.Platform.MauiView.DidUpdateFocus(UIKit.UIFocusUpdateContext! context, UIKit.UIFocusAnimationCoordinator! coordinator) -> void -static Microsoft.Maui.Handlers.RadioButtonHandler.MapBackground(Microsoft.Maui.Handlers.IRadioButtonHandler! handler, Microsoft.Maui.IRadioButton! radioButton) -> void +override Microsoft.Maui.Platform.NoCaretField.LayoutSubviews() -> void +static Microsoft.Maui.Handlers.DatePickerHandler.MapFlowDirection(Microsoft.Maui.Handlers.IDatePickerHandler! handler, Microsoft.Maui.IDatePicker! datePicker) -> void static Microsoft.Maui.Handlers.EditorHandler.MapBackground(Microsoft.Maui.Handlers.IEditorHandler! handler, Microsoft.Maui.IEditor! editor) -> void static Microsoft.Maui.Handlers.EntryHandler.MapBackground(Microsoft.Maui.Handlers.IEntryHandler! handler, Microsoft.Maui.IEntry! entry) -> void -static Microsoft.Maui.Handlers.DatePickerHandler.MapFlowDirection(Microsoft.Maui.Handlers.IDatePickerHandler! handler, Microsoft.Maui.IDatePicker! datePicker) -> void -override Microsoft.Maui.Handlers.EditorHandler.PlatformArrange(Microsoft.Maui.Graphics.Rect rect) -> void +static Microsoft.Maui.Handlers.RadioButtonHandler.MapBackground(Microsoft.Maui.Handlers.IRadioButtonHandler! handler, Microsoft.Maui.IRadioButton! radioButton) -> void +virtual Microsoft.Maui.Platform.MauiView.AccessibilityElements.get -> Foundation.NSObject![]? diff --git a/src/Core/src/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txt b/src/Core/src/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txt index 6f9608ce94f0..1bd85c5c0751 100644 --- a/src/Core/src/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txt +++ b/src/Core/src/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txt @@ -1,18 +1,21 @@ #nullable enable +override Microsoft.Maui.Handlers.EditorHandler.PlatformArrange(Microsoft.Maui.Graphics.Rect rect) -> void override Microsoft.Maui.Handlers.LabelHandler.GetDesiredSize(double widthConstraint, double heightConstraint) -> Microsoft.Maui.Graphics.Size override Microsoft.Maui.Handlers.ShapeViewHandler.GetDesiredSize(double widthConstraint, double heightConstraint) -> Microsoft.Maui.Graphics.Size override Microsoft.Maui.Handlers.StepperHandler.GetDesiredSize(double widthConstraint, double heightConstraint) -> Microsoft.Maui.Graphics.Size override Microsoft.Maui.MauiUIApplicationDelegate.ValidateCommand(UIKit.UICommand! command) -> void +override Microsoft.Maui.Platform.MauiTextField.LayoutSubviews() -> void override Microsoft.Maui.Platform.MauiTextView.TextAlignment.get -> UIKit.UITextAlignment override Microsoft.Maui.Platform.MauiTextView.TextAlignment.set -> void override Microsoft.Maui.Platform.MauiView.AccessibilityActivate() -> bool override Microsoft.Maui.Platform.MauiView.AccessibilityLabel.get -> string? override Microsoft.Maui.Platform.MauiView.AccessibilityLabel.set -> void +override Microsoft.Maui.Platform.MauiView.Bounds.get -> CoreGraphics.CGRect +override Microsoft.Maui.Platform.MauiView.Bounds.set -> void override Microsoft.Maui.Platform.MauiView.DidUpdateFocus(UIKit.UIFocusUpdateContext! context, UIKit.UIFocusAnimationCoordinator! coordinator) -> void -static Microsoft.Maui.Handlers.RadioButtonHandler.MapBackground(Microsoft.Maui.Handlers.IRadioButtonHandler! handler, Microsoft.Maui.IRadioButton! radioButton) -> void +override Microsoft.Maui.Platform.NoCaretField.LayoutSubviews() -> void +static Microsoft.Maui.Handlers.DatePickerHandler.MapFlowDirection(Microsoft.Maui.Handlers.IDatePickerHandler! handler, Microsoft.Maui.IDatePicker! datePicker) -> void static Microsoft.Maui.Handlers.EditorHandler.MapBackground(Microsoft.Maui.Handlers.IEditorHandler! handler, Microsoft.Maui.IEditor! editor) -> void static Microsoft.Maui.Handlers.EntryHandler.MapBackground(Microsoft.Maui.Handlers.IEntryHandler! handler, Microsoft.Maui.IEntry! entry) -> void -static Microsoft.Maui.Handlers.DatePickerHandler.MapFlowDirection(Microsoft.Maui.Handlers.IDatePickerHandler! handler, Microsoft.Maui.IDatePicker! datePicker) -> void -override Microsoft.Maui.Platform.MauiTextField.LayoutSubviews() -> void -override Microsoft.Maui.Platform.NoCaretField.LayoutSubviews() -> void -override Microsoft.Maui.Handlers.EditorHandler.PlatformArrange(Microsoft.Maui.Graphics.Rect rect) -> void +static Microsoft.Maui.Handlers.RadioButtonHandler.MapBackground(Microsoft.Maui.Handlers.IRadioButtonHandler! handler, Microsoft.Maui.IRadioButton! radioButton) -> void +virtual Microsoft.Maui.Platform.MauiView.AccessibilityElements.get -> Foundation.NSObject![]? From 41489f4f9e24a741b216d174f81991db2b886d9e Mon Sep 17 00:00:00 2001 From: SuthiYuvaraj <92777079+SuthiYuvaraj@users.noreply.github.com> Date: Wed, 15 Jul 2026 16:22:32 +0530 Subject: [PATCH 05/62] Fix with Custom Accessibility class --- src/Core/src/Platform/iOS/MauiView.cs | 73 +++++++++++++------ .../src/Platform/iOS/SemanticExtensions.cs | 2 + .../PublicAPI/net-ios/PublicAPI.Unshipped.txt | 11 +-- .../net-maccatalyst/PublicAPI.Unshipped.txt | 13 ++-- 4 files changed, 62 insertions(+), 37 deletions(-) diff --git a/src/Core/src/Platform/iOS/MauiView.cs b/src/Core/src/Platform/iOS/MauiView.cs index aeb184b1cd38..7e44c998dd2b 100644 --- a/src/Core/src/Platform/iOS/MauiView.cs +++ b/src/Core/src/Platform/iOS/MauiView.cs @@ -1008,26 +1008,26 @@ public override bool AccessibilityActivate() /// Hint for the phantom element. See . internal string? AccessibilityContainerHint { get; set; } - WeakReference? _accessibilityContainerElementRef; + /// + /// Cached phantom accessibility element for container semantics. + /// WeakReference avoids NSObject retain-cycle/MEM0002 warnings. + /// + WeakReference? _accessibilityContainerElementRef; - public override CGRect Bounds + /// + /// Clears the cached phantom accessibility element. Call this alongside setting + /// / to null + /// (e.g. when a container is demoted back to a plain leaf in + /// ), so a stale cached element + /// doesn't resurrect with leftover label/hint state if semantics get re-applied later. + /// + internal void ClearAccessibilityContainerElement() { - get => base.Bounds; - set - { - var sizeChanged = base.Bounds.Size != value.Size; - base.Bounds = value; - - if (sizeChanged - && _accessibilityContainerElementRef is not null - && _accessibilityContainerElementRef.TryGetTarget(out var element)) - { - element.AccessibilityFrameInContainerSpace = new CGRect(0, 0, value.Width, value.Height); - UIAccessibility.PostNotification(UIAccessibilityPostNotification.LayoutChanged, null); - } - } + _accessibilityContainerElementRef = null; } + // Exposes the UIKit accessibilityElements selector on MauiView. + // Returning null keeps default platform behavior (VoiceOver infers elements from subviews). [Export("accessibilityElements")] public virtual NSObject[]? AccessibilityElements { @@ -1035,20 +1035,25 @@ public virtual NSObject[]? AccessibilityElements { if (string.IsNullOrEmpty(AccessibilityContainerLabel) && string.IsNullOrEmpty(AccessibilityContainerHint)) { - _accessibilityContainerElementRef = null; + ClearAccessibilityContainerElement(); return null; } - UIAccessibilityElement? containerLabelElement = null; - if (_accessibilityContainerElementRef?.TryGetTarget(out containerLabelElement) != true + // UIKit recurses into each entry's own accessibility rules, so children stay reachable. + // Reuse the same instance across calls so VoiceOver/Accessibility Inspector retain + // identity continuity on whichever element they're currently focused on/inspecting. + if (_accessibilityContainerElementRef?.TryGetTarget(out var containerLabelElement) != true || containerLabelElement is null) { - containerLabelElement = new UIAccessibilityElement(this) + containerLabelElement = new ContainerPhantomAccessibilityElement(this) { + // AccessibilityFrame is computed live from this container's current Bounds on every + // read (see ContainerPhantomAccessibilityElement below) — no frame value is stored + // or manually kept in sync here, so resizes, rotations, and re-layouts are reflected + // automatically without a Bounds override or explicit per-resize notification. IsAccessibilityElement = true, - AccessibilityFrameInContainerSpace = new CGRect(0, 0, Bounds.Width, Bounds.Height), }; - _accessibilityContainerElementRef = new WeakReference(containerLabelElement); + _accessibilityContainerElementRef = new WeakReference(containerLabelElement); } containerLabelElement.AccessibilityLabel = AccessibilityContainerLabel; @@ -1057,8 +1062,32 @@ public virtual NSObject[]? AccessibilityElements var elements = new NSObject[Subviews.Length + 1]; elements[0] = containerLabelElement; Array.Copy(Subviews, 0, elements, 1, Subviews.Length); + return elements; } } + + /// + /// Phantom accessibility element for container label/hint. + /// AccessibilityFrame is computed from current container bounds on each read. + /// + internal class ContainerPhantomAccessibilityElement : UIAccessibilityElement + { + public ContainerPhantomAccessibilityElement(NSObject container) : base(container) { } + + public override CGRect AccessibilityFrame + { + get + { + if (AccessibilityContainer is UIView view) + { + return UIAccessibility.ConvertFrameToScreenCoordinates(view.Bounds, view); + } + + return base.AccessibilityFrame; + } + set => base.AccessibilityFrame = value; + } + } } } diff --git a/src/Core/src/Platform/iOS/SemanticExtensions.cs b/src/Core/src/Platform/iOS/SemanticExtensions.cs index 5700fbf313e4..daa693b9dbc1 100644 --- a/src/Core/src/Platform/iOS/SemanticExtensions.cs +++ b/src/Core/src/Platform/iOS/SemanticExtensions.cs @@ -95,6 +95,7 @@ public static void UpdateSemantics(this UIView platformView, IView view) clearedMauiView.SynthesizeAccessibilityLabelFromChildren = false; clearedMauiView.AccessibilityContainerLabel = null; clearedMauiView.AccessibilityContainerHint = null; + clearedMauiView.ClearAccessibilityContainerElement(); } } @@ -208,6 +209,7 @@ public static void UpdateSemantics(this UIView platformView, IView view) { leafMauiView.AccessibilityContainerLabel = null; leafMauiView.AccessibilityContainerHint = null; + leafMauiView.ClearAccessibilityContainerElement(); } UpdateSemantics(platformView, semantics); diff --git a/src/Core/src/PublicAPI/net-ios/PublicAPI.Unshipped.txt b/src/Core/src/PublicAPI/net-ios/PublicAPI.Unshipped.txt index 1bd85c5c0751..1cd9969f12ff 100644 --- a/src/Core/src/PublicAPI/net-ios/PublicAPI.Unshipped.txt +++ b/src/Core/src/PublicAPI/net-ios/PublicAPI.Unshipped.txt @@ -1,21 +1,18 @@ #nullable enable -override Microsoft.Maui.Handlers.EditorHandler.PlatformArrange(Microsoft.Maui.Graphics.Rect rect) -> void override Microsoft.Maui.Handlers.LabelHandler.GetDesiredSize(double widthConstraint, double heightConstraint) -> Microsoft.Maui.Graphics.Size override Microsoft.Maui.Handlers.ShapeViewHandler.GetDesiredSize(double widthConstraint, double heightConstraint) -> Microsoft.Maui.Graphics.Size override Microsoft.Maui.Handlers.StepperHandler.GetDesiredSize(double widthConstraint, double heightConstraint) -> Microsoft.Maui.Graphics.Size override Microsoft.Maui.MauiUIApplicationDelegate.ValidateCommand(UIKit.UICommand! command) -> void override Microsoft.Maui.Platform.MauiTextField.LayoutSubviews() -> void +override Microsoft.Maui.Platform.NoCaretField.LayoutSubviews() -> void override Microsoft.Maui.Platform.MauiTextView.TextAlignment.get -> UIKit.UITextAlignment override Microsoft.Maui.Platform.MauiTextView.TextAlignment.set -> void override Microsoft.Maui.Platform.MauiView.AccessibilityActivate() -> bool override Microsoft.Maui.Platform.MauiView.AccessibilityLabel.get -> string? override Microsoft.Maui.Platform.MauiView.AccessibilityLabel.set -> void -override Microsoft.Maui.Platform.MauiView.Bounds.get -> CoreGraphics.CGRect -override Microsoft.Maui.Platform.MauiView.Bounds.set -> void override Microsoft.Maui.Platform.MauiView.DidUpdateFocus(UIKit.UIFocusUpdateContext! context, UIKit.UIFocusAnimationCoordinator! coordinator) -> void -override Microsoft.Maui.Platform.NoCaretField.LayoutSubviews() -> void -static Microsoft.Maui.Handlers.DatePickerHandler.MapFlowDirection(Microsoft.Maui.Handlers.IDatePickerHandler! handler, Microsoft.Maui.IDatePicker! datePicker) -> void +static Microsoft.Maui.Handlers.RadioButtonHandler.MapBackground(Microsoft.Maui.Handlers.IRadioButtonHandler! handler, Microsoft.Maui.IRadioButton! radioButton) -> void static Microsoft.Maui.Handlers.EditorHandler.MapBackground(Microsoft.Maui.Handlers.IEditorHandler! handler, Microsoft.Maui.IEditor! editor) -> void static Microsoft.Maui.Handlers.EntryHandler.MapBackground(Microsoft.Maui.Handlers.IEntryHandler! handler, Microsoft.Maui.IEntry! entry) -> void -static Microsoft.Maui.Handlers.RadioButtonHandler.MapBackground(Microsoft.Maui.Handlers.IRadioButtonHandler! handler, Microsoft.Maui.IRadioButton! radioButton) -> void -virtual Microsoft.Maui.Platform.MauiView.AccessibilityElements.get -> Foundation.NSObject![]? +static Microsoft.Maui.Handlers.DatePickerHandler.MapFlowDirection(Microsoft.Maui.Handlers.IDatePickerHandler! handler, Microsoft.Maui.IDatePicker! datePicker) -> void +override Microsoft.Maui.Handlers.EditorHandler.PlatformArrange(Microsoft.Maui.Graphics.Rect rect) -> void \ No newline at end of file diff --git a/src/Core/src/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txt b/src/Core/src/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txt index 1bd85c5c0751..1d2df0f3ca25 100644 --- a/src/Core/src/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txt +++ b/src/Core/src/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txt @@ -1,21 +1,18 @@ #nullable enable -override Microsoft.Maui.Handlers.EditorHandler.PlatformArrange(Microsoft.Maui.Graphics.Rect rect) -> void override Microsoft.Maui.Handlers.LabelHandler.GetDesiredSize(double widthConstraint, double heightConstraint) -> Microsoft.Maui.Graphics.Size override Microsoft.Maui.Handlers.ShapeViewHandler.GetDesiredSize(double widthConstraint, double heightConstraint) -> Microsoft.Maui.Graphics.Size override Microsoft.Maui.Handlers.StepperHandler.GetDesiredSize(double widthConstraint, double heightConstraint) -> Microsoft.Maui.Graphics.Size override Microsoft.Maui.MauiUIApplicationDelegate.ValidateCommand(UIKit.UICommand! command) -> void -override Microsoft.Maui.Platform.MauiTextField.LayoutSubviews() -> void override Microsoft.Maui.Platform.MauiTextView.TextAlignment.get -> UIKit.UITextAlignment override Microsoft.Maui.Platform.MauiTextView.TextAlignment.set -> void override Microsoft.Maui.Platform.MauiView.AccessibilityActivate() -> bool override Microsoft.Maui.Platform.MauiView.AccessibilityLabel.get -> string? override Microsoft.Maui.Platform.MauiView.AccessibilityLabel.set -> void -override Microsoft.Maui.Platform.MauiView.Bounds.get -> CoreGraphics.CGRect -override Microsoft.Maui.Platform.MauiView.Bounds.set -> void override Microsoft.Maui.Platform.MauiView.DidUpdateFocus(UIKit.UIFocusUpdateContext! context, UIKit.UIFocusAnimationCoordinator! coordinator) -> void -override Microsoft.Maui.Platform.NoCaretField.LayoutSubviews() -> void -static Microsoft.Maui.Handlers.DatePickerHandler.MapFlowDirection(Microsoft.Maui.Handlers.IDatePickerHandler! handler, Microsoft.Maui.IDatePicker! datePicker) -> void +static Microsoft.Maui.Handlers.RadioButtonHandler.MapBackground(Microsoft.Maui.Handlers.IRadioButtonHandler! handler, Microsoft.Maui.IRadioButton! radioButton) -> void static Microsoft.Maui.Handlers.EditorHandler.MapBackground(Microsoft.Maui.Handlers.IEditorHandler! handler, Microsoft.Maui.IEditor! editor) -> void static Microsoft.Maui.Handlers.EntryHandler.MapBackground(Microsoft.Maui.Handlers.IEntryHandler! handler, Microsoft.Maui.IEntry! entry) -> void -static Microsoft.Maui.Handlers.RadioButtonHandler.MapBackground(Microsoft.Maui.Handlers.IRadioButtonHandler! handler, Microsoft.Maui.IRadioButton! radioButton) -> void -virtual Microsoft.Maui.Platform.MauiView.AccessibilityElements.get -> Foundation.NSObject![]? +static Microsoft.Maui.Handlers.DatePickerHandler.MapFlowDirection(Microsoft.Maui.Handlers.IDatePickerHandler! handler, Microsoft.Maui.IDatePicker! datePicker) -> void +override Microsoft.Maui.Platform.MauiTextField.LayoutSubviews() -> void +override Microsoft.Maui.Platform.NoCaretField.LayoutSubviews() -> void +override Microsoft.Maui.Handlers.EditorHandler.PlatformArrange(Microsoft.Maui.Graphics.Rect rect) -> void \ No newline at end of file From 1f42a4c1de77dfeeec024401cddf98d6e3f72633 Mon Sep 17 00:00:00 2001 From: SuthiYuvaraj <92777079+SuthiYuvaraj@users.noreply.github.com> Date: Wed, 15 Jul 2026 16:23:18 +0530 Subject: [PATCH 06/62] removed changes in unshipped --- src/Core/src/PublicAPI/net-ios/PublicAPI.Unshipped.txt | 2 +- src/Core/src/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Core/src/PublicAPI/net-ios/PublicAPI.Unshipped.txt b/src/Core/src/PublicAPI/net-ios/PublicAPI.Unshipped.txt index 1cd9969f12ff..62d80c13a1e1 100644 --- a/src/Core/src/PublicAPI/net-ios/PublicAPI.Unshipped.txt +++ b/src/Core/src/PublicAPI/net-ios/PublicAPI.Unshipped.txt @@ -15,4 +15,4 @@ static Microsoft.Maui.Handlers.RadioButtonHandler.MapBackground(Microsoft.Maui.H static Microsoft.Maui.Handlers.EditorHandler.MapBackground(Microsoft.Maui.Handlers.IEditorHandler! handler, Microsoft.Maui.IEditor! editor) -> void static Microsoft.Maui.Handlers.EntryHandler.MapBackground(Microsoft.Maui.Handlers.IEntryHandler! handler, Microsoft.Maui.IEntry! entry) -> void static Microsoft.Maui.Handlers.DatePickerHandler.MapFlowDirection(Microsoft.Maui.Handlers.IDatePickerHandler! handler, Microsoft.Maui.IDatePicker! datePicker) -> void -override Microsoft.Maui.Handlers.EditorHandler.PlatformArrange(Microsoft.Maui.Graphics.Rect rect) -> void \ No newline at end of file +override Microsoft.Maui.Handlers.EditorHandler.PlatformArrange(Microsoft.Maui.Graphics.Rect rect) -> void diff --git a/src/Core/src/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txt b/src/Core/src/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txt index 1d2df0f3ca25..6f9608ce94f0 100644 --- a/src/Core/src/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txt +++ b/src/Core/src/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txt @@ -15,4 +15,4 @@ static Microsoft.Maui.Handlers.EntryHandler.MapBackground(Microsoft.Maui.Handler static Microsoft.Maui.Handlers.DatePickerHandler.MapFlowDirection(Microsoft.Maui.Handlers.IDatePickerHandler! handler, Microsoft.Maui.IDatePicker! datePicker) -> void override Microsoft.Maui.Platform.MauiTextField.LayoutSubviews() -> void override Microsoft.Maui.Platform.NoCaretField.LayoutSubviews() -> void -override Microsoft.Maui.Handlers.EditorHandler.PlatformArrange(Microsoft.Maui.Graphics.Rect rect) -> void \ No newline at end of file +override Microsoft.Maui.Handlers.EditorHandler.PlatformArrange(Microsoft.Maui.Graphics.Rect rect) -> void From 6111a5b4468bd227374d96eca0ece821be51f606 Mon Sep 17 00:00:00 2001 From: SuthiYuvaraj <92777079+SuthiYuvaraj@users.noreply.github.com> Date: Mon, 20 Jul 2026 19:17:45 +0530 Subject: [PATCH 07/62] Update SemanticExtensions.cs --- .../src/Platform/iOS/SemanticExtensions.cs | 31 +++++++++++++------ 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/src/Core/src/Platform/iOS/SemanticExtensions.cs b/src/Core/src/Platform/iOS/SemanticExtensions.cs index daa693b9dbc1..b0463f61bf40 100644 --- a/src/Core/src/Platform/iOS/SemanticExtensions.cs +++ b/src/Core/src/Platform/iOS/SemanticExtensions.cs @@ -93,12 +93,10 @@ public static void UpdateSemantics(this UIView platformView, IView view) if (platformView is MauiView clearedMauiView) { clearedMauiView.SynthesizeAccessibilityLabelFromChildren = false; - clearedMauiView.AccessibilityContainerLabel = null; - clearedMauiView.AccessibilityContainerHint = null; - clearedMauiView.ClearAccessibilityContainerElement(); } } + ClearContainerAccessibility(platformView); return; } @@ -189,6 +187,11 @@ public static void UpdateSemantics(this UIView platformView, IView view) && contentView.PresentedContent is not null && platformView.GestureRecognizers is not { Length: > 0 }) { + // Keep the container's own AccessibilityLabel/Hint set too (even though it never + // becomes the accessibility element itself, IsAccessibilityElement stays false). + // Testing showed VoiceOver's traversal order goes wrong (jumps to the last child + // instead of the first) if these are left nil while a custom accessibilityElements + // array is also returned — so don't treat this assignment as dead code. platformView.AccessibilityLabel = semantics.Description; platformView.AccessibilityHint = semantics.Hint; platformView.IsAccessibilityElement = false; @@ -205,16 +208,26 @@ public static void UpdateSemantics(this UIView platformView, IView view) // Falling through: this container has no content, or owns its own gesture (Guard 2). // Clear any stale phantom label so it doesn't linger once this view becomes a leaf. - if (platformView is MauiView leafMauiView) - { - leafMauiView.AccessibilityContainerLabel = null; - leafMauiView.AccessibilityContainerHint = null; - leafMauiView.ClearAccessibilityContainerElement(); - } + ClearContainerAccessibility(platformView); UpdateSemantics(platformView, semantics); } + /// + /// Clears any phantom container accessibility state (label, hint, and cached phantom + /// element) set by the IContentView container branch above. Shared by both the + /// null-semantics reset path and the fallthrough-to-leaf path so the two don't drift. + /// + static void ClearContainerAccessibility(UIView platformView) + { + if (platformView is MauiView mauiView) + { + mauiView.AccessibilityContainerLabel = null; + mauiView.AccessibilityContainerHint = null; + mauiView.ClearAccessibilityContainerElement(); + } + } + internal static void UpdateSemantics(this UIView platformView, Semantics? semantics) { if (semantics == null) From 0d59d676624d545777a5a6ff9bfb718689dccab5 Mon Sep 17 00:00:00 2001 From: SuthiYuvaraj <92777079+SuthiYuvaraj@users.noreply.github.com> Date: Tue, 21 Jul 2026 18:19:07 +0530 Subject: [PATCH 08/62] Update Issue33612.cs --- .../tests/TestCases.Shared.Tests/Tests/Issues/Issue33612.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue33612.cs b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue33612.cs index 7c8a7cd238cc..1f6233caeca7 100644 --- a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue33612.cs +++ b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue33612.cs @@ -1,3 +1,4 @@ +#if !WINDOWS // Fix is not implemented on Windows yet using NUnit.Framework; using UITest.Appium; using UITest.Core; @@ -40,3 +41,4 @@ public void TappingSuggestionItemStillInvokesItsOwnGesture() Assert.That(tappedItemText, Is.EqualTo("First item")); } } +#endif From 9a88799e23f691b9fe7eb5b0e00a73182944f788 Mon Sep 17 00:00:00 2001 From: SuthiYuvaraj <92777079+SuthiYuvaraj@users.noreply.github.com> Date: Tue, 21 Jul 2026 18:33:16 +0530 Subject: [PATCH 09/62] Update Issue33612.cs --- .../tests/TestCases.Shared.Tests/Tests/Issues/Issue33612.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue33612.cs b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue33612.cs index 1f6233caeca7..5e271d521040 100644 --- a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue33612.cs +++ b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue33612.cs @@ -1,4 +1,4 @@ -#if !WINDOWS // Fix is not implemented on Windows yet +#if !WINDOWS using NUnit.Framework; using UITest.Appium; using UITest.Core; From 964c7ac13403c31a7079dda8b4d05b8791382ae5 Mon Sep 17 00:00:00 2001 From: SuthiYuvaraj <92777079+SuthiYuvaraj@users.noreply.github.com> Date: Mon, 27 Jul 2026 13:46:17 +0530 Subject: [PATCH 10/62] Update SemanticExtensions.cs --- src/Core/src/Platform/iOS/SemanticExtensions.cs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/Core/src/Platform/iOS/SemanticExtensions.cs b/src/Core/src/Platform/iOS/SemanticExtensions.cs index b0463f61bf40..1ecc823f9f55 100644 --- a/src/Core/src/Platform/iOS/SemanticExtensions.cs +++ b/src/Core/src/Platform/iOS/SemanticExtensions.cs @@ -198,8 +198,21 @@ public static void UpdateSemantics(this UIView platformView, IView view) if (platformView is MauiView containerMauiView) { + var labelChanged = containerMauiView.AccessibilityContainerLabel != semantics.Description; + var hintChanged = containerMauiView.AccessibilityContainerHint != semantics.Hint; + containerMauiView.AccessibilityContainerLabel = semantics.Description; containerMauiView.AccessibilityContainerHint = semantics.Hint; + + // When the phantom element's label/hint change at runtime (e.g. via a binding + // update) VoiceOver's accessibility tree cache needs to be invalidated, otherwise + // the updated text is only picked up on the next re-focus. Only post when the + // view is actually in a window — posting off-screen is a no-op that also + // suppresses redundant notifications during initial handler setup. + if ((labelChanged || hintChanged) && platformView.Window is not null) + { + UIAccessibility.PostNotification(UIAccessibilityPostNotification.LayoutChanged, null); + } } UpdateSemanticsHeading(platformView, semantics); From 581457eab60febc08617b051e1a700083682a491 Mon Sep 17 00:00:00 2001 From: SuthiYuvaraj <92777079+SuthiYuvaraj@users.noreply.github.com> Date: Mon, 27 Jul 2026 15:10:03 +0530 Subject: [PATCH 11/62] Update MauiView.cs --- src/Core/src/Platform/iOS/MauiView.cs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/Core/src/Platform/iOS/MauiView.cs b/src/Core/src/Platform/iOS/MauiView.cs index 7e44c998dd2b..0300f9c117c1 100644 --- a/src/Core/src/Platform/iOS/MauiView.cs +++ b/src/Core/src/Platform/iOS/MauiView.cs @@ -1039,6 +1039,20 @@ public virtual NSObject[]? AccessibilityElements return null; } + // Guard 2 (lazy): if native gesture recognizers are now attached, this container is + // itself the actionable unit (a tap gesture was wired up by GesturePlatformManager). + // Evaluating this at getter time — mirroring the SynthesizeAccessibilityLabelFromChildren + // synthesis pattern above — avoids the chicken-and-egg problem where SemanticExtensions' + // Guard 2 runs during the initial MapSemantics pass, before Controls has attached the + // native UIGestureRecognizers. Skipping the phantom here lets UIKit fall back to default + // behavior (Button trait + AccessibilityLabel/Hint on the container itself, as set by + // SemanticExtensions), which is the correct actionable-leaf presentation. + if (GestureRecognizers is { Length: > 0 }) + { + ClearAccessibilityContainerElement(); + return null; + } + // UIKit recurses into each entry's own accessibility rules, so children stay reachable. // Reuse the same instance across calls so VoiceOver/Accessibility Inspector retain // identity continuity on whichever element they're currently focused on/inspecting. From ff82b7d1eb200e002c8d95230b425d8a2839d5a6 Mon Sep 17 00:00:00 2001 From: SuthiYuvaraj <92777079+SuthiYuvaraj@users.noreply.github.com> Date: Mon, 3 Aug 2026 15:24:08 +0530 Subject: [PATCH 12/62] Accessibility issue --- src/Core/src/PublicAPI/net-ios/PublicAPI.Unshipped.txt | 1 + src/Core/src/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txt | 1 + 2 files changed, 2 insertions(+) diff --git a/src/Core/src/PublicAPI/net-ios/PublicAPI.Unshipped.txt b/src/Core/src/PublicAPI/net-ios/PublicAPI.Unshipped.txt index 62d80c13a1e1..63e38bb54a1f 100644 --- a/src/Core/src/PublicAPI/net-ios/PublicAPI.Unshipped.txt +++ b/src/Core/src/PublicAPI/net-ios/PublicAPI.Unshipped.txt @@ -8,6 +8,7 @@ override Microsoft.Maui.Platform.NoCaretField.LayoutSubviews() -> void override Microsoft.Maui.Platform.MauiTextView.TextAlignment.get -> UIKit.UITextAlignment override Microsoft.Maui.Platform.MauiTextView.TextAlignment.set -> void override Microsoft.Maui.Platform.MauiView.AccessibilityActivate() -> bool +virtual Microsoft.Maui.Platform.MauiView.AccessibilityElements.get -> Foundation.NSObject![]? override Microsoft.Maui.Platform.MauiView.AccessibilityLabel.get -> string? override Microsoft.Maui.Platform.MauiView.AccessibilityLabel.set -> void override Microsoft.Maui.Platform.MauiView.DidUpdateFocus(UIKit.UIFocusUpdateContext! context, UIKit.UIFocusAnimationCoordinator! coordinator) -> void diff --git a/src/Core/src/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txt b/src/Core/src/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txt index 6f9608ce94f0..df5fc7e0365b 100644 --- a/src/Core/src/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txt +++ b/src/Core/src/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txt @@ -6,6 +6,7 @@ override Microsoft.Maui.MauiUIApplicationDelegate.ValidateCommand(UIKit.UIComman override Microsoft.Maui.Platform.MauiTextView.TextAlignment.get -> UIKit.UITextAlignment override Microsoft.Maui.Platform.MauiTextView.TextAlignment.set -> void override Microsoft.Maui.Platform.MauiView.AccessibilityActivate() -> bool +virtual Microsoft.Maui.Platform.MauiView.AccessibilityElements.get -> Foundation.NSObject![]? override Microsoft.Maui.Platform.MauiView.AccessibilityLabel.get -> string? override Microsoft.Maui.Platform.MauiView.AccessibilityLabel.set -> void override Microsoft.Maui.Platform.MauiView.DidUpdateFocus(UIKit.UIFocusUpdateContext! context, UIKit.UIFocusAnimationCoordinator! coordinator) -> void From e55fa5b2f192d3dff5b96b5a0536fa80936de35f Mon Sep 17 00:00:00 2001 From: SuthiYuvaraj <92777079+SuthiYuvaraj@users.noreply.github.com> Date: Wed, 5 Aug 2026 11:40:46 +0530 Subject: [PATCH 13/62] Update Issue33612.cs --- .../Tests/Issues/Issue33612.cs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue33612.cs b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue33612.cs index 5e271d521040..dc6fd953d874 100644 --- a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue33612.cs +++ b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue33612.cs @@ -30,13 +30,20 @@ public void ContainerDescriptionDoesNotHideIndividuallyAccessibleItems() public void TappingSuggestionItemStillInvokesItsOwnGesture() { App.WaitForElement("SuggestionsContainer"); - App.WaitForElement("First item"); - - App.Tap("First item"); + var firstItem = App.WaitForElement("First item"); + + if (Device == TestDevice.Mac) + { + var itemBounds = firstItem.GetRect(); + App.TapCoordinates(itemBounds.CenterX(), itemBounds.CenterY()); + } + else + { + App.Tap("First item"); + } App.WaitForElement("OK"); App.Tap("OK"); - var tappedItemText = App.WaitForElement("TappedItemLabel").GetText(); Assert.That(tappedItemText, Is.EqualTo("First item")); } From f1a9303a70ffae8200eecb4a50155b7eaaafd1e5 Mon Sep 17 00:00:00 2001 From: SuthiYuvaraj <92777079+SuthiYuvaraj@users.noreply.github.com> Date: Tue, 18 Aug 2026 19:54:27 +0530 Subject: [PATCH 14/62] Testcase updates --- .../TestCases.HostApp/Issues/Issue33612.cs | 22 +++++++++++-------- .../Tests/Issues/Issue33612.cs | 15 ++++++------- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/src/Controls/tests/TestCases.HostApp/Issues/Issue33612.cs b/src/Controls/tests/TestCases.HostApp/Issues/Issue33612.cs index 6c1ab26fa978..75f6fbe4baa2 100644 --- a/src/Controls/tests/TestCases.HostApp/Issues/Issue33612.cs +++ b/src/Controls/tests/TestCases.HostApp/Issues/Issue33612.cs @@ -5,11 +5,11 @@ namespace Maui.Controls.Sample.Issues; [Issue(IssueTracker.Github, 33612, "Inconsistent Accessibility Behavior Across Platforms - a container with SemanticProperties.Description/Hint should not collapse its independently-accessible children", PlatformAffected.All)] public class Issue33612 : ContentPage { - public ObservableCollection Items { get; } = new() + public ObservableCollection Items { get; } = new() { - "First item", - "Second item", - "Third item" + new SuggestionItem("Item1", "First item"), + new SuggestionItem("Item2", "Second item"), + new SuggestionItem("Item3", "Third item"), }; Label _tappedItemLabel; @@ -55,7 +55,7 @@ DataTemplate CreateItemTemplate() HorizontalOptions = LayoutOptions.Center, VerticalOptions = LayoutOptions.Center }; - label.SetBinding(Label.TextProperty, new Binding(".")); + label.SetBinding(Label.TextProperty, new Binding(nameof(SuggestionItem.Text))); // Each item is its own actionable unit: it owns a gesture recognizer, so it should // remain a normal leaf accessibility element carrying its own Description/Hint, @@ -66,8 +66,10 @@ DataTemplate CreateItemTemplate() Margin = 6, Content = label }; - border.SetBinding(AutomationIdProperty, new Binding(".")); - border.SetBinding(SemanticProperties.DescriptionProperty, new Binding(".")); + // AutomationId is intentionally distinct from the visible text so tests can locate the + // Border unambiguously without matching the inner Label or a phantom accessibility element. + border.SetBinding(AutomationIdProperty, new Binding(nameof(SuggestionItem.AutomationId))); + border.SetBinding(SemanticProperties.DescriptionProperty, new Binding(nameof(SuggestionItem.Text))); SemanticProperties.SetHint(border, "Double tap to activate"); var tapGestureRecognizer = new TapGestureRecognizer(); @@ -80,11 +82,13 @@ DataTemplate CreateItemTemplate() async void OnSuggestionTapped(object sender, TappedEventArgs e) { - if (sender is Border tappedBorder && tappedBorder.BindingContext is string item) + if (sender is Border tappedBorder && tappedBorder.BindingContext is SuggestionItem item) { - _tappedItemLabel.Text = item; + _tappedItemLabel.Text = item.Text; } await DisplayAlert("Suggestion Selected", "is a suggestion tap event", "OK"); } + + public record SuggestionItem(string AutomationId, string Text); } diff --git a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue33612.cs b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue33612.cs index dc6fd953d874..221f0ac745f4 100644 --- a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue33612.cs +++ b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue33612.cs @@ -17,12 +17,11 @@ public void ContainerDescriptionDoesNotHideIndividuallyAccessibleItems() { App.WaitForElement("SuggestionsContainer"); - // Each item must still be individually reachable by automation/accessibility tooling — - // before the fix, a Description/Hint on the outer container collapsed the whole subtree - // into a single opaque element, hiding these nested items entirely. - App.WaitForElement("First item"); - App.WaitForElement("Second item"); - App.WaitForElement("Third item"); + // AutomationIds are intentionally distinct from the visible text so this can't be satisfied + // by the inner Label alone — it proves the Border itself is reachable. + App.WaitForElement("Item1"); + App.WaitForElement("Item2"); + App.WaitForElement("Item3"); } [Test] @@ -30,7 +29,7 @@ public void ContainerDescriptionDoesNotHideIndividuallyAccessibleItems() public void TappingSuggestionItemStillInvokesItsOwnGesture() { App.WaitForElement("SuggestionsContainer"); - var firstItem = App.WaitForElement("First item"); + var firstItem = App.WaitForElement("Item1"); if (Device == TestDevice.Mac) { @@ -39,7 +38,7 @@ public void TappingSuggestionItemStillInvokesItsOwnGesture() } else { - App.Tap("First item"); + App.Tap("Item1"); } App.WaitForElement("OK"); From 64f2e91fb673f48efbcbe908ae854659b51c3c5f Mon Sep 17 00:00:00 2001 From: SuthiYuvaraj <92777079+SuthiYuvaraj@users.noreply.github.com> Date: Tue, 13 Oct 2026 19:05:06 +0530 Subject: [PATCH 15/62] Fix-33612 --- src/Core/src/Platform/iOS/MauiView.cs | 104 ------------------ .../src/Platform/iOS/SemanticExtensions.cs | 66 +++-------- .../PublicAPI/net-ios/PublicAPI.Unshipped.txt | 1 - .../net-maccatalyst/PublicAPI.Unshipped.txt | 1 - 4 files changed, 15 insertions(+), 157 deletions(-) diff --git a/src/Core/src/Platform/iOS/MauiView.cs b/src/Core/src/Platform/iOS/MauiView.cs index 0300f9c117c1..aa48f7f40804 100644 --- a/src/Core/src/Platform/iOS/MauiView.cs +++ b/src/Core/src/Platform/iOS/MauiView.cs @@ -999,109 +999,5 @@ public override bool AccessibilityActivate() return base.AccessibilityActivate(); } - /// - /// Label for a phantom accessibility element announcing this container's own Description - /// as a separate VoiceOver stop (see #33612), without hiding its real children. - /// - internal string? AccessibilityContainerLabel { get; set; } - - /// Hint for the phantom element. See . - internal string? AccessibilityContainerHint { get; set; } - - /// - /// Cached phantom accessibility element for container semantics. - /// WeakReference avoids NSObject retain-cycle/MEM0002 warnings. - /// - WeakReference? _accessibilityContainerElementRef; - - /// - /// Clears the cached phantom accessibility element. Call this alongside setting - /// / to null - /// (e.g. when a container is demoted back to a plain leaf in - /// ), so a stale cached element - /// doesn't resurrect with leftover label/hint state if semantics get re-applied later. - /// - internal void ClearAccessibilityContainerElement() - { - _accessibilityContainerElementRef = null; - } - - // Exposes the UIKit accessibilityElements selector on MauiView. - // Returning null keeps default platform behavior (VoiceOver infers elements from subviews). - [Export("accessibilityElements")] - public virtual NSObject[]? AccessibilityElements - { - get - { - if (string.IsNullOrEmpty(AccessibilityContainerLabel) && string.IsNullOrEmpty(AccessibilityContainerHint)) - { - ClearAccessibilityContainerElement(); - return null; - } - - // Guard 2 (lazy): if native gesture recognizers are now attached, this container is - // itself the actionable unit (a tap gesture was wired up by GesturePlatformManager). - // Evaluating this at getter time — mirroring the SynthesizeAccessibilityLabelFromChildren - // synthesis pattern above — avoids the chicken-and-egg problem where SemanticExtensions' - // Guard 2 runs during the initial MapSemantics pass, before Controls has attached the - // native UIGestureRecognizers. Skipping the phantom here lets UIKit fall back to default - // behavior (Button trait + AccessibilityLabel/Hint on the container itself, as set by - // SemanticExtensions), which is the correct actionable-leaf presentation. - if (GestureRecognizers is { Length: > 0 }) - { - ClearAccessibilityContainerElement(); - return null; - } - - // UIKit recurses into each entry's own accessibility rules, so children stay reachable. - // Reuse the same instance across calls so VoiceOver/Accessibility Inspector retain - // identity continuity on whichever element they're currently focused on/inspecting. - if (_accessibilityContainerElementRef?.TryGetTarget(out var containerLabelElement) != true - || containerLabelElement is null) - { - containerLabelElement = new ContainerPhantomAccessibilityElement(this) - { - // AccessibilityFrame is computed live from this container's current Bounds on every - // read (see ContainerPhantomAccessibilityElement below) — no frame value is stored - // or manually kept in sync here, so resizes, rotations, and re-layouts are reflected - // automatically without a Bounds override or explicit per-resize notification. - IsAccessibilityElement = true, - }; - _accessibilityContainerElementRef = new WeakReference(containerLabelElement); - } - - containerLabelElement.AccessibilityLabel = AccessibilityContainerLabel; - containerLabelElement.AccessibilityHint = AccessibilityContainerHint; - - var elements = new NSObject[Subviews.Length + 1]; - elements[0] = containerLabelElement; - Array.Copy(Subviews, 0, elements, 1, Subviews.Length); - - return elements; - } - } - - /// - /// Phantom accessibility element for container label/hint. - /// AccessibilityFrame is computed from current container bounds on each read. - /// - internal class ContainerPhantomAccessibilityElement : UIAccessibilityElement - { - public ContainerPhantomAccessibilityElement(NSObject container) : base(container) { } - - public override CGRect AccessibilityFrame - { - get - { - if (AccessibilityContainer is UIView view) - { - return UIAccessibility.ConvertFrameToScreenCoordinates(view.Bounds, view); - } - - return base.AccessibilityFrame; - } - set => base.AccessibilityFrame = value; - } - } } } diff --git a/src/Core/src/Platform/iOS/SemanticExtensions.cs b/src/Core/src/Platform/iOS/SemanticExtensions.cs index 1ecc823f9f55..c1f554d9039c 100644 --- a/src/Core/src/Platform/iOS/SemanticExtensions.cs +++ b/src/Core/src/Platform/iOS/SemanticExtensions.cs @@ -96,7 +96,13 @@ public static void UpdateSemantics(this UIView platformView, IView view) } } - ClearContainerAccessibility(platformView); + if (view is IContentView && view is not ILayout) + { + platformView.ShouldGroupAccessibilityChildren = false; + platformView.AccessibilityLabel = null; + platformView.AccessibilityHint = null; + } + return; } @@ -175,70 +181,28 @@ public static void UpdateSemantics(this UIView platformView, IView view) } } - // IContentView containers (ContentView, Border, Frame, etc.) don't get #35590 synthesis. - // Left alone they'd hit the generic UpdateSemantics below and collapse into one leaf, - // hiding children (root cause of #33612). So never collapse them; instead announce - // Description/Hint via a phantom element (MauiView.AccessibilityElements) while keeping - // children reachable. Skip (fall through to a normal leaf) when empty (Guard 1) or when - // the container owns its own gesture recognizer, i.e. is itself the actionable unit - // (Guard 2). + // Non-layout content containers (ContentView, Border, Frame, etc.) with presented content + // should remain containers so their independently accessible children stay reachable. if (view is IContentView contentView && view is not ILayout && contentView.PresentedContent is not null && platformView.GestureRecognizers is not { Length: > 0 }) { - // Keep the container's own AccessibilityLabel/Hint set too (even though it never - // becomes the accessibility element itself, IsAccessibilityElement stays false). - // Testing showed VoiceOver's traversal order goes wrong (jumps to the last child - // instead of the first) if these are left nil while a custom accessibilityElements - // array is also returned — so don't treat this assignment as dead code. platformView.AccessibilityLabel = semantics.Description; platformView.AccessibilityHint = semantics.Hint; platformView.IsAccessibilityElement = false; - - if (platformView is MauiView containerMauiView) - { - var labelChanged = containerMauiView.AccessibilityContainerLabel != semantics.Description; - var hintChanged = containerMauiView.AccessibilityContainerHint != semantics.Hint; - - containerMauiView.AccessibilityContainerLabel = semantics.Description; - containerMauiView.AccessibilityContainerHint = semantics.Hint; - - // When the phantom element's label/hint change at runtime (e.g. via a binding - // update) VoiceOver's accessibility tree cache needs to be invalidated, otherwise - // the updated text is only picked up on the next re-focus. Only post when the - // view is actually in a window — posting off-screen is a no-op that also - // suppresses redundant notifications during initial handler setup. - if ((labelChanged || hintChanged) && platformView.Window is not null) - { - UIAccessibility.PostNotification(UIAccessibilityPostNotification.LayoutChanged, null); - } - } - + platformView.ShouldGroupAccessibilityChildren = true; UpdateSemanticsHeading(platformView, semantics); return; } - // Falling through: this container has no content, or owns its own gesture (Guard 2). - // Clear any stale phantom label so it doesn't linger once this view becomes a leaf. - ClearContainerAccessibility(platformView); - - UpdateSemantics(platformView, semantics); - } - - /// - /// Clears any phantom container accessibility state (label, hint, and cached phantom - /// element) set by the IContentView container branch above. Shared by both the - /// null-semantics reset path and the fallthrough-to-leaf path so the two don't drift. - /// - static void ClearContainerAccessibility(UIView platformView) - { - if (platformView is MauiView mauiView) + if (view is IContentView && view is not ILayout + && platformView.ShouldGroupAccessibilityChildren) { - mauiView.AccessibilityContainerLabel = null; - mauiView.AccessibilityContainerHint = null; - mauiView.ClearAccessibilityContainerElement(); + platformView.ShouldGroupAccessibilityChildren = false; } + + UpdateSemantics(platformView, semantics); } internal static void UpdateSemantics(this UIView platformView, Semantics? semantics) diff --git a/src/Core/src/PublicAPI/net-ios/PublicAPI.Unshipped.txt b/src/Core/src/PublicAPI/net-ios/PublicAPI.Unshipped.txt index 63e38bb54a1f..62d80c13a1e1 100644 --- a/src/Core/src/PublicAPI/net-ios/PublicAPI.Unshipped.txt +++ b/src/Core/src/PublicAPI/net-ios/PublicAPI.Unshipped.txt @@ -8,7 +8,6 @@ override Microsoft.Maui.Platform.NoCaretField.LayoutSubviews() -> void override Microsoft.Maui.Platform.MauiTextView.TextAlignment.get -> UIKit.UITextAlignment override Microsoft.Maui.Platform.MauiTextView.TextAlignment.set -> void override Microsoft.Maui.Platform.MauiView.AccessibilityActivate() -> bool -virtual Microsoft.Maui.Platform.MauiView.AccessibilityElements.get -> Foundation.NSObject![]? override Microsoft.Maui.Platform.MauiView.AccessibilityLabel.get -> string? override Microsoft.Maui.Platform.MauiView.AccessibilityLabel.set -> void override Microsoft.Maui.Platform.MauiView.DidUpdateFocus(UIKit.UIFocusUpdateContext! context, UIKit.UIFocusAnimationCoordinator! coordinator) -> void diff --git a/src/Core/src/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txt b/src/Core/src/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txt index df5fc7e0365b..6f9608ce94f0 100644 --- a/src/Core/src/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txt +++ b/src/Core/src/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txt @@ -6,7 +6,6 @@ override Microsoft.Maui.MauiUIApplicationDelegate.ValidateCommand(UIKit.UIComman override Microsoft.Maui.Platform.MauiTextView.TextAlignment.get -> UIKit.UITextAlignment override Microsoft.Maui.Platform.MauiTextView.TextAlignment.set -> void override Microsoft.Maui.Platform.MauiView.AccessibilityActivate() -> bool -virtual Microsoft.Maui.Platform.MauiView.AccessibilityElements.get -> Foundation.NSObject![]? override Microsoft.Maui.Platform.MauiView.AccessibilityLabel.get -> string? override Microsoft.Maui.Platform.MauiView.AccessibilityLabel.set -> void override Microsoft.Maui.Platform.MauiView.DidUpdateFocus(UIKit.UIFocusUpdateContext! context, UIKit.UIFocusAnimationCoordinator! coordinator) -> void From 7ab5c37012171c0edcb69a2c56dbf7d968f1afa4 Mon Sep 17 00:00:00 2001 From: SuthiYuvaraj Date: Wed, 18 Nov 2026 00:04:42 +0530 Subject: [PATCH 16/62] Update MauiView.cs --- src/Core/src/Platform/iOS/MauiView.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Core/src/Platform/iOS/MauiView.cs b/src/Core/src/Platform/iOS/MauiView.cs index aa48f7f40804..2ba89eb58cf2 100644 --- a/src/Core/src/Platform/iOS/MauiView.cs +++ b/src/Core/src/Platform/iOS/MauiView.cs @@ -998,6 +998,5 @@ public override bool AccessibilityActivate() return base.AccessibilityActivate(); } - } } From dd49a89da126dfb800923a8731cabf68bb0a43f0 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Mon, 30 Nov 2026 22:53:47 +0000 Subject: [PATCH 17/62] Preserve native accessibility defaults on Apple content views Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../Core/VisualElement/VisualElement.iOS.cs | 10 +- .../src/Platform/iOS/SemanticExtensions.cs | 154 +++++++++++++++--- 2 files changed, 135 insertions(+), 29 deletions(-) diff --git a/src/Controls/src/Core/VisualElement/VisualElement.iOS.cs b/src/Controls/src/Core/VisualElement/VisualElement.iOS.cs index 5195d1ae8978..17d549bc6c9e 100644 --- a/src/Controls/src/Core/VisualElement/VisualElement.iOS.cs +++ b/src/Controls/src/Core/VisualElement/VisualElement.iOS.cs @@ -1,7 +1,11 @@ -namespace Microsoft.Maui.Controls +using Microsoft.Maui.Controls.Platform; +using Microsoft.Maui.Platform; + +namespace Microsoft.Maui.Controls { - public partial class VisualElement + public partial class VisualElement : IContentViewAccessibility { - + bool IContentViewAccessibility.HasAccessibleTap => this is View view && view.HasAccessibleTapGesture(); + bool? IContentViewAccessibility.IsInAccessibleTree => AutomationProperties.GetIsInAccessibleTree(this); } } \ No newline at end of file diff --git a/src/Core/src/Platform/iOS/SemanticExtensions.cs b/src/Core/src/Platform/iOS/SemanticExtensions.cs index c1f554d9039c..2e4480120760 100644 --- a/src/Core/src/Platform/iOS/SemanticExtensions.cs +++ b/src/Core/src/Platform/iOS/SemanticExtensions.cs @@ -1,10 +1,21 @@ -using System.Text; +using System.Runtime.CompilerServices; +using System.Text; using UIKit; namespace Microsoft.Maui.Platform { + internal interface IContentViewAccessibility + { + bool HasAccessibleTap { get; } + bool? IsInAccessibleTree { get; } + } + public static partial class SemanticExtensions { + static readonly ConditionalWeakTable s_contentSemanticsDefaults = new(); + static readonly ConditionalWeakTable s_contentRoleDefaults = new(); + const int MaxAccessibleSubviewDepth = 32; + internal static void UpdateSemantics(this UIBarItem platformView, Semantics? semantics) { if (semantics == null) @@ -81,11 +92,17 @@ public static void UpdateSemantics(this UIView platformView, IView view) { var semantics = view?.Semantics; + if (view is IContentView contentView && UsesContentSemantics(platformView, view)) + { + UpdateContentSemantics(platformView, contentView, semantics); + return; + } + // Null semantics (e.g. ClearValue): reverse any previous promotion so the layout // stops announcing stale content and its children become navigable again. if (semantics is null) { - if ((view is ILayout || view is IContentView) && platformView is not UIControl && platformView.IsAccessibilityElement) + if (view is ILayout && platformView is not UIControl && platformView.IsAccessibilityElement) { platformView.IsAccessibilityElement = false; platformView.AccessibilityLabel = null; @@ -96,13 +113,6 @@ public static void UpdateSemantics(this UIView platformView, IView view) } } - if (view is IContentView && view is not ILayout) - { - platformView.ShouldGroupAccessibilityChildren = false; - platformView.AccessibilityLabel = null; - platformView.AccessibilityHint = null; - } - return; } @@ -181,28 +191,117 @@ public static void UpdateSemantics(this UIView platformView, IView view) } } - // Non-layout content containers (ContentView, Border, Frame, etc.) with presented content - // should remain containers so their independently accessible children stay reachable. - if (view is IContentView contentView - && view is not ILayout - && contentView.PresentedContent is not null - && platformView.GestureRecognizers is not { Length: > 0 }) + UpdateSemantics(platformView, semantics); + } + + static void UpdateContentSemantics(UIView platformView, IContentView view, Semantics? semantics) + { + var settings = view as IContentViewAccessibility; + bool? explicitRole = settings?.IsInAccessibleTree; + if (semantics is null || !HasContentSemantics(semantics)) { - platformView.AccessibilityLabel = semantics.Description; - platformView.AccessibilityHint = semantics.Hint; - platformView.IsAccessibilityElement = false; - platformView.ShouldGroupAccessibilityChildren = true; - UpdateSemanticsHeading(platformView, semantics); + if (s_contentSemanticsDefaults.TryGetValue(platformView, out var saved)) + { + saved.Restore(platformView, explicitRole); + s_contentSemanticsDefaults.Remove(platformView); + } + return; } - if (view is IContentView && view is not ILayout - && platformView.ShouldGroupAccessibilityChildren) + var defaults = s_contentSemanticsDefaults.GetValue(platformView, static native => new(native)); + bool groupChildren = explicitRole != true && !semantics.IsHeading + && !defaults.IsAccessibilityElement && !defaults.IsHeading && settings?.HasAccessibleTap != true + && view.PresentedContent is not null && HasAccessibleSubview(platformView, 0); + + platformView.AccessibilityLabel = semantics.Description; + platformView.AccessibilityHint = semantics.Hint; + platformView.IsAccessibilityElement = explicitRole ?? !groupChildren; + platformView.ShouldGroupAccessibilityChildren = groupChildren; + UpdateSemanticsHeading(platformView, semantics.IsHeading || defaults.IsHeading); + } + + static bool UsesContentSemantics(UIView platformView, IView view) => + view is IContentView and not ILayout && platformView is not (UIControl or SemanticSwitchContentView); + + static bool HasContentSemantics(Semantics semantics) => + semantics.IsHeading || !string.IsNullOrWhiteSpace(semantics.Description) || !string.IsNullOrWhiteSpace(semantics.Hint); + + internal static bool RefreshContentSemantics(IViewHandler handler) + { + if (handler.VirtualView is not { } view || handler.PlatformView is not UIView platformView + || !UsesContentSemantics(platformView, view) + || !(view.Semantics is { } semantics && HasContentSemantics(semantics))) + return false; + + handler.UpdateValue(nameof(IView.Semantics)); + return true; + } + + internal static bool MapContentAccessibilityRole(IViewHandler handler, bool? role) + { + if (handler.VirtualView is not { } view || handler.PlatformView is not UIView platformView + || !UsesContentSemantics(platformView, view)) + return false; + + if (role.HasValue && !s_contentRoleDefaults.TryGetValue(platformView, out _)) { - platformView.ShouldGroupAccessibilityChildren = false; + bool originalRole = s_contentSemanticsDefaults.TryGetValue(platformView, out var saved) + ? saved.IsAccessibilityElement : platformView.IsAccessibilityElement; + s_contentRoleDefaults.Add(platformView, new(originalRole)); } - UpdateSemantics(platformView, semantics); + if (!RefreshContentSemantics(handler)) + { + if (role.HasValue) + platformView.IsAccessibilityElement = role.Value; + else if (s_contentRoleDefaults.TryGetValue(platformView, out var saved)) + platformView.IsAccessibilityElement = saved.Value; + } + + if (!role.HasValue) + s_contentRoleDefaults.Remove(platformView); + + return true; + } + + static bool HasAccessibleSubview(UIView platformView, int depth) + { + if (depth >= MaxAccessibleSubviewDepth || platformView.AccessibilityElementsHidden) + return false; + + foreach (var child in platformView.Subviews) + { + if (!child.Hidden && child.Alpha > 0 && !child.AccessibilityElementsHidden + && (child.IsAccessibilityElement || HasAccessibleSubview(child, depth + 1))) + return true; + } + + return false; + } + + sealed class ContentRoleDefault(bool value) + { + public bool Value { get; } = value; + } + + sealed class ContentSemanticsDefaults(UIView platformView) + { + readonly string? _label = platformView.AccessibilityLabel; + readonly string? _hint = platformView.AccessibilityHint; + readonly bool _groupsChildren = platformView.ShouldGroupAccessibilityChildren; + public bool IsAccessibilityElement { get; } = s_contentRoleDefaults.TryGetValue(platformView, out var role) + ? role.Value : platformView.IsAccessibilityElement; + public bool IsHeading { get; } = (platformView.AccessibilityTraits & UIAccessibilityTrait.Header) != 0; + + public void Restore(UIView platformView, bool? explicitRole) + { + platformView.AccessibilityLabel = _label; + platformView.AccessibilityHint = _hint; + platformView.ShouldGroupAccessibilityChildren = _groupsChildren; + platformView.IsAccessibilityElement = explicitRole ?? IsAccessibilityElement; + UpdateSemanticsHeading(platformView, IsHeading); + } } internal static void UpdateSemantics(this UIView platformView, Semantics? semantics) @@ -237,12 +336,15 @@ internal static void UpdateSemantics(this UIView platformView, Semantics? semant UpdateSemanticsHeading(platformView, semantics); } - static void UpdateSemanticsHeading(UIView platformView, Semantics semantics) + static void UpdateSemanticsHeading(UIView platformView, Semantics semantics) => + UpdateSemanticsHeading(platformView, semantics.IsHeading); + + static void UpdateSemanticsHeading(UIView platformView, bool isHeading) { var accessibilityTraits = platformView.AccessibilityTraits; var hasHeader = (accessibilityTraits & UIAccessibilityTrait.Header) == UIAccessibilityTrait.Header; - if (semantics.IsHeading) + if (isHeading) { if (!hasHeader) { From 43f61139bc01623049475674bf2745b6cab8cd38 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Mon, 30 Nov 2026 22:53:53 +0000 Subject: [PATCH 18/62] Refresh Apple content accessibility for eligible tap gestures Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../GestureManager/GesturePlatformManager.iOS.cs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Controls/src/Core/Platform/GestureManager/GesturePlatformManager.iOS.cs b/src/Controls/src/Core/Platform/GestureManager/GesturePlatformManager.iOS.cs index bdf750546762..f613e0da1f0e 100644 --- a/src/Controls/src/Core/Platform/GestureManager/GesturePlatformManager.iOS.cs +++ b/src/Controls/src/Core/Platform/GestureManager/GesturePlatformManager.iOS.cs @@ -889,8 +889,15 @@ _handler.VirtualView is View v && void OnTapGestureRecognizerPropertyChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e) { - if (e.Is(TapGestureRecognizer.ButtonsProperty)) + if ((e.Is(TapGestureRecognizer.ButtonsProperty) || e.Is(TapGestureRecognizer.NumberOfTapsRequiredProperty)) + && Microsoft.Maui.Platform.SemanticExtensions.RefreshContentSemantics(_handler)) + { + GestureRecognizersOnCollectionChanged(null, new(NotifyCollectionChangedAction.Reset)); + } + else if (e.Is(TapGestureRecognizer.ButtonsProperty)) + { LoadRecognizers(); + } } void OnSwipeGestureRecognizerPropertyChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e) @@ -975,6 +982,7 @@ void GestureRecognizersOnCollectionChanged(object? sender, NotifyCollectionChang _addedFlags = UIAccessibilityTrait.None; _defaultAccessibilityRespondsToUserInteraction = null; + Microsoft.Maui.Platform.SemanticExtensions.RefreshContentSemantics(_handler); LoadRecognizers(); } From ede45ddb29b5bdac6b450502fa42d1faf364677b Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Mon, 30 Nov 2026 22:53:54 +0000 Subject: [PATCH 19/62] Refresh Apple accessibility when presented content changes Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- src/Core/src/Handlers/Border/BorderHandler.iOS.cs | 2 ++ src/Core/src/Handlers/ContentView/ContentViewHandler.iOS.cs | 1 + src/Core/src/Handlers/RefreshView/RefreshViewHandler.iOS.cs | 5 ++++- src/Core/src/Handlers/ScrollView/ScrollViewHandler.iOS.cs | 1 + .../src/Handlers/SwipeItemView/SwipeItemViewHandler.iOS.cs | 3 +++ src/Core/src/Handlers/SwipeView/SwipeViewHandler.iOS.cs | 1 + 6 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/Core/src/Handlers/Border/BorderHandler.iOS.cs b/src/Core/src/Handlers/Border/BorderHandler.iOS.cs index 8324f96f6de5..9a87868986bc 100644 --- a/src/Core/src/Handlers/Border/BorderHandler.iOS.cs +++ b/src/Core/src/Handlers/Border/BorderHandler.iOS.cs @@ -68,6 +68,8 @@ static partial void UpdateContent(IBorderHandler handler) platformView.AddSubview(platformContent); } } + + SemanticExtensions.RefreshContentSemantics(handler); } } } \ No newline at end of file diff --git a/src/Core/src/Handlers/ContentView/ContentViewHandler.iOS.cs b/src/Core/src/Handlers/ContentView/ContentViewHandler.iOS.cs index 023a40b2befe..22060131ea6a 100644 --- a/src/Core/src/Handlers/ContentView/ContentViewHandler.iOS.cs +++ b/src/Core/src/Handlers/ContentView/ContentViewHandler.iOS.cs @@ -67,6 +67,7 @@ static void UpdateContent(IContentViewHandler handler) public static partial void MapContent(IContentViewHandler handler, IContentView page) { UpdateContent(handler); + SemanticExtensions.RefreshContentSemantics(handler); } protected override void DisconnectHandler(ContentView platformView) diff --git a/src/Core/src/Handlers/RefreshView/RefreshViewHandler.iOS.cs b/src/Core/src/Handlers/RefreshView/RefreshViewHandler.iOS.cs index 2b441bb65033..cf637659275a 100644 --- a/src/Core/src/Handlers/RefreshView/RefreshViewHandler.iOS.cs +++ b/src/Core/src/Handlers/RefreshView/RefreshViewHandler.iOS.cs @@ -53,7 +53,10 @@ public static void MapIsRefreshing(IRefreshViewHandler handler, IRefreshView ref => handler.PlatformView.IsRefreshing = handler.VirtualView.IsRefreshing; public static void MapContent(IRefreshViewHandler handler, IRefreshView refreshView) - => UpdateContent(handler); + { + UpdateContent(handler); + SemanticExtensions.RefreshContentSemantics(handler); + } public static void MapRefreshColor(IRefreshViewHandler handler, IRefreshView refreshView) => UpdateRefreshColor(handler); diff --git a/src/Core/src/Handlers/ScrollView/ScrollViewHandler.iOS.cs b/src/Core/src/Handlers/ScrollView/ScrollViewHandler.iOS.cs index 05daf0c17cf7..41d18a127078 100644 --- a/src/Core/src/Handlers/ScrollView/ScrollViewHandler.iOS.cs +++ b/src/Core/src/Handlers/ScrollView/ScrollViewHandler.iOS.cs @@ -73,6 +73,7 @@ public static void MapContent(IScrollViewHandler handler, IScrollView scrollView // We'll use the local cross-platform layout methods defined in our handler (which wrap the ScrollView's default methods) // so we can normalize the behavior of the scrollview to match the other platforms UpdateContentView(scrollView, handler); + SemanticExtensions.RefreshContentSemantics(handler); } // We don't actually have this mapped because we don't need it, but we can't remove it because it's public diff --git a/src/Core/src/Handlers/SwipeItemView/SwipeItemViewHandler.iOS.cs b/src/Core/src/Handlers/SwipeItemView/SwipeItemViewHandler.iOS.cs index 4d0dc435bfca..cb2f77960612 100644 --- a/src/Core/src/Handlers/SwipeItemView/SwipeItemViewHandler.iOS.cs +++ b/src/Core/src/Handlers/SwipeItemView/SwipeItemViewHandler.iOS.cs @@ -39,7 +39,10 @@ void UpdateContent() public static void MapContent(ISwipeItemViewHandler handler, ISwipeItemView page) { if (handler is SwipeItemViewHandler platformHandler) + { platformHandler.UpdateContent(); + SemanticExtensions.RefreshContentSemantics(handler); + } } public static void MapVisibility(ISwipeItemViewHandler handler, ISwipeItemView view) diff --git a/src/Core/src/Handlers/SwipeView/SwipeViewHandler.iOS.cs b/src/Core/src/Handlers/SwipeView/SwipeViewHandler.iOS.cs index 3dd5b216a5a3..027c18ac180a 100644 --- a/src/Core/src/Handlers/SwipeView/SwipeViewHandler.iOS.cs +++ b/src/Core/src/Handlers/SwipeView/SwipeViewHandler.iOS.cs @@ -22,6 +22,7 @@ public static void MapContent(ISwipeViewHandler handler, ISwipeView view) _ = handler.VirtualView ?? throw new InvalidOperationException($"{nameof(VirtualView)} should have been set by base class."); handler.PlatformView.UpdateContent(view, handler.MauiContext); + SemanticExtensions.RefreshContentSemantics(handler); } public static void MapIsEnabled(ISwipeViewHandler handler, ISwipeView swipeView) From 7205cb968ecc3671162e378cf995c5fddd631ac3 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Mon, 30 Nov 2026 22:53:54 +0000 Subject: [PATCH 20/62] Honor explicit Apple content accessibility tree settings Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- src/Controls/src/Core/Element/Element.iOS.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Controls/src/Core/Element/Element.iOS.cs b/src/Controls/src/Core/Element/Element.iOS.cs index f9cfd5b7e035..17361b21afce 100644 --- a/src/Controls/src/Core/Element/Element.iOS.cs +++ b/src/Controls/src/Core/Element/Element.iOS.cs @@ -10,6 +10,10 @@ public partial class Element { public static void MapAutomationPropertiesIsInAccessibleTree(IElementHandler handler, Element element) { + if (handler is IViewHandler viewHandler && ReferenceEquals(handler.VirtualView, element) + && Microsoft.Maui.Platform.SemanticExtensions.MapContentAccessibilityRole(viewHandler, AutomationProperties.GetIsInAccessibleTree(element))) + return; + // If the user hasn't set IsInAccessibleTree then just don't do anything if (!element.IsSet(AutomationProperties.IsInAccessibleTreeProperty)) return; From e8cac7157b73dd6333ca71bb48edfd47836e4dfd Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Mon, 30 Nov 2026 22:53:54 +0000 Subject: [PATCH 21/62] Test Apple content accessibility roles and parent semantic text Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../ContentAccessibilityTests.iOS.cs | 176 ++++++++++++++++++ 1 file changed, 176 insertions(+) create mode 100644 src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs diff --git a/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs b/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs new file mode 100644 index 000000000000..262329e2e5e1 --- /dev/null +++ b/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs @@ -0,0 +1,176 @@ +using System.Threading.Tasks; +using Microsoft.Maui.Controls; +using Microsoft.Maui.Handlers; +using UIKit; +using Xunit; + +namespace Microsoft.Maui.DeviceTests; + +[Category(TestCategory.Accessibility)] +public class ContentAccessibilityTests : ControlsHandlerTestBase +{ + [Fact] + public async Task RadioButtonWithoutSemanticTextKeepsNativeAccessibility() + { + var radio = new RadioButton { IsChecked = true }; + var handler = await CreateHandlerAsync(radio); + + await InvokeOnMainThreadAsync(() => + { + Assert.True(handler.PlatformView.IsAccessibilityElement); + Assert.Equal("1", handler.PlatformView.AccessibilityValue); + }); + } + + [Fact] + public async Task OnlyAccessibleTapChangesContentAccessibilityRole() + { + var border = new Border { Content = new Button { Text = "Child action" } }; + SemanticProperties.SetDescription(border, "Actions"); + var handler = await CreateHandlerAsync(border); + + await InvokeOnMainThreadAsync(() => + { + Assert.False(handler.PlatformView.IsAccessibilityElement); + border.GestureRecognizers.Add(new PanGestureRecognizer()); + SemanticProperties.SetDescription(border, "More actions"); + Assert.False(handler.PlatformView.IsAccessibilityElement); + + var tap = new TapGestureRecognizer(); + border.GestureRecognizers.Add(tap); + Assert.True(handler.PlatformView.IsAccessibilityElement); + Assert.False(handler.PlatformView.ShouldGroupAccessibilityChildren); + Assert.True((handler.PlatformView.AccessibilityTraits & UIAccessibilityTrait.Button) != 0); + tap.NumberOfTapsRequired = 2; + Assert.False(handler.PlatformView.IsAccessibilityElement); + Assert.True((handler.PlatformView.AccessibilityTraits & UIAccessibilityTrait.Button) == 0); + tap.NumberOfTapsRequired = 1; + Assert.True(handler.PlatformView.IsAccessibilityElement); + border.GestureRecognizers.Remove(tap); + Assert.False(handler.PlatformView.IsAccessibilityElement); + }); + } + + [Fact] + public async Task DecorativeContentKeepsParentDescriptionFocusable() + { + var view = new ContentView { Content = new BoxView() }; + SemanticProperties.SetDescription(view, "Decorative swatch"); + var handler = await CreateHandlerAsync(view); + + await InvokeOnMainThreadAsync(() => + { + Assert.True(handler.PlatformView.IsAccessibilityElement); + Assert.Equal("Decorative swatch", handler.PlatformView.AccessibilityLabel); + }); + } + + [Fact] + public async Task ReplacingContentRemapsAccessibilityRole() + { + var border = new Border(); + SemanticProperties.SetDescription(border, "Actions"); + var handler = await CreateHandlerAsync(border); + + await InvokeOnMainThreadAsync(() => + { + Assert.True(handler.PlatformView.IsAccessibilityElement); + border.Content = new Button { Text = "Child action" }; + Assert.False(handler.PlatformView.IsAccessibilityElement); + Assert.True(handler.PlatformView.ShouldGroupAccessibilityChildren); + border.Content = null; + Assert.True(handler.PlatformView.IsAccessibilityElement); + Assert.False(handler.PlatformView.ShouldGroupAccessibilityChildren); + Assert.Equal("Actions", handler.PlatformView.AccessibilityLabel); + }); + } + + [Theory] + [InlineData(true)] + [InlineData(false)] + public async Task ExplicitAccessibilityRoleSurvivesSemanticsRemapping(bool include) + { + var view = new ContentView { Content = new Button { Text = "Child action" } }; + SemanticProperties.SetDescription(view, "Actions"); + var handler = await CreateHandlerAsync(view); + + await InvokeOnMainThreadAsync(() => + { + AutomationProperties.SetIsInAccessibleTree(view, include); + Assert.Equal(include, handler.PlatformView.IsAccessibilityElement); + SemanticProperties.SetHint(view, "Choose an action"); + Assert.Equal(include, handler.PlatformView.IsAccessibilityElement); + view.Content = new BoxView(); + Assert.Equal(include, handler.PlatformView.IsAccessibilityElement); + view.ClearValue(AutomationProperties.IsInAccessibleTreeProperty); + Assert.True(handler.PlatformView.IsAccessibilityElement); + view.Content = new Button { Text = "Another child action" }; + Assert.False(handler.PlatformView.IsAccessibilityElement); + Assert.True(handler.PlatformView.ShouldGroupAccessibilityChildren); + }); + } + + [Fact] + public async Task PreconfiguredAccessibilityRoleDoesNotBecomeTheNativeDefault() + { + var view = new ContentView { Content = new Button { Text = "Child action" } }; + AutomationProperties.SetIsInAccessibleTree(view, true); + var handler = await CreateHandlerAsync(view); + + await InvokeOnMainThreadAsync(() => + { + Assert.True(handler.PlatformView.IsAccessibilityElement); + SemanticProperties.SetDescription(view, "Actions"); + view.ClearValue(AutomationProperties.IsInAccessibleTreeProperty); + Assert.False(handler.PlatformView.IsAccessibilityElement); + Assert.True(handler.PlatformView.ShouldGroupAccessibilityChildren); + }); + } + + [Fact] + public async Task GroupedContentKeepsItsOwnSemanticText() + { + var child = new Button { Text = "Child action" }; + var view = new ContentView { Content = child }; + SemanticProperties.SetHint(view, "Choose an action"); + var handler = await CreateHandlerAsync(view); + + await InvokeOnMainThreadAsync(() => + { + var native = handler.PlatformView; + Assert.False(native.IsAccessibilityElement); + Assert.True(native.ShouldGroupAccessibilityChildren); + var nativeChild = Assert.IsAssignableFrom(child.Handler?.PlatformView); + Assert.True(nativeChild.IsAccessibilityElement); + Assert.Null(native.AccessibilityLabel); + Assert.Equal("Choose an action", native.AccessibilityHint); + + SemanticProperties.SetDescription(view, "Actions"); + Assert.Equal("Actions", native.AccessibilityLabel); + view.ClearValue(SemanticProperties.DescriptionProperty); + view.ClearValue(SemanticProperties.HintProperty); + Assert.False(native.ShouldGroupAccessibilityChildren); + Assert.Null(native.AccessibilityLabel); + Assert.Null(native.AccessibilityHint); + + SemanticProperties.SetHint(view, "Choose again"); + Assert.True(native.ShouldGroupAccessibilityChildren); + Assert.Equal("Choose again", native.AccessibilityHint); + }); + } + + [Fact] + public async Task HeadingRetainsAnAccessibleFocusStop() + { + var border = new Border { Content = new Button { Text = "Child action" } }; + SemanticProperties.SetDescription(border, "Actions"); + SemanticProperties.SetHeadingLevel(border, SemanticHeadingLevel.Level1); + var handler = await CreateHandlerAsync(border); + + await InvokeOnMainThreadAsync(() => + { + Assert.True(handler.PlatformView.IsAccessibilityElement); + Assert.True((handler.PlatformView.AccessibilityTraits & UIAccessibilityTrait.Header) != 0); + }); + } +} From 3ff29a467bff7afc3dbb6380c340bc45d660c493 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Tue, 1 Dec 2026 00:23:31 +0000 Subject: [PATCH 22/62] Find accessible primary taps after secondary taps Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../src/Core/Platform/SemanticExtensions.cs | 5 +++-- .../SemanticPropertyUnitTests.cs | 22 +++++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/Controls/src/Core/Platform/SemanticExtensions.cs b/src/Controls/src/Core/Platform/SemanticExtensions.cs index 9ba68c0d569d..fd14a8c43e1b 100644 --- a/src/Controls/src/Core/Platform/SemanticExtensions.cs +++ b/src/Controls/src/Core/Platform/SemanticExtensions.cs @@ -14,10 +14,11 @@ internal static bool HasAccessibleTapGesture( foreach (var gesture in virtualView.GestureRecognizers) { //Accessibility can't handle Tap Recognizers with > 1 tap - if (gesture is TapGestureRecognizer tgr && tgr.NumberOfTapsRequired == 1) + if (gesture is TapGestureRecognizer tgr && tgr.NumberOfTapsRequired == 1 + && (tgr.Buttons & ButtonsMask.Primary) == ButtonsMask.Primary) { tapGestureRecognizer = tgr; - return (tgr.Buttons & ButtonsMask.Primary) == ButtonsMask.Primary; + return true; } } tapGestureRecognizer = null; diff --git a/src/Controls/tests/Core.UnitTests/SemanticPropertyUnitTests.cs b/src/Controls/tests/Core.UnitTests/SemanticPropertyUnitTests.cs index f6e97eb3e2f1..9880178dfbd8 100644 --- a/src/Controls/tests/Core.UnitTests/SemanticPropertyUnitTests.cs +++ b/src/Controls/tests/Core.UnitTests/SemanticPropertyUnitTests.cs @@ -9,6 +9,28 @@ namespace Microsoft.Maui.Controls.Core.UnitTests { public class SemanticPropertyUnitTests : BaseTestFixture { + [Fact] + public void HasAccessibleTapGesture_SecondaryTapDoesNotHideLaterPrimaryTap() + { + var view = new Border(); + view.GestureRecognizers.Add(new TapGestureRecognizer { Buttons = ButtonsMask.Secondary }); + var primary = new TapGestureRecognizer { Buttons = ButtonsMask.Primary }; + view.GestureRecognizers.Add(primary); + + Assert.True(Platform.SemanticExtensions.HasAccessibleTapGesture(view, out var tap)); + Assert.Same(primary, tap); + } + + [Fact] + public void HasAccessibleTapGesture_SecondaryOnlyIsNotAccessible() + { + var view = new Border(); + view.GestureRecognizers.Add(new TapGestureRecognizer { Buttons = ButtonsMask.Secondary }); + view.GestureRecognizers.Add(new TapGestureRecognizer { NumberOfTapsRequired = 2 }); + + Assert.False(Platform.SemanticExtensions.HasAccessibleTapGesture(view, out _)); + } + [Fact] public void FakeBindSemanticProperties_PropertiesPropagate() { From c46c6b4b6c9a5425366dc9f0a7cc6ead8efe19fc Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Tue, 1 Dec 2026 00:23:45 +0000 Subject: [PATCH 23/62] Keep long-press content hosts accessible Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../src/Core/VisualElement/VisualElement.iOS.cs | 3 ++- .../Accessibility/ContentAccessibilityTests.iOS.cs | 10 +++++++++- src/Core/src/Platform/iOS/SemanticExtensions.cs | 4 ++-- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/Controls/src/Core/VisualElement/VisualElement.iOS.cs b/src/Controls/src/Core/VisualElement/VisualElement.iOS.cs index 17d549bc6c9e..2faeb9b249f5 100644 --- a/src/Controls/src/Core/VisualElement/VisualElement.iOS.cs +++ b/src/Controls/src/Core/VisualElement/VisualElement.iOS.cs @@ -5,7 +5,8 @@ namespace Microsoft.Maui.Controls { public partial class VisualElement : IContentViewAccessibility { - bool IContentViewAccessibility.HasAccessibleTap => this is View view && view.HasAccessibleTapGesture(); + bool IContentViewAccessibility.HasAccessibleGesture => + this is View view && (view.HasAccessibleTapGesture() || view.HasAccessibleLongPressGesture()); bool? IContentViewAccessibility.IsInAccessibleTree => AutomationProperties.GetIsInAccessibleTree(this); } } \ No newline at end of file diff --git a/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs b/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs index 262329e2e5e1..8670fc2a5db0 100644 --- a/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs +++ b/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs @@ -23,7 +23,7 @@ await InvokeOnMainThreadAsync(() => } [Fact] - public async Task OnlyAccessibleTapChangesContentAccessibilityRole() + public async Task AccessibleGesturesChangeContentAccessibilityRole() { var border = new Border { Content = new Button { Text = "Child action" } }; SemanticProperties.SetDescription(border, "Actions"); @@ -48,6 +48,14 @@ await InvokeOnMainThreadAsync(() => Assert.True(handler.PlatformView.IsAccessibilityElement); border.GestureRecognizers.Remove(tap); Assert.False(handler.PlatformView.IsAccessibilityElement); + + var longPress = new LongPressGestureRecognizer(); + border.GestureRecognizers.Add(longPress); + Assert.True(handler.PlatformView.IsAccessibilityElement); + Assert.False(handler.PlatformView.ShouldGroupAccessibilityChildren); + Assert.True((handler.PlatformView.AccessibilityTraits & UIAccessibilityTrait.Button) != 0); + border.GestureRecognizers.Remove(longPress); + Assert.False(handler.PlatformView.IsAccessibilityElement); }); } diff --git a/src/Core/src/Platform/iOS/SemanticExtensions.cs b/src/Core/src/Platform/iOS/SemanticExtensions.cs index 79a41973d673..4c6539004ce3 100644 --- a/src/Core/src/Platform/iOS/SemanticExtensions.cs +++ b/src/Core/src/Platform/iOS/SemanticExtensions.cs @@ -7,7 +7,7 @@ namespace Microsoft.Maui.Platform { internal interface IContentViewAccessibility { - bool HasAccessibleTap { get; } + bool HasAccessibleGesture { get; } bool? IsInAccessibleTree { get; } } @@ -220,7 +220,7 @@ static void UpdateContentSemantics(UIView platformView, IContentView view, Seman var defaults = s_contentSemanticsDefaults.GetValue(platformView, static native => new(native)); bool groupChildren = explicitRole != true && !semantics.IsHeading - && !defaults.IsAccessibilityElement && !defaults.IsHeading && settings?.HasAccessibleTap != true + && !defaults.IsAccessibilityElement && !defaults.IsHeading && settings?.HasAccessibleGesture != true && view.PresentedContent is not null && HasAccessibleSubview(platformView, 0); platformView.AccessibilityLabel = semantics.Description; From 89bb1045054c28041a7aabba3e8688b0c2083f4e Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Tue, 1 Dec 2026 00:23:57 +0000 Subject: [PATCH 24/62] Preserve explicit accessibility roles with custom mappers Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../ContentAccessibilityTests.iOS.cs | 28 +++++++++++++++++++ .../src/Platform/iOS/SemanticExtensions.cs | 15 +++++----- 2 files changed, 36 insertions(+), 7 deletions(-) diff --git a/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs b/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs index 8670fc2a5db0..5bdbffac3016 100644 --- a/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs +++ b/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs @@ -135,6 +135,34 @@ await InvokeOnMainThreadAsync(() => }); } + [Fact] + public async Task ReplacementSemanticsMapperDoesNotSuppressExplicitAccessibilityRole() + { + var view = new ContentView { Content = new Button { Text = "Child action" } }; + SemanticProperties.SetDescription(view, "Actions"); + var handler = await CreateHandlerAsync(view); + + await InvokeOnMainThreadAsync(() => + { + Assert.False(handler.PlatformView.IsAccessibilityElement); + AutomationProperties.SetIsInAccessibleTree(view, true); + Assert.True(handler.PlatformView.IsAccessibilityElement); + Assert.Equal("Actions", handler.PlatformView.AccessibilityLabel); + view.ClearValue(AutomationProperties.IsInAccessibleTreeProperty); + Assert.False(handler.PlatformView.IsAccessibilityElement); + }); + } + + sealed class TextOnlyContentViewHandler : ContentViewHandler + { + public TextOnlyContentViewHandler() : base(new PropertyMapper(Mapper) + { + [nameof(IView.Semantics)] = (handler, view) => handler.PlatformView.AccessibilityLabel = view.Semantics?.Description, + }) + { + } + } + [Fact] public async Task GroupedContentKeepsItsOwnSemanticText() { diff --git a/src/Core/src/Platform/iOS/SemanticExtensions.cs b/src/Core/src/Platform/iOS/SemanticExtensions.cs index 4c6539004ce3..80550c5f983e 100644 --- a/src/Core/src/Platform/iOS/SemanticExtensions.cs +++ b/src/Core/src/Platform/iOS/SemanticExtensions.cs @@ -260,16 +260,17 @@ internal static bool MapContentAccessibilityRole(IViewHandler handler, bool? rol s_contentRoleDefaults.Add(platformView, new(originalRole)); } - if (!RefreshContentSemantics(handler)) + if (!role.HasValue && s_contentRoleDefaults.TryGetValue(platformView, out var previousRole)) { - if (role.HasValue) - platformView.IsAccessibilityElement = role.Value; - else if (s_contentRoleDefaults.TryGetValue(platformView, out var saved)) - platformView.IsAccessibilityElement = saved.Value; + platformView.IsAccessibilityElement = previousRole.Value; + s_contentRoleDefaults.Remove(platformView); } - if (!role.HasValue) - s_contentRoleDefaults.Remove(platformView); + RefreshContentSemantics(handler); + + // A replacement Semantics mapping can map the label and hint without applying the role. + if (role.HasValue) + platformView.IsAccessibilityElement = role.Value; return true; } From fc303736357242f94b044a59d34e8c90568af730 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Tue, 1 Dec 2026 00:24:23 +0000 Subject: [PATCH 25/62] Route native accessibility activation to content taps Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../GesturePlatformManager.iOS.cs | 84 ++++++++----------- .../ContentAccessibilityTests.iOS.cs | 23 +++++ .../src/Platform/iOS/SemanticExtensions.cs | 2 +- 3 files changed, 57 insertions(+), 52 deletions(-) diff --git a/src/Controls/src/Core/Platform/GestureManager/GesturePlatformManager.iOS.cs b/src/Controls/src/Core/Platform/GestureManager/GesturePlatformManager.iOS.cs index 6e951878fac9..3a296ad34014 100644 --- a/src/Controls/src/Core/Platform/GestureManager/GesturePlatformManager.iOS.cs +++ b/src/Controls/src/Core/Platform/GestureManager/GesturePlatformManager.iOS.cs @@ -768,6 +768,7 @@ void LoadRecognizers() bool dragFound = false; bool dropFound = false; + bool addedButtonTrait = false; if (PlatformView != null && _handler.VirtualView is View v && (v.HasAccessibleTapGesture() || v.HasAccessibleLongPressGesture()) && @@ -775,6 +776,7 @@ _handler.VirtualView is View v && { PlatformView.AccessibilityTraits |= UIAccessibilityTrait.Button; _addedFlags |= UIAccessibilityTrait.Button; + addedButtonTrait = true; // Ensure container views are marked as accessibility elements so VoiceOver // can announce the Button trait and make the container focusable for VoiceOver. @@ -801,57 +803,6 @@ _handler.VirtualView is View v && _setShouldGroupAccessibilityChildren = true; } - // UIKit's default accessibilityActivate() simulates touch events which are intermittently - // unreliable for UITapGestureRecognizer (especially on macOS Catalyst Ctrl+Option+Space). - // Bypass that path by directly invoking SendTapped on the MAUI TapGestureRecognizer for - // both iOS and Catalyst. VoiceOver activation is a single semantic event — UIKit's - // simulated-touch path also does not honor NumberOfTapsRequired > 1 from a VoiceOver - // activation, so the direct path does not regress that scenario and makes activation - // reliable across both platforms. - // This block is decoupled from the grouping block above so it also registers when - // SemanticExtensions already promoted the container (layout with Hint + gesture). - // Note: Only Microsoft.Maui.Platform.MauiView exposes AccessibilityActivateCallback, - // so layouts whose platform view is not a MauiView (e.g. Border, ScrollView, custom - // container handlers) fall back to UIKit's default simulated-touch activation path. - if (PlatformView is Microsoft.Maui.Platform.MauiView mauiView && - _handler.VirtualView is global::Microsoft.Maui.ILayout) - { - var weakThis = new WeakReference(this); - - mauiView.AccessibilityActivateCallback = () => - { - if (!weakThis.TryGetTarget(out var manager)) - { - return false; - } - - var view = manager._handler?.VirtualView as View; - - if (view is null) - { - return false; - } - - // Honor the same gates UIKit's touch dispatch would have applied. VoiceOver - // activation bypasses UIKit's hit-testing/touch path, so without these - // guards a disabled or input-transparent layout would still fire its tap. - if (!view.IsEnabled || view.InputTransparent) - { - return false; - } - - if (view.HasAccessibleTapGesture(out var tap)) - { - tap.SendTapped(view); - return true; - } - - return false; - }; - - _setAccessibilityActivateCallback = true; - } - if (OperatingSystem.IsIOSVersionAtLeast(13) || OperatingSystem.IsMacCatalystVersionAtLeast(13) #if TVOS || OperatingSystem.IsTvOSVersionAtLeast(11) @@ -863,6 +814,17 @@ _handler.VirtualView is View v && } } + if (!_setAccessibilityActivateCallback && + PlatformView is Microsoft.Maui.Platform.MauiView mauiView && + _handler.VirtualView is View activatableView && + (activatableView is global::Microsoft.Maui.ILayout + ? addedButtonTrait + : Microsoft.Maui.Platform.SemanticExtensions.UsesContentSemantics(mauiView, activatableView) + && activatableView.HasAccessibleTapGesture())) + { + ConnectAccessibilityActivateCallback(mauiView); + } + _interactions.Clear(); for (int i = 0; i < ElementGestureRecognizers.Count; i++) @@ -1013,6 +975,26 @@ _handler.VirtualView is View v && } } + void ConnectAccessibilityActivateCallback(Microsoft.Maui.Platform.MauiView mauiView) + { + // UIKit's simulated-touch activation is unreliable for tap recognizers on Mac Catalyst. + var weakThis = new WeakReference(this); + mauiView.AccessibilityActivateCallback = () => + { + if (!weakThis.TryGetTarget(out var manager) || + manager._handler.VirtualView is not View view || !view.IsEnabled || view.InputTransparent || + (view is not global::Microsoft.Maui.ILayout && manager.PlatformView?.IsAccessibilityElement != true) || + !view.HasAccessibleTapGesture(out var tap)) + { + return false; + } + + tap.SendTapped(view); + return true; + }; + _setAccessibilityActivateCallback = true; + } + void OnTapGestureRecognizerPropertyChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e) { if ((e.Is(TapGestureRecognizer.ButtonsProperty) || e.Is(TapGestureRecognizer.NumberOfTapsRequiredProperty)) diff --git a/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs b/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs index 5bdbffac3016..f1e8a3e45512 100644 --- a/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs +++ b/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs @@ -135,6 +135,29 @@ await InvokeOnMainThreadAsync(() => }); } + [Fact] + public async Task AccessibilityActivateInvokesBorderTap() + { + var border = new Border { Content = new Label { Text = "Action" } }; + SemanticProperties.SetDescription(border, "Action"); + var tap = new TapGestureRecognizer(); + int taps = 0; + tap.Tapped += (sender, _) => + { + Assert.Same(border, sender); + taps++; + }; + border.GestureRecognizers.Add(tap); + + var handler = await CreateHandlerAsync(border); + await InvokeOnMainThreadAsync(() => + { + Assert.True(handler.PlatformView.IsAccessibilityElement); + Assert.True(handler.PlatformView.AccessibilityActivate()); + Assert.Equal(1, taps); + }); + } + [Fact] public async Task ReplacementSemanticsMapperDoesNotSuppressExplicitAccessibilityRole() { diff --git a/src/Core/src/Platform/iOS/SemanticExtensions.cs b/src/Core/src/Platform/iOS/SemanticExtensions.cs index 80550c5f983e..50b3a0daabe1 100644 --- a/src/Core/src/Platform/iOS/SemanticExtensions.cs +++ b/src/Core/src/Platform/iOS/SemanticExtensions.cs @@ -230,7 +230,7 @@ static void UpdateContentSemantics(UIView platformView, IContentView view, Seman UpdateSemanticsHeading(platformView, semantics.IsHeading || defaults.IsHeading); } - static bool UsesContentSemantics(UIView platformView, IView view) => + internal static bool UsesContentSemantics(UIView platformView, IView view) => view is IContentView and not ILayout && platformView is not (UIControl or SemanticSwitchContentView); static bool HasContentSemantics(Semantics semantics) => From b05e3554321dc0e8c038ea15c3974cf0fc79b91e Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Tue, 1 Dec 2026 00:25:43 +0000 Subject: [PATCH 26/62] Refresh content accessibility roles after nested changes Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- src/Controls/src/Core/Element/Element.iOS.cs | 2 + .../Handlers/Items/iOS/MauiCollectionView.cs | 2 + .../ContentAccessibilityTests.iOS.cs | 49 ++++++++++++++ .../src/Handlers/Border/BorderHandler.iOS.cs | 2 +- .../ContentView/ContentViewHandler.iOS.cs | 2 +- .../src/Handlers/Layout/LayoutHandler.iOS.cs | 6 ++ .../RefreshView/RefreshViewHandler.iOS.cs | 2 +- .../ScrollView/ScrollViewHandler.iOS.cs | 2 +- .../SwipeItemView/SwipeItemViewHandler.iOS.cs | 2 +- .../SwipeView/SwipeViewHandler.iOS.cs | 2 +- src/Core/src/Handlers/View/ViewHandler.cs | 13 ++++ .../src/Platform/iOS/SemanticExtensions.cs | 64 +++++++++++++++++-- 12 files changed, 136 insertions(+), 12 deletions(-) diff --git a/src/Controls/src/Core/Element/Element.iOS.cs b/src/Controls/src/Core/Element/Element.iOS.cs index 17361b21afce..1b0bab319d4a 100644 --- a/src/Controls/src/Core/Element/Element.iOS.cs +++ b/src/Controls/src/Core/Element/Element.iOS.cs @@ -32,6 +32,7 @@ public static void MapAutomationPropertiesIsInAccessibleTree(IElementHandler han var _defaultIsAccessibilityElement = Control.IsAccessibilityElement || Control is UIControl; Control.IsAccessibilityElement = (bool)((bool?)element.GetValue(AutomationProperties.IsInAccessibleTreeProperty) ?? _defaultIsAccessibilityElement); + Microsoft.Maui.Platform.SemanticExtensions.RefreshAncestorContentRoles(Control); } public static void MapAutomationPropertiesExcludedWithChildren(IElementHandler handler, Element view) @@ -43,6 +44,7 @@ public static void MapAutomationPropertiesExcludedWithChildren(IElementHandler h var _defaultAccessibilityElementsHidden = Control.AccessibilityElementsHidden || Control is UIControl; Control.AccessibilityElementsHidden = (bool)((bool?)view.GetValue(AutomationProperties.ExcludedWithChildrenProperty) ?? _defaultAccessibilityElementsHidden); + Microsoft.Maui.Platform.SemanticExtensions.RefreshAncestorContentRoles(Control); } static void MapAutomationPropertiesIsInAccessibleTree(IElementHandler handler, IElement element) diff --git a/src/Controls/src/Core/Handlers/Items/iOS/MauiCollectionView.cs b/src/Controls/src/Core/Handlers/Items/iOS/MauiCollectionView.cs index 592887a2510e..046bf62dbffc 100644 --- a/src/Controls/src/Core/Handlers/Items/iOS/MauiCollectionView.cs +++ b/src/Controls/src/Core/Handlers/Items/iOS/MauiCollectionView.cs @@ -239,6 +239,8 @@ public override void AddSubview(UIView view) public override void LayoutSubviews() { base.LayoutSubviews(); + // Deferred cells may not be attached until UIKit lays out the collection. + Microsoft.Maui.Platform.SemanticExtensions.RefreshAncestorContentRoles(this); if (_isSwipeEnabled.HasValue) { diff --git a/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs b/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs index f1e8a3e45512..4c72aff3a726 100644 --- a/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs +++ b/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs @@ -3,10 +3,12 @@ using Microsoft.Maui.Handlers; using UIKit; using Xunit; +using static Microsoft.Maui.DeviceTests.AssertHelpers; namespace Microsoft.Maui.DeviceTests; [Category(TestCategory.Accessibility)] +[Collection(ControlsHandlerTestBase.RunInNewWindowCollection)] public class ContentAccessibilityTests : ControlsHandlerTestBase { [Fact] @@ -93,6 +95,53 @@ await InvokeOnMainThreadAsync(() => }); } + [Fact] + public async Task NestedVisibilityAndChildMutationsRemapAccessibilityRole() + { + var button = new Button { Text = "Child action" }; + var layout = new VerticalStackLayout { Children = { button } }; + var border = new Border { Content = layout }; + SemanticProperties.SetDescription(border, "Actions"); + var handler = await CreateHandlerAsync(border); + + await InvokeOnMainThreadAsync(() => + { + Assert.False(handler.PlatformView.IsAccessibilityElement); + button.IsVisible = false; + Assert.True(handler.PlatformView.IsAccessibilityElement); + button.IsVisible = true; + Assert.False(handler.PlatformView.IsAccessibilityElement); + button.Opacity = 0; + Assert.True(handler.PlatformView.IsAccessibilityElement); + button.Opacity = 1; + Assert.False(handler.PlatformView.IsAccessibilityElement); + layout.Clear(); + Assert.True(handler.PlatformView.IsAccessibilityElement); + layout.Add(button); + Assert.False(handler.PlatformView.IsAccessibilityElement); + }); + } + + [Fact] + public async Task DeferredCollectionItemsRemapAncestorAccessibilityRole() + { + var collection = new CollectionView + { + ItemTemplate = new DataTemplate(() => new Button { Text = "Child action", HeightRequest = 44 }), + }; + var border = new Border { Content = collection, HeightRequest = 120, WidthRequest = 120 }; + SemanticProperties.SetDescription(border, "Actions"); + + await CreateHandlerAndAddToWindow(border, async handler => + { + Assert.True(handler.PlatformView.IsAccessibilityElement); + collection.ItemsSource = new[] { "Action" }; + + await AssertEventually(() => !handler.PlatformView.IsAccessibilityElement && + handler.PlatformView.ShouldGroupAccessibilityChildren, timeout: 5000); + }); + } + [Theory] [InlineData(true)] [InlineData(false)] diff --git a/src/Core/src/Handlers/Border/BorderHandler.iOS.cs b/src/Core/src/Handlers/Border/BorderHandler.iOS.cs index 9a87868986bc..b1f8448bdd8d 100644 --- a/src/Core/src/Handlers/Border/BorderHandler.iOS.cs +++ b/src/Core/src/Handlers/Border/BorderHandler.iOS.cs @@ -69,7 +69,7 @@ static partial void UpdateContent(IBorderHandler handler) } } - SemanticExtensions.RefreshContentSemantics(handler); + SemanticExtensions.ContentChanged(handler); } } } \ No newline at end of file diff --git a/src/Core/src/Handlers/ContentView/ContentViewHandler.iOS.cs b/src/Core/src/Handlers/ContentView/ContentViewHandler.iOS.cs index 22060131ea6a..4b4a07c65353 100644 --- a/src/Core/src/Handlers/ContentView/ContentViewHandler.iOS.cs +++ b/src/Core/src/Handlers/ContentView/ContentViewHandler.iOS.cs @@ -67,7 +67,7 @@ static void UpdateContent(IContentViewHandler handler) public static partial void MapContent(IContentViewHandler handler, IContentView page) { UpdateContent(handler); - SemanticExtensions.RefreshContentSemantics(handler); + SemanticExtensions.ContentChanged(handler); } protected override void DisconnectHandler(ContentView platformView) diff --git a/src/Core/src/Handlers/Layout/LayoutHandler.iOS.cs b/src/Core/src/Handlers/Layout/LayoutHandler.iOS.cs index 385375633e2b..90e6d0baf83a 100644 --- a/src/Core/src/Handlers/Layout/LayoutHandler.iOS.cs +++ b/src/Core/src/Handlers/Layout/LayoutHandler.iOS.cs @@ -40,6 +40,7 @@ public override void SetVirtualView(IView view) } PlatformView.InvalidateAncestorsMeasures(); + SemanticExtensions.RefreshAncestorContentRoles(PlatformView); } public void Add(IView child) @@ -58,6 +59,7 @@ public void Add(IView child) } PlatformView.InvalidateAncestorsMeasures(); + SemanticExtensions.RefreshAncestorContentRoles(PlatformView); } public void Remove(IView child) @@ -71,12 +73,14 @@ public void Remove(IView child) } PlatformView.InvalidateAncestorsMeasures(); + SemanticExtensions.RefreshAncestorContentRoles(PlatformView); } public void Clear() { PlatformView.ClearSubviews(); PlatformView.InvalidateAncestorsMeasures(); + SemanticExtensions.RefreshAncestorContentRoles(PlatformView); } public void Insert(int index, IView child) @@ -95,6 +99,7 @@ public void Insert(int index, IView child) } PlatformView.InvalidateAncestorsMeasures(); + SemanticExtensions.RefreshAncestorContentRoles(PlatformView); } public void Update(int index, IView child) @@ -109,6 +114,7 @@ public void Update(int index, IView child) PlatformView.InsertSubview(child.ToPlatform(MauiContext), targetIndex); PlatformView.SetNeedsLayout(); PlatformView.InvalidateAncestorsMeasures(); + SemanticExtensions.RefreshAncestorContentRoles(PlatformView); } public void UpdateZIndex(IView child) diff --git a/src/Core/src/Handlers/RefreshView/RefreshViewHandler.iOS.cs b/src/Core/src/Handlers/RefreshView/RefreshViewHandler.iOS.cs index 336877e1c3af..e4fafe377b7a 100644 --- a/src/Core/src/Handlers/RefreshView/RefreshViewHandler.iOS.cs +++ b/src/Core/src/Handlers/RefreshView/RefreshViewHandler.iOS.cs @@ -55,7 +55,7 @@ public static void MapIsRefreshing(IRefreshViewHandler handler, IRefreshView ref public static void MapContent(IRefreshViewHandler handler, IRefreshView refreshView) { UpdateContent(handler); - SemanticExtensions.RefreshContentSemantics(handler); + SemanticExtensions.ContentChanged(handler); } public static void MapRefreshColor(IRefreshViewHandler handler, IRefreshView refreshView) diff --git a/src/Core/src/Handlers/ScrollView/ScrollViewHandler.iOS.cs b/src/Core/src/Handlers/ScrollView/ScrollViewHandler.iOS.cs index 6c2639d014e9..72f290e8d014 100644 --- a/src/Core/src/Handlers/ScrollView/ScrollViewHandler.iOS.cs +++ b/src/Core/src/Handlers/ScrollView/ScrollViewHandler.iOS.cs @@ -136,7 +136,7 @@ public static void MapContent(IScrollViewHandler handler, IScrollView scrollView // We'll use the local cross-platform layout methods defined in our handler (which wrap the ScrollView's default methods) // so we can normalize the behavior of the scrollview to match the other platforms UpdateContentView(scrollView, handler); - SemanticExtensions.RefreshContentSemantics(handler); + SemanticExtensions.ContentChanged(handler); } // We don't actually have this mapped because we don't need it, but we can't remove it because it's public diff --git a/src/Core/src/Handlers/SwipeItemView/SwipeItemViewHandler.iOS.cs b/src/Core/src/Handlers/SwipeItemView/SwipeItemViewHandler.iOS.cs index cb2f77960612..22579f57a194 100644 --- a/src/Core/src/Handlers/SwipeItemView/SwipeItemViewHandler.iOS.cs +++ b/src/Core/src/Handlers/SwipeItemView/SwipeItemViewHandler.iOS.cs @@ -41,7 +41,7 @@ public static void MapContent(ISwipeItemViewHandler handler, ISwipeItemView page if (handler is SwipeItemViewHandler platformHandler) { platformHandler.UpdateContent(); - SemanticExtensions.RefreshContentSemantics(handler); + SemanticExtensions.ContentChanged(handler); } } diff --git a/src/Core/src/Handlers/SwipeView/SwipeViewHandler.iOS.cs b/src/Core/src/Handlers/SwipeView/SwipeViewHandler.iOS.cs index 027c18ac180a..59e72fc08f30 100644 --- a/src/Core/src/Handlers/SwipeView/SwipeViewHandler.iOS.cs +++ b/src/Core/src/Handlers/SwipeView/SwipeViewHandler.iOS.cs @@ -22,7 +22,7 @@ public static void MapContent(ISwipeViewHandler handler, ISwipeView view) _ = handler.VirtualView ?? throw new InvalidOperationException($"{nameof(VirtualView)} should have been set by base class."); handler.PlatformView.UpdateContent(view, handler.MauiContext); - SemanticExtensions.RefreshContentSemantics(handler); + SemanticExtensions.ContentChanged(handler); } public static void MapIsEnabled(ISwipeViewHandler handler, ISwipeView swipeView) diff --git a/src/Core/src/Handlers/View/ViewHandler.cs b/src/Core/src/Handlers/View/ViewHandler.cs index 7999914d7642..dec42c82748f 100644 --- a/src/Core/src/Handlers/View/ViewHandler.cs +++ b/src/Core/src/Handlers/View/ViewHandler.cs @@ -514,6 +514,10 @@ public static void MapVisibility(IViewHandler handler, IView view) #endif ((PlatformView?)handler.PlatformView)?.UpdateVisibility(view); +#if __IOS__ || MACCATALYST + if (handler.PlatformView is PlatformView platformView) + SemanticExtensions.RefreshAncestorContentRoles(platformView); +#endif } /// @@ -583,6 +587,11 @@ public static void MapOpacity(IViewHandler handler, IView view) } else ((PlatformView?)handler.PlatformView)?.UpdateOpacity(view); + +#if __IOS__ || MACCATALYST + if (handler.PlatformView is PlatformView platformView) + SemanticExtensions.RefreshAncestorContentRoles(platformView); +#endif } /// @@ -647,6 +656,10 @@ public static void MapSemantics(IViewHandler handler, IView view) { MappingSemantics(handler, view); ((PlatformView?)handler.PlatformView)?.UpdateSemantics(view); +#if __IOS__ || MACCATALYST + if (handler.PlatformView is PlatformView platformView) + SemanticExtensions.RefreshAncestorContentRoles(platformView); +#endif } /// diff --git a/src/Core/src/Platform/iOS/SemanticExtensions.cs b/src/Core/src/Platform/iOS/SemanticExtensions.cs index 50b3a0daabe1..3659ba7bbceb 100644 --- a/src/Core/src/Platform/iOS/SemanticExtensions.cs +++ b/src/Core/src/Platform/iOS/SemanticExtensions.cs @@ -219,17 +219,43 @@ static void UpdateContentSemantics(UIView platformView, IContentView view, Seman } var defaults = s_contentSemanticsDefaults.GetValue(platformView, static native => new(native)); - bool groupChildren = explicitRole != true && !semantics.IsHeading - && !defaults.IsAccessibilityElement && !defaults.IsHeading && settings?.HasAccessibleGesture != true - && view.PresentedContent is not null && HasAccessibleSubview(platformView, 0); - + defaults.SetContent(view, semantics.IsHeading); platformView.AccessibilityLabel = semantics.Description; platformView.AccessibilityHint = semantics.Hint; - platformView.IsAccessibilityElement = explicitRole ?? !groupChildren; - platformView.ShouldGroupAccessibilityChildren = groupChildren; + ApplyContentRole(platformView, view, defaults); UpdateSemanticsHeading(platformView, semantics.IsHeading || defaults.IsHeading); } + static void ApplyContentRole(UIView platformView, IContentView view, ContentSemanticsDefaults defaults) + { + var settings = view as IContentViewAccessibility; + bool? explicitRole = settings?.IsInAccessibleTree; + bool groupChildren = explicitRole != true && !defaults.HasSemanticHeading + && !defaults.IsAccessibilityElement && !defaults.IsHeading && settings?.HasAccessibleGesture != true + && view.PresentedContent is not null && HasAccessibleSubview(platformView, 0); + + var isElement = explicitRole ?? !groupChildren; + if (platformView.IsAccessibilityElement != isElement) + platformView.IsAccessibilityElement = isElement; + if (platformView.ShouldGroupAccessibilityChildren != groupChildren) + platformView.ShouldGroupAccessibilityChildren = groupChildren; + } + + internal static void RefreshAncestorContentRoles(UIView platformView) + { + // Refresh inside-out so each ancestor sees updated descendant roles. + for (var ancestor = platformView.Superview; ancestor is not null; ancestor = ancestor.Superview) + { + if (s_contentSemanticsDefaults.TryGetValue(ancestor, out var saved) + && saved.TryGetContent(out var view) + && ReferenceEquals(view.Handler?.PlatformView, ancestor) + && ReferenceEquals(view.Handler?.VirtualView, view)) + { + ApplyContentRole(ancestor, view, saved); + } + } + } + internal static bool UsesContentSemantics(UIView platformView, IView view) => view is IContentView and not ILayout && platformView is not (UIControl or SemanticSwitchContentView); @@ -247,6 +273,13 @@ internal static bool RefreshContentSemantics(IViewHandler handler) return true; } + internal static void ContentChanged(IViewHandler handler) + { + RefreshContentSemantics(handler); + if (handler.PlatformView is UIView platformView) + RefreshAncestorContentRoles(platformView); + } + internal static bool MapContentAccessibilityRole(IViewHandler handler, bool? role) { if (handler.VirtualView is not { } view || handler.PlatformView is not UIView platformView @@ -272,6 +305,7 @@ internal static bool MapContentAccessibilityRole(IViewHandler handler, bool? rol if (role.HasValue) platformView.IsAccessibilityElement = role.Value; + RefreshAncestorContentRoles(platformView); return true; } @@ -297,6 +331,7 @@ sealed class ContentRoleDefault(bool value) sealed class ContentSemanticsDefaults(UIView platformView) { + WeakReference? _content; readonly string? _label = platformView.AccessibilityLabel; readonly string? _hint = platformView.AccessibilityHint; readonly bool _groupsChildren = platformView.ShouldGroupAccessibilityChildren; @@ -304,6 +339,23 @@ sealed class ContentSemanticsDefaults(UIView platformView) ? role.Value : platformView.IsAccessibilityElement; public bool IsHeading { get; } = (platformView.AccessibilityTraits & UIAccessibilityTrait.Header) != 0; + public bool HasSemanticHeading { get; private set; } + + public void SetContent(IContentView view, bool isHeading) + { + HasSemanticHeading = isHeading; + if (_content is null) + _content = new(view); + else + _content.SetTarget(view); + } + + public bool TryGetContent([System.Diagnostics.CodeAnalysis.NotNullWhen(true)] out IContentView? view) + { + view = null; + return _content?.TryGetTarget(out view) == true; + } + public void Restore(UIView platformView, bool? explicitRole) { platformView.AccessibilityLabel = _label; From 4197e1d98f85bb4817e54296b15b3dfd74baaf85 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Tue, 1 Dec 2026 01:37:54 +0000 Subject: [PATCH 27/62] [iOS] Dispatch all eligible accessibility taps on content hosts Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../GesturePlatformManager.iOS.cs | 25 ++++++++++++++ .../src/Core/Platform/SemanticExtensions.cs | 7 ++-- .../ContentAccessibilityTests.iOS.cs | 34 +++++++++++++++++++ 3 files changed, 63 insertions(+), 3 deletions(-) diff --git a/src/Controls/src/Core/Platform/GestureManager/GesturePlatformManager.iOS.cs b/src/Controls/src/Core/Platform/GestureManager/GesturePlatformManager.iOS.cs index 3a296ad34014..5d6cc9a85ede 100644 --- a/src/Controls/src/Core/Platform/GestureManager/GesturePlatformManager.iOS.cs +++ b/src/Controls/src/Core/Platform/GestureManager/GesturePlatformManager.iOS.cs @@ -989,7 +989,32 @@ manager._handler.VirtualView is not View view || !view.IsEnabled || view.InputTr return false; } + if (view is global::Microsoft.Maui.ILayout) + { + tap.SendTapped(view); + return true; + } + + // Snapshot before sending: an action or event can change the recognizer collection. + var gestures = view.GestureRecognizers; + List? additionalTaps = null; + bool foundFirst = false; + for (int i = 0; i < gestures.Count; i++) + { + if (gestures[i] is not TapGestureRecognizer candidate || !candidate.IsAccessibleTapGesture()) + continue; + + if (foundFirst) + (additionalTaps ??= new()).Add(candidate); + foundFirst = true; + } + tap.SendTapped(view); + if (additionalTaps is not null) + { + foreach (var additionalTap in additionalTaps) + additionalTap.SendTapped(view); + } return true; }; _setAccessibilityActivateCallback = true; diff --git a/src/Controls/src/Core/Platform/SemanticExtensions.cs b/src/Controls/src/Core/Platform/SemanticExtensions.cs index fd14a8c43e1b..5af4058d35e2 100644 --- a/src/Controls/src/Core/Platform/SemanticExtensions.cs +++ b/src/Controls/src/Core/Platform/SemanticExtensions.cs @@ -13,9 +13,7 @@ internal static bool HasAccessibleTapGesture( { foreach (var gesture in virtualView.GestureRecognizers) { - //Accessibility can't handle Tap Recognizers with > 1 tap - if (gesture is TapGestureRecognizer tgr && tgr.NumberOfTapsRequired == 1 - && (tgr.Buttons & ButtonsMask.Primary) == ButtonsMask.Primary) + if (gesture is TapGestureRecognizer tgr && tgr.IsAccessibleTapGesture()) { tapGestureRecognizer = tgr; return true; @@ -25,6 +23,9 @@ internal static bool HasAccessibleTapGesture( return false; } + internal static bool IsAccessibleTapGesture(this TapGestureRecognizer tap) => + tap.NumberOfTapsRequired == 1 && (tap.Buttons & ButtonsMask.Primary) == ButtonsMask.Primary; + internal static bool HasAccessibleLongPressGesture(this View virtualView) => HasAccessibleLongPressGesture(virtualView, out _); diff --git a/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs b/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs index 4c72aff3a726..072005ac6385 100644 --- a/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs +++ b/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs @@ -1,3 +1,4 @@ +using System; using System.Threading.Tasks; using Microsoft.Maui.Controls; using Microsoft.Maui.Handlers; @@ -207,6 +208,39 @@ await InvokeOnMainThreadAsync(() => }); } + [Fact] + public async Task AccessibilityActivateInvokesAllPrimarySingleTapsOnBorder() + { + var border = new Border { Content = new Label { Text = "Action" } }; + SemanticProperties.SetDescription(border, "Action"); + var first = new TapGestureRecognizer(); + var second = new TapGestureRecognizer { Buttons = ButtonsMask.Primary | ButtonsMask.Secondary }; + var secondary = new TapGestureRecognizer { Buttons = ButtonsMask.Secondary }; + var doubleTap = new TapGestureRecognizer { NumberOfTapsRequired = 2 }; + int firstTaps = 0, secondTaps = 0, otherTaps = 0; + first.Tapped += (_, _) => + { + firstTaps++; + border.GestureRecognizers.Remove(first); + }; + second.Tapped += (_, _) => secondTaps++; + secondary.Tapped += (_, _) => otherTaps++; + doubleTap.Tapped += (_, _) => otherTaps++; + border.GestureRecognizers.Add(first); + border.GestureRecognizers.Add(secondary); + border.GestureRecognizers.Add(second); + border.GestureRecognizers.Add(doubleTap); + var handler = await CreateHandlerAsync(border); + + await InvokeOnMainThreadAsync(() => + { + Assert.True(Assert.IsType>(handler.PlatformView.AccessibilityActivateCallback)()); + Assert.Equal(1, firstTaps); + Assert.Equal(1, secondTaps); + Assert.Equal(0, otherTaps); + }); + } + [Fact] public async Task ReplacementSemanticsMapperDoesNotSuppressExplicitAccessibilityRole() { From 2f534eab29a1ddccb7d0402cfb76257b0ada80fe Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Tue, 1 Dec 2026 01:38:02 +0000 Subject: [PATCH 28/62] [iOS] Skip redundant ancestor accessibility rescans Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../Items/iOS/GroupableItemsViewController.cs | 1 + .../Handlers/Items/iOS/ItemsViewController.cs | 2 + .../Handlers/Items/iOS/MauiCollectionView.cs | 45 +++++++++++++++++-- .../iOS/GroupableItemsViewController2.cs | 1 + .../Items2/iOS/ItemsViewController2.cs | 2 + .../iOS/StructuredItemsViewController2.cs | 1 + .../PublicAPI/net-ios/PublicAPI.Unshipped.txt | 2 + .../net-maccatalyst/PublicAPI.Unshipped.txt | 2 + .../ContentAccessibilityTests.iOS.cs | 4 ++ src/Core/src/Handlers/View/ViewHandler.cs | 10 ++++- 10 files changed, 66 insertions(+), 4 deletions(-) diff --git a/src/Controls/src/Core/Handlers/Items/iOS/GroupableItemsViewController.cs b/src/Controls/src/Core/Handlers/Items/iOS/GroupableItemsViewController.cs index 493fe9114fcd..3fa9f5719346 100644 --- a/src/Controls/src/Core/Handlers/Items/iOS/GroupableItemsViewController.cs +++ b/src/Controls/src/Core/Handlers/Items/iOS/GroupableItemsViewController.cs @@ -95,6 +95,7 @@ public override UICollectionReusableView GetViewForSupplementaryElement(UICollec break; } + (collectionView as MauiCollectionView)?.InvalidateAccessibilityContent(); return view; } diff --git a/src/Controls/src/Core/Handlers/Items/iOS/ItemsViewController.cs b/src/Controls/src/Core/Handlers/Items/iOS/ItemsViewController.cs index 368540ccf80b..2f70228246a4 100644 --- a/src/Controls/src/Core/Handlers/Items/iOS/ItemsViewController.cs +++ b/src/Controls/src/Core/Handlers/Items/iOS/ItemsViewController.cs @@ -159,6 +159,7 @@ public override UICollectionViewCell GetCell(UICollectionView collectionView, NS break; } + (collectionView as MauiCollectionView)?.InvalidateAccessibilityContent(); return cell; } @@ -1067,6 +1068,7 @@ private protected virtual NSIndexPath GetAdjustedIndexPathForItemSource(NSIndexP internal virtual void CellDisplayingEndedFromDelegate(UICollectionViewCell cell, NSIndexPath indexPath) { + (CollectionView as MauiCollectionView)?.InvalidateAccessibilityContent(); if (cell is TemplatedCell templatedCell && (templatedCell.PlatformHandler?.VirtualView as View)?.BindingContext is object bindingContext) { diff --git a/src/Controls/src/Core/Handlers/Items/iOS/MauiCollectionView.cs b/src/Controls/src/Core/Handlers/Items/iOS/MauiCollectionView.cs index 046bf62dbffc..b72c15b548b4 100644 --- a/src/Controls/src/Core/Handlers/Items/iOS/MauiCollectionView.cs +++ b/src/Controls/src/Core/Handlers/Items/iOS/MauiCollectionView.cs @@ -9,6 +9,8 @@ namespace Microsoft.Maui.Controls.Handlers.Items; public class MauiCollectionView : UICollectionView, IUIViewLifeCycleEvents, IPlatformMeasureInvalidationController { + bool _accessibilityContentChanged; + bool _layingOutSubviews; bool _invalidateParentWhenMovedToWindow; bool? _isSwipeEnabled; bool? _isBounceEnabled; @@ -236,11 +238,48 @@ public override void AddSubview(UIView view) // during the very first layout pass, before SetSwipeEnabled(false) below runs. We reapply on // every layout pass, for both enabled and disabled, since Bounces can otherwise revert to its // default (true) after UIKit reconfigures the embedded scroller. + internal void InvalidateAccessibilityContent() + { + if (_accessibilityContentChanged) + return; + + _accessibilityContentChanged = true; + if (!_layingOutSubviews) + SetNeedsLayout(); + } + + /// + public override void SubviewAdded(UIView uiview) + { + base.SubviewAdded(uiview); + InvalidateAccessibilityContent(); + } + + /// + public override void WillRemoveSubview(UIView uiview) + { + base.WillRemoveSubview(uiview); + InvalidateAccessibilityContent(); + } + public override void LayoutSubviews() { - base.LayoutSubviews(); - // Deferred cells may not be attached until UIKit lays out the collection. - Microsoft.Maui.Platform.SemanticExtensions.RefreshAncestorContentRoles(this); + _layingOutSubviews = true; + try + { + base.LayoutSubviews(); + } + finally + { + _layingOutSubviews = false; + } + + if (_accessibilityContentChanged) + { + // Wait for UIKit to attach and remove deferred cells and supplementary views. + _accessibilityContentChanged = false; + Microsoft.Maui.Platform.SemanticExtensions.RefreshAncestorContentRoles(this); + } if (_isSwipeEnabled.HasValue) { diff --git a/src/Controls/src/Core/Handlers/Items2/iOS/GroupableItemsViewController2.cs b/src/Controls/src/Core/Handlers/Items2/iOS/GroupableItemsViewController2.cs index 2e4b363cafda..3a21f9eeee1f 100644 --- a/src/Controls/src/Core/Handlers/Items2/iOS/GroupableItemsViewController2.cs +++ b/src/Controls/src/Core/Handlers/Items2/iOS/GroupableItemsViewController2.cs @@ -112,6 +112,7 @@ public override UICollectionReusableView GetViewForSupplementaryElement(UICollec break; } + (collectionView as Items.MauiCollectionView)?.InvalidateAccessibilityContent(); return view; } diff --git a/src/Controls/src/Core/Handlers/Items2/iOS/ItemsViewController2.cs b/src/Controls/src/Core/Handlers/Items2/iOS/ItemsViewController2.cs index 689e445de50a..dca372333c9a 100644 --- a/src/Controls/src/Core/Handlers/Items2/iOS/ItemsViewController2.cs +++ b/src/Controls/src/Core/Handlers/Items2/iOS/ItemsViewController2.cs @@ -141,6 +141,7 @@ public override UICollectionViewCell GetCell(UICollectionView collectionView, NS DefaultCell2.Label.Text = ItemsSource[indexpathAdjusted].ToString(); } + (collectionView as MauiCollectionView)?.InvalidateAccessibilityContent(); return cell; } @@ -861,6 +862,7 @@ private protected virtual NSIndexPath GetAdjustedIndexPathForItemSource(NSIndexP internal virtual void CellDisplayingEndedFromDelegate(UICollectionViewCell cell, NSIndexPath indexPath) { + (CollectionView as MauiCollectionView)?.InvalidateAccessibilityContent(); if (cell is TemplatedCell2 templatedCell2 && (templatedCell2.PlatformHandler?.VirtualView as View)?.BindingContext is { } bindingContext) { diff --git a/src/Controls/src/Core/Handlers/Items2/iOS/StructuredItemsViewController2.cs b/src/Controls/src/Core/Handlers/Items2/iOS/StructuredItemsViewController2.cs index 6cd2eb54b383..484d7964e330 100644 --- a/src/Controls/src/Core/Handlers/Items2/iOS/StructuredItemsViewController2.cs +++ b/src/Controls/src/Core/Handlers/Items2/iOS/StructuredItemsViewController2.cs @@ -112,6 +112,7 @@ public override UICollectionReusableView GetViewForSupplementaryElement(UICollec break; } + (collectionView as Items.MauiCollectionView)?.InvalidateAccessibilityContent(); return view; } diff --git a/src/Controls/src/Core/PublicAPI/net-ios/PublicAPI.Unshipped.txt b/src/Controls/src/Core/PublicAPI/net-ios/PublicAPI.Unshipped.txt index 53af1e100334..1ed133d5d3ab 100644 --- a/src/Controls/src/Core/PublicAPI/net-ios/PublicAPI.Unshipped.txt +++ b/src/Controls/src/Core/PublicAPI/net-ios/PublicAPI.Unshipped.txt @@ -1,4 +1,6 @@ #nullable enable +override Microsoft.Maui.Controls.Handlers.Items.MauiCollectionView.SubviewAdded(UIKit.UIView! uiview) -> void +override Microsoft.Maui.Controls.Handlers.Items.MauiCollectionView.WillRemoveSubview(UIKit.UIView! uiview) -> void ~override Microsoft.Maui.Controls.Platform.Compatibility.ShellFlyoutContentRenderer.TraitCollectionDidChange(UIKit.UITraitCollection previousTraitCollection) -> void ~static Microsoft.Maui.Controls.ResourceDictionary.CreateMergedDictionary(Microsoft.Maui.Controls.ResourceDictionary mergeTarget) -> T override Microsoft.Maui.Controls.Handlers.Items2.ItemsViewController2.ViewDidLayoutSubviews() -> void diff --git a/src/Controls/src/Core/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txt b/src/Controls/src/Core/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txt index 53af1e100334..1ed133d5d3ab 100644 --- a/src/Controls/src/Core/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txt +++ b/src/Controls/src/Core/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txt @@ -1,4 +1,6 @@ #nullable enable +override Microsoft.Maui.Controls.Handlers.Items.MauiCollectionView.SubviewAdded(UIKit.UIView! uiview) -> void +override Microsoft.Maui.Controls.Handlers.Items.MauiCollectionView.WillRemoveSubview(UIKit.UIView! uiview) -> void ~override Microsoft.Maui.Controls.Platform.Compatibility.ShellFlyoutContentRenderer.TraitCollectionDidChange(UIKit.UITraitCollection previousTraitCollection) -> void ~static Microsoft.Maui.Controls.ResourceDictionary.CreateMergedDictionary(Microsoft.Maui.Controls.ResourceDictionary mergeTarget) -> T override Microsoft.Maui.Controls.Handlers.Items2.ItemsViewController2.ViewDidLayoutSubviews() -> void diff --git a/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs b/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs index 072005ac6385..543e0b7e8c0f 100644 --- a/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs +++ b/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs @@ -140,6 +140,10 @@ await CreateHandlerAndAddToWindow(border, async handler => await AssertEventually(() => !handler.PlatformView.IsAccessibilityElement && handler.PlatformView.ShouldGroupAccessibilityChildren, timeout: 5000); + + collection.ItemsSource = Array.Empty(); + await AssertEventually(() => handler.PlatformView.IsAccessibilityElement && + !handler.PlatformView.ShouldGroupAccessibilityChildren, timeout: 5000); }); } diff --git a/src/Core/src/Handlers/View/ViewHandler.cs b/src/Core/src/Handlers/View/ViewHandler.cs index dec42c82748f..c20704d05765 100644 --- a/src/Core/src/Handlers/View/ViewHandler.cs +++ b/src/Core/src/Handlers/View/ViewHandler.cs @@ -579,6 +579,13 @@ public static void MapOpacity(IViewHandler handler, IView view) return; #endif +#if __IOS__ || MACCATALYST + var opacityView = (handler.HasContainer ? handler.ContainerView : handler.PlatformView) as PlatformView; + bool wasNonTransparent = opacityView?.Alpha > 0; + var platformView = handler.PlatformView as PlatformView; + bool wasPlatformNonTransparent = platformView?.Alpha > 0; +#endif + if (handler.HasContainer) { ((PlatformView?)handler.ContainerView)?.UpdateOpacity(view); @@ -589,7 +596,8 @@ public static void MapOpacity(IViewHandler handler, IView view) ((PlatformView?)handler.PlatformView)?.UpdateOpacity(view); #if __IOS__ || MACCATALYST - if (handler.PlatformView is PlatformView platformView) + if (platformView is not null && (wasNonTransparent != (opacityView?.Alpha > 0) + || wasPlatformNonTransparent != (platformView.Alpha > 0))) SemanticExtensions.RefreshAncestorContentRoles(platformView); #endif } From 163fe3607415b9765d5bf544c85b93f2911b5899 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Tue, 1 Dec 2026 01:38:11 +0000 Subject: [PATCH 29/62] [iOS] Preserve app Semantics mapper during ancestor refresh Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../ContentAccessibilityTests.iOS.cs | 38 +++++++++++++++++++ .../src/Platform/iOS/SemanticExtensions.cs | 25 ++++++++++-- 2 files changed, 59 insertions(+), 4 deletions(-) diff --git a/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs b/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs index 543e0b7e8c0f..baa79284b3a8 100644 --- a/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs +++ b/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs @@ -245,6 +245,44 @@ await InvokeOnMainThreadAsync(() => }); } + [Fact] + public async Task DescendantChangePreservesAppSemanticsMapperRole() + { + var button = new Button { Text = "Child action" }; + var layout = new VerticalStackLayout { Children = { button } }; + var view = new ContentView { Content = layout }; + SemanticProperties.SetDescription(view, "Actions"); + var handler = await CreateHandlerAsync(view); + + await InvokeOnMainThreadAsync(() => + { + Assert.True(handler.PlatformView.IsAccessibilityElement); + Assert.False(handler.PlatformView.ShouldGroupAccessibilityChildren); + button.Opacity = 0; + button.Opacity = 1; + Assert.True(handler.PlatformView.IsAccessibilityElement); + Assert.False(handler.PlatformView.ShouldGroupAccessibilityChildren); + }); + } + + sealed class CustomRoleContentViewHandler : ContentViewHandler + { + public CustomRoleContentViewHandler() : base(CreateMapper()) + { + } + + static PropertyMapper CreateMapper() + { + var mapper = new PropertyMapper(Mapper); + mapper.AppendToMapping(nameof(IView.Semantics), (handler, _) => + { + handler.PlatformView.IsAccessibilityElement = true; + handler.PlatformView.ShouldGroupAccessibilityChildren = false; + }); + return mapper; + } + } + [Fact] public async Task ReplacementSemanticsMapperDoesNotSuppressExplicitAccessibilityRole() { diff --git a/src/Core/src/Platform/iOS/SemanticExtensions.cs b/src/Core/src/Platform/iOS/SemanticExtensions.cs index 3659ba7bbceb..62ed0ece0075 100644 --- a/src/Core/src/Platform/iOS/SemanticExtensions.cs +++ b/src/Core/src/Platform/iOS/SemanticExtensions.cs @@ -243,15 +243,31 @@ static void ApplyContentRole(UIView platformView, IContentView view, ContentSema internal static void RefreshAncestorContentRoles(UIView platformView) { - // Refresh inside-out so each ancestor sees updated descendant roles. + if (s_contentSemanticsDefaults.TryGetValue(platformView, out var current) && current.IsRefreshingMapper) + return; + + // Run the effective mapper inside-out, including app appends, before visiting the next host. for (var ancestor = platformView.Superview; ancestor is not null; ancestor = ancestor.Superview) { if (s_contentSemanticsDefaults.TryGetValue(ancestor, out var saved) && saved.TryGetContent(out var view) - && ReferenceEquals(view.Handler?.PlatformView, ancestor) - && ReferenceEquals(view.Handler?.VirtualView, view)) + && view.Handler is IViewHandler handler + && ReferenceEquals(handler.PlatformView, ancestor) + && ReferenceEquals(handler.VirtualView, view)) { - ApplyContentRole(ancestor, view, saved); + // The active walk will continue past this host after its mapper finishes. + if (saved.IsRefreshingMapper) + return; + + saved.IsRefreshingMapper = true; + try + { + handler.UpdateValue(nameof(IView.Semantics)); + } + finally + { + saved.IsRefreshingMapper = false; + } } } } @@ -340,6 +356,7 @@ sealed class ContentSemanticsDefaults(UIView platformView) public bool IsHeading { get; } = (platformView.AccessibilityTraits & UIAccessibilityTrait.Header) != 0; public bool HasSemanticHeading { get; private set; } + public bool IsRefreshingMapper { get; set; } public void SetContent(IContentView view, bool isHeading) { From e871aa5f82525768a79d060fe6d9e4113ba39b27 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Tue, 1 Dec 2026 01:38:24 +0000 Subject: [PATCH 30/62] [iOS] Cover direct activation of explicitly excluded content Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../ContentAccessibilityTests.iOS.cs | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs b/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs index baa79284b3a8..4aeec8a77d36 100644 --- a/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs +++ b/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs @@ -245,6 +245,31 @@ await InvokeOnMainThreadAsync(() => }); } + [Fact] + public async Task AccessibilityActivateCallbackRespectsBorderExclusion() + { + var border = new Border { Content = new Label { Text = "Action" } }; + SemanticProperties.SetDescription(border, "Action"); + var tap = new TapGestureRecognizer(); + int taps = 0; + tap.Tapped += (_, _) => taps++; + border.GestureRecognizers.Add(tap); + var handler = await CreateHandlerAsync(border); + + await InvokeOnMainThreadAsync(() => + { + AutomationProperties.SetIsInAccessibleTree(border, false); + Assert.False(handler.PlatformView.IsAccessibilityElement); + Assert.False(Assert.IsType>(handler.PlatformView.AccessibilityActivateCallback)()); + Assert.Equal(0, taps); + + border.ClearValue(AutomationProperties.IsInAccessibleTreeProperty); + Assert.True(handler.PlatformView.IsAccessibilityElement); + Assert.True(Assert.IsType>(handler.PlatformView.AccessibilityActivateCallback)()); + Assert.Equal(1, taps); + }); + } + [Fact] public async Task DescendantChangePreservesAppSemanticsMapperRole() { From 456e2394930af6af8dcbbcfa6bde948550571334 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Tue, 1 Dec 2026 03:17:56 +0000 Subject: [PATCH 31/62] [iOS] Refresh ancestor roles after the effective Semantics mapper Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../ContentAccessibilityTests.iOS.cs | 35 +++++++++++++++++++ .../src/Handlers/Element/ElementHandler.cs | 15 ++++++++ src/Core/src/Handlers/View/ViewHandler.cs | 3 +- .../src/Platform/iOS/SemanticExtensions.cs | 3 +- 4 files changed, 53 insertions(+), 3 deletions(-) diff --git a/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs b/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs index 4aeec8a77d36..7c43bc53e1fe 100644 --- a/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs +++ b/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs @@ -290,6 +290,41 @@ await InvokeOnMainThreadAsync(() => }); } + [Fact] + public async Task AncestorRoleUsesOriginatingSemanticsMapperFinalState() + { + var inner = new ContentView { Content = new BoxView() }; + SemanticProperties.SetDescription(inner, "Inner"); + var outer = new ContentView { Content = inner }; + SemanticProperties.SetDescription(outer, "Outer"); + + var innerHandler = await CreateHandlerAsync(inner); + var outerHandler = await CreateHandlerAsync(outer); + await InvokeOnMainThreadAsync(() => + { + Assert.Same(innerHandler, inner.Handler); + Assert.False(innerHandler.PlatformView.IsAccessibilityElement); + Assert.True(outerHandler.PlatformView.IsAccessibilityElement); + SemanticProperties.SetHint(inner, "New hint"); + Assert.False(innerHandler.PlatformView.IsAccessibilityElement); + Assert.True(outerHandler.PlatformView.IsAccessibilityElement); + }); + } + + sealed class ExcludedContentViewHandler : ContentViewHandler + { + public ExcludedContentViewHandler() : base(CreateMapper()) + { + } + + static PropertyMapper CreateMapper() + { + var mapper = new PropertyMapper(Mapper); + mapper.AppendToMapping(nameof(IView.Semantics), (handler, _) => handler.PlatformView.IsAccessibilityElement = false); + return mapper; + } + } + sealed class CustomRoleContentViewHandler : ContentViewHandler { public CustomRoleContentViewHandler() : base(CreateMapper()) diff --git a/src/Core/src/Handlers/Element/ElementHandler.cs b/src/Core/src/Handlers/Element/ElementHandler.cs index 58a3fe8da35e..e1450f9f4db1 100644 --- a/src/Core/src/Handlers/Element/ElementHandler.cs +++ b/src/Core/src/Handlers/Element/ElementHandler.cs @@ -128,6 +128,9 @@ public virtual void SetVirtualView(IElement view) } _handlerState = ElementHandlerState.Connected; +#if __IOS__ || MACCATALYST + RefreshAncestorContentRoles(); +#endif } public virtual void UpdateValue(string property) @@ -136,7 +139,19 @@ public virtual void UpdateValue(string property) return; _mapper?.UpdateProperty(this, VirtualView, property); +#if __IOS__ || MACCATALYST + if (property == nameof(IView.Semantics)) + RefreshAncestorContentRoles(); +#endif + } + +#if __IOS__ || MACCATALYST + void RefreshAncestorContentRoles() + { + if (this is IViewHandler && PlatformView is UIKit.UIView platformView) + Platform.SemanticExtensions.RefreshAncestorContentRoles(platformView); } +#endif public virtual void Invoke(string command, object? args) { diff --git a/src/Core/src/Handlers/View/ViewHandler.cs b/src/Core/src/Handlers/View/ViewHandler.cs index c20704d05765..fc3ea5c3fbba 100644 --- a/src/Core/src/Handlers/View/ViewHandler.cs +++ b/src/Core/src/Handlers/View/ViewHandler.cs @@ -665,7 +665,8 @@ public static void MapSemantics(IViewHandler handler, IView view) MappingSemantics(handler, view); ((PlatformView?)handler.PlatformView)?.UpdateSemantics(view); #if __IOS__ || MACCATALYST - if (handler.PlatformView is PlatformView platformView) + // Compatibility handlers do not use ElementHandler's post-mapping path. + if (handler is not ElementHandler && handler.PlatformView is PlatformView platformView) SemanticExtensions.RefreshAncestorContentRoles(platformView); #endif } diff --git a/src/Core/src/Platform/iOS/SemanticExtensions.cs b/src/Core/src/Platform/iOS/SemanticExtensions.cs index 62ed0ece0075..d9e4bf61d56d 100644 --- a/src/Core/src/Platform/iOS/SemanticExtensions.cs +++ b/src/Core/src/Platform/iOS/SemanticExtensions.cs @@ -291,8 +291,7 @@ internal static bool RefreshContentSemantics(IViewHandler handler) internal static void ContentChanged(IViewHandler handler) { - RefreshContentSemantics(handler); - if (handler.PlatformView is UIView platformView) + if (handler.PlatformView is UIView platformView && (!RefreshContentSemantics(handler) || handler is not Handlers.ElementHandler)) RefreshAncestorContentRoles(platformView); } From f28b1a9b32a67db1dd10965821b692f2c39d5a48 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Tue, 1 Dec 2026 03:18:05 +0000 Subject: [PATCH 32/62] [iOS] Preserve the native accessibility tap position Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../GesturePlatformManager.iOS.cs | 36 +++++++++++++++++-- .../ContentAccessibilityTests.iOS.cs | 32 +++++++++++++++++ 2 files changed, 66 insertions(+), 2 deletions(-) diff --git a/src/Controls/src/Core/Platform/GestureManager/GesturePlatformManager.iOS.cs b/src/Controls/src/Core/Platform/GestureManager/GesturePlatformManager.iOS.cs index 5d6cc9a85ede..3b92470e6463 100644 --- a/src/Controls/src/Core/Platform/GestureManager/GesturePlatformManager.iOS.cs +++ b/src/Controls/src/Core/Platform/GestureManager/GesturePlatformManager.iOS.cs @@ -1009,11 +1009,43 @@ manager._handler.VirtualView is not View view || !view.IsEnabled || view.InputTr foundFirst = true; } - tap.SendTapped(view); + // Direct activation has no touch, but UIKit supplies its activation point in screen coordinates. + if (manager.PlatformView is not UIView nativeView) + return false; + + var window = nativeView.Window; + var screenPoint = nativeView.AccessibilityActivationPoint; + var bounds = nativeView.Bounds; + var windowPoint = window?.ConvertPointFromWindow(screenPoint, null); + var localPoint = windowPoint is { } point + ? nativeView.ConvertPointFromView(point, window) + : new CGPoint(bounds.GetMidX(), bounds.GetMidY()); + var source = new WeakReference(nativeView); + var sourceWindow = window is not null ? new WeakReference(window) : null; + Point? GetPosition(IElement? relativeTo) + { + if (relativeTo is null) + return windowPoint is { } position ? new Point(position.X, position.Y) : null; + + if (relativeTo.Handler?.PlatformView is not UIView target) + return null; + if (source.TryGetTarget(out var native) && ReferenceEquals(native, target)) + return new Point(localPoint.X, localPoint.Y); + if (windowPoint is { } location && sourceWindow?.TryGetTarget(out var nativeWindow) == true + && target.Window == nativeWindow) + { + var converted = target.ConvertPointFromView(location, nativeWindow); + return new Point(converted.X, converted.Y); + } + + return null; + } + + tap.SendTapped(view, GetPosition); if (additionalTaps is not null) { foreach (var additionalTap in additionalTaps) - additionalTap.SendTapped(view); + additionalTap.SendTapped(view, GetPosition); } return true; }; diff --git a/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs b/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs index 7c43bc53e1fe..2cfc99b989cd 100644 --- a/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs +++ b/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs @@ -212,6 +212,38 @@ await InvokeOnMainThreadAsync(() => }); } + [Fact] + public async Task AccessibilityActivateUsesNativeActivationPoint() + { + var tap = new TapGestureRecognizer(); + var border = new Border + { + Content = new Label { Text = "Action" }, + GestureRecognizers = { tap }, + }; + var parent = new ContentView { Content = border }; + SemanticProperties.SetDescription(border, "Action"); + TappedEventArgs? tapped = null; + tap.Tapped += (_, args) => tapped = args; + + await CreateHandlerAndAddToWindow(parent, handler => + { + var native = Assert.IsAssignableFrom(border.Handler?.PlatformView); + var window = Assert.IsAssignableFrom(native.Window); + var point = new CoreGraphics.CGPoint(12, 24); + var windowPoint = native.ConvertPointToView(point, window); + var parentPoint = native.ConvertPointToView(point, handler.PlatformView); + native.AccessibilityActivationPoint = window.ConvertPointToWindow(windowPoint, null); + Assert.Equal(window.ConvertPointToWindow(windowPoint, null), native.AccessibilityActivationPoint); + + Assert.True(native.AccessibilityActivate()); + var args = Assert.IsType(tapped); + Assert.Equal(new Microsoft.Maui.Graphics.Point(point.X, point.Y), args.GetPosition(border)); + Assert.Equal(new Microsoft.Maui.Graphics.Point(parentPoint.X, parentPoint.Y), args.GetPosition(parent)); + Assert.Equal(new Microsoft.Maui.Graphics.Point(windowPoint.X, windowPoint.Y), args.GetPosition(null)); + }); + } + [Fact] public async Task AccessibilityActivateInvokesAllPrimarySingleTapsOnBorder() { From 19b67cc54d2859f3766b188871837b376c43e629 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Tue, 1 Dec 2026 03:18:10 +0000 Subject: [PATCH 33/62] [iOS] Remap the content role when subtree exclusion changes Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- src/Controls/src/Core/Element/Element.iOS.cs | 5 ++++- .../ContentAccessibilityTests.iOS.cs | 21 +++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/Controls/src/Core/Element/Element.iOS.cs b/src/Controls/src/Core/Element/Element.iOS.cs index 1b0bab319d4a..cca8e6ba578f 100644 --- a/src/Controls/src/Core/Element/Element.iOS.cs +++ b/src/Controls/src/Core/Element/Element.iOS.cs @@ -44,7 +44,10 @@ public static void MapAutomationPropertiesExcludedWithChildren(IElementHandler h var _defaultAccessibilityElementsHidden = Control.AccessibilityElementsHidden || Control is UIControl; Control.AccessibilityElementsHidden = (bool)((bool?)view.GetValue(AutomationProperties.ExcludedWithChildrenProperty) ?? _defaultAccessibilityElementsHidden); - Microsoft.Maui.Platform.SemanticExtensions.RefreshAncestorContentRoles(Control); + if (handler is IViewHandler viewHandler && ReferenceEquals(handler.VirtualView, view)) + Microsoft.Maui.Platform.SemanticExtensions.ContentChanged(viewHandler); + else + Microsoft.Maui.Platform.SemanticExtensions.RefreshAncestorContentRoles(Control); } static void MapAutomationPropertiesIsInAccessibleTree(IElementHandler handler, IElement element) diff --git a/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs b/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs index 2cfc99b989cd..bc801eea3850 100644 --- a/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs +++ b/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs @@ -123,6 +123,27 @@ await InvokeOnMainThreadAsync(() => }); } + [Fact] + public async Task ReincludingSubtreeRestoresItsContentRole() + { + var button = new Button { Text = "Action" }; + var border = new Border { Content = button }; + SemanticProperties.SetDescription(border, "Actions"); + var handler = await CreateHandlerAsync(border); + + await InvokeOnMainThreadAsync(() => + { + Assert.False(handler.PlatformView.IsAccessibilityElement); + AutomationProperties.SetExcludedWithChildren(border, true); + button.IsVisible = false; + button.IsVisible = true; + AutomationProperties.SetExcludedWithChildren(border, false); + Assert.False(handler.PlatformView.AccessibilityElementsHidden); + Assert.False(handler.PlatformView.IsAccessibilityElement); + Assert.True(handler.PlatformView.ShouldGroupAccessibilityChildren); + }); + } + [Fact] public async Task DeferredCollectionItemsRemapAncestorAccessibilityRole() { From 3a8a6198bee562b446212c86d5642c27c00bf613 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Tue, 1 Dec 2026 03:18:20 +0000 Subject: [PATCH 34/62] [iOS] Coalesce ancestor role refreshes during visibility propagation Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../src/Core/VisualElement/VisualElement.cs | 6 ++ .../ContentAccessibilityTests.iOS.cs | 43 +++++++++ src/Core/src/Handlers/View/ViewHandler.cs | 2 +- .../src/Platform/iOS/SemanticExtensions.cs | 88 ++++++++++++++++--- 4 files changed, 124 insertions(+), 15 deletions(-) diff --git a/src/Controls/src/Core/VisualElement/VisualElement.cs b/src/Controls/src/Core/VisualElement/VisualElement.cs index 6e7843c8cff7..dfdefb0a6631 100644 --- a/src/Controls/src/Core/VisualElement/VisualElement.cs +++ b/src/Controls/src/Core/VisualElement/VisualElement.cs @@ -1990,6 +1990,12 @@ void IPropertyPropagationController.PropagatePropertyChanged(string propertyName this.RefreshPropertyValue(InputTransparentProperty, _inputTransparentExplicit); var effectiveVisibilityChanged = false; +#if IOS || MACCATALYST + using var visibilityRefresh = (propertyName == null || propertyName == IsVisibleProperty.PropertyName) + && Handler?.PlatformView is UIKit.UIView + ? Microsoft.Maui.Platform.SemanticExtensions.BeginVisibilityRefresh() + : null; +#endif if (propertyName == null || propertyName == IsVisibleProperty.PropertyName) effectiveVisibilityChanged = UpdateEffectiveVisibility(); diff --git a/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs b/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs index bc801eea3850..44c9e172af91 100644 --- a/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs +++ b/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs @@ -123,6 +123,33 @@ await InvokeOnMainThreadAsync(() => }); } + [Fact] + public async Task RevealingPopulatedLayoutRefreshesContentHostOnce() + { + var layout = new Grid(); + for (int i = 0; i < 16; i++) + layout.Add(new BoxView()); + var inner = new ContentView { Content = new Button { Text = "Action" } }; + SemanticProperties.SetDescription(inner, "Inner actions"); + var parent = new Grid { layout, inner }; + var view = new ContentView { Content = parent }; + SemanticProperties.SetDescription(view, "Actions"); + var handler = await CreateHandlerAsync(view); + + await InvokeOnMainThreadAsync(() => + { + Assert.False(handler.PlatformView.IsAccessibilityElement); + var count = handler.SemanticsUpdates; + parent.IsVisible = false; + Assert.Equal(count + 1, handler.SemanticsUpdates); + Assert.True(handler.PlatformView.IsAccessibilityElement); + parent.IsVisible = true; + Assert.Equal(count + 2, handler.SemanticsUpdates); + Assert.False(handler.PlatformView.IsAccessibilityElement); + Assert.True(Assert.IsAssignableFrom(inner.Handler?.PlatformView).ShouldGroupAccessibilityChildren); + }); + } + [Fact] public async Task ReincludingSubtreeRestoresItsContentRole() { @@ -144,6 +171,22 @@ await InvokeOnMainThreadAsync(() => }); } + sealed class CountingContentViewHandler : ContentViewHandler + { + public int SemanticsUpdates { get; private set; } + + public CountingContentViewHandler() : base(CreateMapper()) + { + } + + static PropertyMapper CreateMapper() + { + var mapper = new PropertyMapper(Mapper); + mapper.AppendToMapping(nameof(IView.Semantics), (handler, _) => ((CountingContentViewHandler)handler).SemanticsUpdates++); + return mapper; + } + } + [Fact] public async Task DeferredCollectionItemsRemapAncestorAccessibilityRole() { diff --git a/src/Core/src/Handlers/View/ViewHandler.cs b/src/Core/src/Handlers/View/ViewHandler.cs index fc3ea5c3fbba..42fecfc44780 100644 --- a/src/Core/src/Handlers/View/ViewHandler.cs +++ b/src/Core/src/Handlers/View/ViewHandler.cs @@ -516,7 +516,7 @@ public static void MapVisibility(IViewHandler handler, IView view) ((PlatformView?)handler.PlatformView)?.UpdateVisibility(view); #if __IOS__ || MACCATALYST if (handler.PlatformView is PlatformView platformView) - SemanticExtensions.RefreshAncestorContentRoles(platformView); + SemanticExtensions.VisibilityChanged(platformView); #endif } diff --git a/src/Core/src/Platform/iOS/SemanticExtensions.cs b/src/Core/src/Platform/iOS/SemanticExtensions.cs index d9e4bf61d56d..7c8af486f7ed 100644 --- a/src/Core/src/Platform/iOS/SemanticExtensions.cs +++ b/src/Core/src/Platform/iOS/SemanticExtensions.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Runtime.CompilerServices; using System.Text; using UIKit; @@ -16,6 +17,57 @@ public static partial class SemanticExtensions static readonly ConditionalWeakTable s_contentSemanticsDefaults = new(); static readonly ConditionalWeakTable s_contentRoleDefaults = new(); const int MaxAccessibleSubviewDepth = 32; + [ThreadStatic] + static VisibilityRefreshBatch? s_visibilityRefreshBatch; + + internal static VisibilityRefreshBatch? BeginVisibilityRefresh() => + s_visibilityRefreshBatch is null ? s_visibilityRefreshBatch = new() : null; + + internal static void VisibilityChanged(UIView platformView) + { + if (s_visibilityRefreshBatch is { } batch) + { + if (!s_contentSemanticsDefaults.TryGetValue(platformView, out var saved) || !saved.IsRefreshingMapper) + batch.Collect(platformView.Superview); + } + else + RefreshAncestorContentRoles(platformView); + } + + internal sealed class VisibilityRefreshBatch : IDisposable + { + HashSet? _visited; + List? _hosts; + + internal void Collect(UIView? ancestor) + { + int firstHost = _hosts?.Count ?? 0; + for (; ancestor is not null && (_visited ??= new()).Add(ancestor); ancestor = ancestor.Superview) + { + if (s_contentSemanticsDefaults.TryGetValue(ancestor, out var saved)) + { + if (saved.IsRefreshingMapper) + break; + (_hosts ??= new()).Add(ancestor); + } + } + + // Add new hosts outermost first; a previously visited host already has its + // ancestors ahead of it. Reversing the full list at flush gives inside-out order. + _hosts?.Reverse(firstHost, _hosts.Count - firstHost); + } + + public void Dispose() + { + s_visibilityRefreshBatch = null; + if (_hosts is null) + return; + + // Descendants finish mapping visibility before their content hosts are evaluated. + for (int i = _hosts.Count - 1; i >= 0; i--) + RefreshContentHost(_hosts[i]); + } + } internal static void UpdateSemantics(this UIBarItem platformView, Semantics? semantics) { @@ -249,27 +301,35 @@ internal static void RefreshAncestorContentRoles(UIView platformView) // Run the effective mapper inside-out, including app appends, before visiting the next host. for (var ancestor = platformView.Superview; ancestor is not null; ancestor = ancestor.Superview) { - if (s_contentSemanticsDefaults.TryGetValue(ancestor, out var saved) + if (!RefreshContentHost(ancestor)) + return; + } + } + + static bool RefreshContentHost(UIView ancestor) + { + if (s_contentSemanticsDefaults.TryGetValue(ancestor, out var saved) && saved.TryGetContent(out var view) && view.Handler is IViewHandler handler && ReferenceEquals(handler.PlatformView, ancestor) && ReferenceEquals(handler.VirtualView, view)) - { - // The active walk will continue past this host after its mapper finishes. - if (saved.IsRefreshingMapper) - return; + { + // The active walk will continue past this host after its mapper finishes. + if (saved.IsRefreshingMapper) + return false; - saved.IsRefreshingMapper = true; - try - { - handler.UpdateValue(nameof(IView.Semantics)); - } - finally - { - saved.IsRefreshingMapper = false; - } + saved.IsRefreshingMapper = true; + try + { + handler.UpdateValue(nameof(IView.Semantics)); + } + finally + { + saved.IsRefreshingMapper = false; } } + + return true; } internal static bool UsesContentSemantics(UIView platformView, IView view) => From 1434e4b8f3aeb32a6c9197d649ed1f467c8b77bc Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Tue, 1 Dec 2026 03:18:20 +0000 Subject: [PATCH 35/62] [iOS] Test that only opacity zero crossings refresh ancestor roles Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../ContentAccessibilityTests.iOS.cs | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs b/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs index 44c9e172af91..a12577701854 100644 --- a/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs +++ b/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs @@ -171,6 +171,29 @@ await InvokeOnMainThreadAsync(() => }); } + [Fact] + public async Task PositiveOpacityChangesDoNotRefreshAncestorSemantics() + { + var button = new Button { Text = "Action" }; + var view = new ContentView { Content = button }; + SemanticProperties.SetDescription(view, "Actions"); + var handler = await CreateHandlerAsync(view); + + await InvokeOnMainThreadAsync(() => + { + var count = handler.SemanticsUpdates; + button.Opacity = 0.5; + button.Opacity = 0.25; + Assert.Equal(count, handler.SemanticsUpdates); + button.Opacity = 0; + Assert.Equal(count + 1, handler.SemanticsUpdates); + Assert.True(handler.PlatformView.IsAccessibilityElement); + button.Opacity = 1; + Assert.Equal(count + 2, handler.SemanticsUpdates); + Assert.False(handler.PlatformView.IsAccessibilityElement); + }); + } + sealed class CountingContentViewHandler : ContentViewHandler { public int SemanticsUpdates { get; private set; } From e67041d9a14df8e6997c1aa232aa3052d8724e00 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Tue, 1 Dec 2026 05:12:30 +0000 Subject: [PATCH 36/62] Avoid ancestor rescans for accessible leaf text changes Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../ContentAccessibilityTests.iOS.cs | 19 +++++++++++++++++++ .../src/Handlers/Element/ElementHandler.cs | 16 +++++++++++++--- .../src/Platform/iOS/SemanticExtensions.cs | 8 ++++++++ 3 files changed, 40 insertions(+), 3 deletions(-) diff --git a/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs b/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs index a12577701854..5e98c71f5af9 100644 --- a/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs +++ b/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs @@ -171,6 +171,25 @@ await InvokeOnMainThreadAsync(() => }); } + [Fact] + public async Task UpdatingAccessibleButtonTextDoesNotRemapAncestorRole() + { + var button = new Button { Text = "Action" }; + SemanticProperties.SetDescription(button, "First"); + var view = new ContentView { Content = new Grid { button } }; + SemanticProperties.SetDescription(view, "Actions"); + var handler = await CreateHandlerAsync(view); + + await InvokeOnMainThreadAsync(() => + { + Assert.False(handler.PlatformView.IsAccessibilityElement); + var count = handler.SemanticsUpdates; + SemanticProperties.SetDescription(button, "Second"); + Assert.Equal("Second", Assert.IsAssignableFrom(button.Handler?.PlatformView).AccessibilityLabel); + Assert.Equal(count, handler.SemanticsUpdates); + }); + } + [Fact] public async Task PositiveOpacityChangesDoNotRefreshAncestorSemantics() { diff --git a/src/Core/src/Handlers/Element/ElementHandler.cs b/src/Core/src/Handlers/Element/ElementHandler.cs index e1450f9f4db1..41cc55caa440 100644 --- a/src/Core/src/Handlers/Element/ElementHandler.cs +++ b/src/Core/src/Handlers/Element/ElementHandler.cs @@ -138,11 +138,21 @@ public virtual void UpdateValue(string property) if (VirtualView == null) return; - _mapper?.UpdateProperty(this, VirtualView, property); #if __IOS__ || MACCATALYST - if (property == nameof(IView.Semantics)) - RefreshAncestorContentRoles(); + if (property == nameof(IView.Semantics) && this is IViewHandler handler && PlatformView is UIKit.UIView platformView) + { + bool wasAccessibleLeaf = handler.VirtualView is { } view + && !Platform.SemanticExtensions.UsesContentSemantics(platformView, view) + && Platform.SemanticExtensions.IsAccessibleLeaf(handler, platformView); + _mapper?.UpdateProperty(this, VirtualView, property); + // A non-leaf mapper can change accessible descendants without changing this view's flags. + if (!wasAccessibleLeaf || !ReferenceEquals(platformView, PlatformView) + || !Platform.SemanticExtensions.IsAccessibleLeaf(handler, platformView)) + RefreshAncestorContentRoles(); + return; + } #endif + _mapper?.UpdateProperty(this, VirtualView, property); } #if __IOS__ || MACCATALYST diff --git a/src/Core/src/Platform/iOS/SemanticExtensions.cs b/src/Core/src/Platform/iOS/SemanticExtensions.cs index 7c8af486f7ed..3010fce0aa18 100644 --- a/src/Core/src/Platform/iOS/SemanticExtensions.cs +++ b/src/Core/src/Platform/iOS/SemanticExtensions.cs @@ -384,6 +384,14 @@ internal static bool MapContentAccessibilityRole(IViewHandler handler, bool? rol return true; } + internal static bool IsAccessibleLeaf(IViewHandler handler, UIView view) => + view.IsAccessibilityElement && IsAccessibleBranch(view) + && (handler.ContainerView is not UIView container || ReferenceEquals(container, view) + || IsAccessibleBranch(container)); + + static bool IsAccessibleBranch(UIView view) => + !view.Hidden && view.Alpha > 0 && !view.AccessibilityElementsHidden; + static bool HasAccessibleSubview(UIView platformView, int depth) { if (depth >= MaxAccessibleSubviewDepth || platformView.AccessibilityElementsHidden) From a932a5944f406875626cb5614348f0e4382411f7 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Tue, 1 Dec 2026 05:12:47 +0000 Subject: [PATCH 37/62] Refresh accessibility roles after effective opacity mapping Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../ContentAccessibilityTests.iOS.cs | 39 +++++++++++++++++++ .../src/Handlers/Element/ElementHandler.cs | 11 ++++++ src/Core/src/Handlers/View/ViewHandler.cs | 9 ++--- .../src/Platform/iOS/SemanticExtensions.cs | 3 ++ 4 files changed, 56 insertions(+), 6 deletions(-) diff --git a/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs b/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs index 5e98c71f5af9..fb5efa67d292 100644 --- a/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs +++ b/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs @@ -190,6 +190,45 @@ await InvokeOnMainThreadAsync(() => }); } + [Fact] + public async Task AncestorRoleUsesFinalMappedOpacity() + { + var button = new Button { Text = "Action" }; + var view = new ContentView { Content = button }; + SemanticProperties.SetDescription(view, "Actions"); + var buttonHandler = await CreateHandlerAsync(button); + var handler = await CreateHandlerAsync(view); + + await InvokeOnMainThreadAsync(() => + { + Assert.Same(buttonHandler, button.Handler); + Assert.False(handler.PlatformView.IsAccessibilityElement); + var count = handler.SemanticsUpdates; + button.Opacity = 0; + Assert.True(buttonHandler.PlatformView.Alpha > 0); + Assert.False(handler.PlatformView.IsAccessibilityElement); + Assert.Equal(count, handler.SemanticsUpdates); + }); + } + + sealed class MinimumOpacityButtonHandler : ButtonHandler + { + public MinimumOpacityButtonHandler() : base(CreateMapper()) + { + } + + static PropertyMapper CreateMapper() + { + var mapper = new PropertyMapper(Mapper); + mapper.AppendToMapping(nameof(IView.Opacity), (handler, _) => + { + if (handler.PlatformView.Alpha == 0) + handler.PlatformView.Alpha = 0.1f; + }); + return mapper; + } + } + [Fact] public async Task PositiveOpacityChangesDoNotRefreshAncestorSemantics() { diff --git a/src/Core/src/Handlers/Element/ElementHandler.cs b/src/Core/src/Handlers/Element/ElementHandler.cs index 41cc55caa440..007930c4a1e4 100644 --- a/src/Core/src/Handlers/Element/ElementHandler.cs +++ b/src/Core/src/Handlers/Element/ElementHandler.cs @@ -151,6 +151,17 @@ public virtual void UpdateValue(string property) RefreshAncestorContentRoles(); return; } + + if (property == nameof(IView.Opacity) && this is IViewHandler opacityHandler && PlatformView is UIKit.UIView opacityView) + { + bool wasNonTransparent = Platform.SemanticExtensions.IsNonTransparent(opacityHandler, opacityView); + _mapper?.UpdateProperty(this, VirtualView, property); + if (PlatformView is UIKit.UIView updatedView + && (!ReferenceEquals(opacityView, updatedView) + || wasNonTransparent != Platform.SemanticExtensions.IsNonTransparent(opacityHandler, updatedView))) + RefreshAncestorContentRoles(); + return; + } #endif _mapper?.UpdateProperty(this, VirtualView, property); } diff --git a/src/Core/src/Handlers/View/ViewHandler.cs b/src/Core/src/Handlers/View/ViewHandler.cs index 42fecfc44780..4f2538c4d8ad 100644 --- a/src/Core/src/Handlers/View/ViewHandler.cs +++ b/src/Core/src/Handlers/View/ViewHandler.cs @@ -580,10 +580,8 @@ public static void MapOpacity(IViewHandler handler, IView view) #endif #if __IOS__ || MACCATALYST - var opacityView = (handler.HasContainer ? handler.ContainerView : handler.PlatformView) as PlatformView; - bool wasNonTransparent = opacityView?.Alpha > 0; - var platformView = handler.PlatformView as PlatformView; - bool wasPlatformNonTransparent = platformView?.Alpha > 0; + var platformView = handler is not ElementHandler ? handler.PlatformView as PlatformView : null; + bool wasNonTransparent = platformView is not null && SemanticExtensions.IsNonTransparent(handler, platformView); #endif if (handler.HasContainer) @@ -596,8 +594,7 @@ public static void MapOpacity(IViewHandler handler, IView view) ((PlatformView?)handler.PlatformView)?.UpdateOpacity(view); #if __IOS__ || MACCATALYST - if (platformView is not null && (wasNonTransparent != (opacityView?.Alpha > 0) - || wasPlatformNonTransparent != (platformView.Alpha > 0))) + if (platformView is not null && wasNonTransparent != SemanticExtensions.IsNonTransparent(handler, platformView)) SemanticExtensions.RefreshAncestorContentRoles(platformView); #endif } diff --git a/src/Core/src/Platform/iOS/SemanticExtensions.cs b/src/Core/src/Platform/iOS/SemanticExtensions.cs index 3010fce0aa18..008a0d4747b8 100644 --- a/src/Core/src/Platform/iOS/SemanticExtensions.cs +++ b/src/Core/src/Platform/iOS/SemanticExtensions.cs @@ -384,6 +384,9 @@ internal static bool MapContentAccessibilityRole(IViewHandler handler, bool? rol return true; } + internal static bool IsNonTransparent(IViewHandler handler, UIView platformView) => + platformView.Alpha > 0 && (handler.ContainerView is not UIView container || container.Alpha > 0); + internal static bool IsAccessibleLeaf(IViewHandler handler, UIView view) => view.IsAccessibilityElement && IsAccessibleBranch(view) && (handler.ContainerView is not UIView container || ReferenceEquals(container, view) From 6f34e05fd22d181e5990f6494c93342d656a5378 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Tue, 1 Dec 2026 05:13:10 +0000 Subject: [PATCH 38/62] Refresh compatibility accessibility roles after semantics mapping Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../Handlers/VisualElementRenderer.cs | 9 ++++ .../Handlers/iOS/VisualElementRenderer.cs | 3 +- .../ContentAccessibilityTests.iOS.cs | 47 +++++++++++++++++++ src/Core/src/Handlers/View/ViewHandler.cs | 5 +- .../src/Platform/iOS/SemanticExtensions.cs | 7 ++- 5 files changed, 67 insertions(+), 4 deletions(-) diff --git a/src/Controls/src/Core/Compatibility/Handlers/VisualElementRenderer.cs b/src/Controls/src/Core/Compatibility/Handlers/VisualElementRenderer.cs index 0153313c5763..3e004e1682fa 100644 --- a/src/Controls/src/Core/Compatibility/Handlers/VisualElementRenderer.cs +++ b/src/Controls/src/Core/Compatibility/Handlers/VisualElementRenderer.cs @@ -121,7 +121,13 @@ protected virtual void OnElementChanged(ElementChangedEventArgs e) protected virtual void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e) { if (Element is TElement element && e.PropertyName != null) + { _mapper.UpdateProperty(this, element, e.PropertyName); +#if IOS || MACCATALYST + if (e.PropertyName == nameof(IView.Semantics) && ((IElementHandler)this).PlatformView is PlatformView platformView) + Microsoft.Maui.Platform.SemanticExtensions.RefreshAncestorContentRoles(platformView); +#endif + } ElementPropertyChanged?.Invoke(sender, e); ElementPropertyChangedPartial(sender, e); @@ -307,6 +313,9 @@ void IElementHandler.SetVirtualView(Maui.IElement view) // We use _virtualView as a WeakReference, and clear _tempElement _virtualView = _tempElement is null ? null : new(_tempElement); _tempElement = null; + + if (((IElementHandler)this).PlatformView is PlatformView platformView) + Microsoft.Maui.Platform.SemanticExtensions.RefreshAncestorContentRoles(platformView); } #else void IElementHandler.SetVirtualView(Maui.IElement view) => diff --git a/src/Controls/src/Core/Compatibility/Handlers/iOS/VisualElementRenderer.cs b/src/Controls/src/Core/Compatibility/Handlers/iOS/VisualElementRenderer.cs index aad33b3d4faf..712f0f1bccf8 100644 --- a/src/Controls/src/Core/Compatibility/Handlers/iOS/VisualElementRenderer.cs +++ b/src/Controls/src/Core/Compatibility/Handlers/iOS/VisualElementRenderer.cs @@ -6,7 +6,8 @@ namespace Microsoft.Maui.Controls.Handlers.Compatibility { - public abstract partial class VisualElementRenderer : UIView, IPlatformViewHandler, IElementHandler, IPlatformMeasureInvalidationController + public abstract partial class VisualElementRenderer : UIView, IPlatformViewHandler, IElementHandler, IPlatformMeasureInvalidationController, + Microsoft.Maui.Platform.IRefreshesContentRolesAfterMapping where TElement : Element, IView { bool _invalidateParentWhenMovedToWindow; diff --git a/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs b/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs index fb5efa67d292..b1d70b21c7e5 100644 --- a/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs +++ b/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs @@ -488,6 +488,53 @@ await InvokeOnMainThreadAsync(() => }); } + [Fact] + public async Task AncestorRoleUsesCompatibilityRendererFinalState() + { + var inner = new ContentView { Content = new BoxView() }; + SemanticProperties.SetDescription(inner, "Inner"); + var outer = new ContentView { Content = inner }; + SemanticProperties.SetDescription(outer, "Outer"); + + var renderer = await CreateHandlerAsync(inner); + var handler = await CreateHandlerAsync(outer); + await InvokeOnMainThreadAsync(() => + { + Assert.Same(renderer, inner.Handler); + var native = Assert.IsAssignableFrom(((IElementHandler)renderer).PlatformView); + Assert.False(native.IsAccessibilityElement); + Assert.True(handler.PlatformView.IsAccessibilityElement); + + renderer.BeforeExclusion = () => Assert.True(handler.PlatformView.IsAccessibilityElement); + SemanticProperties.SetHint(inner, "New hint"); + + Assert.Equal("New hint", native.AccessibilityHint); + Assert.False(native.IsAccessibilityElement); + Assert.True(handler.PlatformView.IsAccessibilityElement); + }); + } + + sealed class ExcludedContentViewRenderer : Microsoft.Maui.Controls.Handlers.Compatibility.ViewRenderer + { + public Action? BeforeExclusion { get; set; } + + public ExcludedContentViewRenderer() : base(CreateMapper()) + { + } + + static PropertyMapper CreateMapper() + { + var mapper = new PropertyMapper(VisualElementRendererMapper); + mapper.AppendToMapping(nameof(IView.Semantics), (handler, _) => + { + ((ExcludedContentViewRenderer)handler).BeforeExclusion?.Invoke(); + if (handler.PlatformView is UIView native) + native.IsAccessibilityElement = false; + }); + return mapper; + } + } + sealed class ExcludedContentViewHandler : ContentViewHandler { public ExcludedContentViewHandler() : base(CreateMapper()) diff --git a/src/Core/src/Handlers/View/ViewHandler.cs b/src/Core/src/Handlers/View/ViewHandler.cs index 4f2538c4d8ad..d114ac453a67 100644 --- a/src/Core/src/Handlers/View/ViewHandler.cs +++ b/src/Core/src/Handlers/View/ViewHandler.cs @@ -662,8 +662,9 @@ public static void MapSemantics(IViewHandler handler, IView view) MappingSemantics(handler, view); ((PlatformView?)handler.PlatformView)?.UpdateSemantics(view); #if __IOS__ || MACCATALYST - // Compatibility handlers do not use ElementHandler's post-mapping path. - if (handler is not ElementHandler && handler.PlatformView is PlatformView platformView) + // Independent handlers may not have a post-mapping path. + if (handler is not (ElementHandler or IRefreshesContentRolesAfterMapping) + && handler.PlatformView is PlatformView platformView) SemanticExtensions.RefreshAncestorContentRoles(platformView); #endif } diff --git a/src/Core/src/Platform/iOS/SemanticExtensions.cs b/src/Core/src/Platform/iOS/SemanticExtensions.cs index 008a0d4747b8..c296967542d5 100644 --- a/src/Core/src/Platform/iOS/SemanticExtensions.cs +++ b/src/Core/src/Platform/iOS/SemanticExtensions.cs @@ -12,6 +12,10 @@ internal interface IContentViewAccessibility bool? IsInAccessibleTree { get; } } + internal interface IRefreshesContentRolesAfterMapping + { + } + public static partial class SemanticExtensions { static readonly ConditionalWeakTable s_contentSemanticsDefaults = new(); @@ -351,7 +355,8 @@ internal static bool RefreshContentSemantics(IViewHandler handler) internal static void ContentChanged(IViewHandler handler) { - if (handler.PlatformView is UIView platformView && (!RefreshContentSemantics(handler) || handler is not Handlers.ElementHandler)) + if (handler.PlatformView is UIView platformView && (!RefreshContentSemantics(handler) + || handler is not (Handlers.ElementHandler or IRefreshesContentRolesAfterMapping))) RefreshAncestorContentRoles(platformView); } From 143d10a2310e8882e50a431b36a0eaeb8c0d5fd2 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Tue, 1 Dec 2026 05:13:22 +0000 Subject: [PATCH 39/62] Recognize virtual UIKit accessibility descendants Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../ContentAccessibilityTests.iOS.cs | 39 +++++++++++++++++++ .../src/Platform/iOS/SemanticExtensions.cs | 8 +++- 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs b/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs index b1d70b21c7e5..4f4c6e909b07 100644 --- a/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs +++ b/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs @@ -357,6 +357,45 @@ await InvokeOnMainThreadAsync(() => }); } + [Fact] + public async Task ContentRoleRecognizesExplicitNativeAccessibilityElements() + { + var child = new BoxView(); + var parent = new Border { Content = child }; + SemanticProperties.SetDescription(parent, "Chart"); + var childHandler = await CreateHandlerAsync(child); + var parentHandler = await CreateHandlerAsync(parent); + + await InvokeOnMainThreadAsync(() => + { + Assert.Same(childHandler, child.Handler); + Assert.False(childHandler.PlatformView.IsAccessibilityElement); + Assert.Empty(childHandler.PlatformView.Subviews); + Assert.False(parentHandler.PlatformView.IsAccessibilityElement); + Assert.True(parentHandler.PlatformView.ShouldGroupAccessibilityChildren); + }); + } + + sealed class NativeAccessibilityContainerHandler : ViewHandler + { + public NativeAccessibilityContainerHandler() : base(ViewMapper) + { + } + + protected override UIView CreatePlatformView() + { + var view = new UIView(); + using var key = new Foundation.NSString("accessibilityElements"); + using var elements = Foundation.NSArray.FromNSObjects(new UIAccessibilityElement(view) + { + AccessibilityLabel = "Chart segment", + IsAccessibilityElement = true, + }); + view.SetValueForKey(elements, key); + return view; + } + } + [Fact] public async Task AccessibilityActivateUsesNativeActivationPoint() { diff --git a/src/Core/src/Platform/iOS/SemanticExtensions.cs b/src/Core/src/Platform/iOS/SemanticExtensions.cs index c296967542d5..7a5bd8033e79 100644 --- a/src/Core/src/Platform/iOS/SemanticExtensions.cs +++ b/src/Core/src/Platform/iOS/SemanticExtensions.cs @@ -2,6 +2,8 @@ using System.Collections.Generic; using System.Runtime.CompilerServices; using System.Text; +using Foundation; +using ObjCRuntime; using UIKit; namespace Microsoft.Maui.Platform @@ -20,6 +22,8 @@ public static partial class SemanticExtensions { static readonly ConditionalWeakTable s_contentSemanticsDefaults = new(); static readonly ConditionalWeakTable s_contentRoleDefaults = new(); + static readonly Selector s_accessibilityElementsSelector = new("accessibilityElements"); + static readonly NSString s_accessibilityElementsKey = new("accessibilityElements"); const int MaxAccessibleSubviewDepth = 32; [ThreadStatic] static VisibilityRefreshBatch? s_visibilityRefreshBatch; @@ -412,7 +416,9 @@ static bool HasAccessibleSubview(UIView platformView, int depth) return true; } - return false; + // UIKit's informal container API also exposes virtual elements with no corresponding UIView. + return platformView.RespondsToSelector(s_accessibilityElementsSelector) + && platformView.ValueForKey(s_accessibilityElementsKey) is NSArray { Count: > 0 }; } sealed class ContentRoleDefault(bool value) From 6ccfa0cc1b92b9fab3a4515223c397482cb45a54 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Tue, 1 Dec 2026 05:13:30 +0000 Subject: [PATCH 40/62] Distinguish parent and local accessibility activation coordinates Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../Elements/Accessibility/ContentAccessibilityTests.iOS.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs b/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs index 4f4c6e909b07..3f6b61fb9d80 100644 --- a/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs +++ b/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs @@ -405,7 +405,7 @@ public async Task AccessibilityActivateUsesNativeActivationPoint() Content = new Label { Text = "Action" }, GestureRecognizers = { tap }, }; - var parent = new ContentView { Content = border }; + var parent = new ContentView { Content = border, Padding = new Thickness(18, 30) }; SemanticProperties.SetDescription(border, "Action"); TappedEventArgs? tapped = null; tap.Tapped += (_, args) => tapped = args; @@ -417,6 +417,7 @@ await CreateHandlerAndAddToWindow(parent, handler => var point = new CoreGraphics.CGPoint(12, 24); var windowPoint = native.ConvertPointToView(point, window); var parentPoint = native.ConvertPointToView(point, handler.PlatformView); + Assert.NotEqual(point, parentPoint); native.AccessibilityActivationPoint = window.ConvertPointToWindow(windowPoint, null); Assert.Equal(window.ConvertPointToWindow(windowPoint, null), native.AccessibilityActivationPoint); From 8c41f7bd5439c7ff7c0fa1f9ec3b1d24e479905d Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Tue, 1 Dec 2026 07:01:00 +0000 Subject: [PATCH 41/62] Keep accessible content-host description edits local Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../ContentAccessibilityTests.iOS.cs | 26 +++++++++++++++++++ .../src/Handlers/Element/ElementHandler.cs | 4 +-- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs b/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs index 3f6b61fb9d80..7d5cb3074478 100644 --- a/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs +++ b/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs @@ -190,6 +190,32 @@ await InvokeOnMainThreadAsync(() => }); } + [Fact] + public async Task UpdatingAccessibleBorderTextDoesNotRemapAncestorRole() + { + var item = new Border + { + Content = new Label { Text = "Action" }, + GestureRecognizers = { new TapGestureRecognizer() }, + }; + SemanticProperties.SetDescription(item, "First"); + var view = new ContentView { Content = new Grid { item } }; + SemanticProperties.SetDescription(view, "Actions"); + var handler = await CreateHandlerAsync(view); + + await InvokeOnMainThreadAsync(() => + { + var native = Assert.IsAssignableFrom(item.Handler?.PlatformView); + Assert.True(native.IsAccessibilityElement); + Assert.False(handler.PlatformView.IsAccessibilityElement); + var count = handler.SemanticsUpdates; + SemanticProperties.SetDescription(item, "Second"); + Assert.Equal("Second", native.AccessibilityLabel); + Assert.True(native.IsAccessibilityElement); + Assert.Equal(count, handler.SemanticsUpdates); + }); + } + [Fact] public async Task AncestorRoleUsesFinalMappedOpacity() { diff --git a/src/Core/src/Handlers/Element/ElementHandler.cs b/src/Core/src/Handlers/Element/ElementHandler.cs index 007930c4a1e4..30b9a915a0f7 100644 --- a/src/Core/src/Handlers/Element/ElementHandler.cs +++ b/src/Core/src/Handlers/Element/ElementHandler.cs @@ -141,9 +141,7 @@ public virtual void UpdateValue(string property) #if __IOS__ || MACCATALYST if (property == nameof(IView.Semantics) && this is IViewHandler handler && PlatformView is UIKit.UIView platformView) { - bool wasAccessibleLeaf = handler.VirtualView is { } view - && !Platform.SemanticExtensions.UsesContentSemantics(platformView, view) - && Platform.SemanticExtensions.IsAccessibleLeaf(handler, platformView); + bool wasAccessibleLeaf = Platform.SemanticExtensions.IsAccessibleLeaf(handler, platformView); _mapper?.UpdateProperty(this, VirtualView, property); // A non-leaf mapper can change accessible descendants without changing this view's flags. if (!wasAccessibleLeaf || !ReferenceEquals(platformView, PlatformView) From b01cb3d2fbeb94e07eee6c46adf88b83b7cd415d Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Tue, 1 Dec 2026 07:01:00 +0000 Subject: [PATCH 42/62] Refresh compatibility accessibility after opacity mapping Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../Handlers/VisualElementRenderer.cs | 12 ++++- .../ContentAccessibilityTests.iOS.cs | 46 +++++++++++++++++++ src/Core/src/Handlers/View/ViewHandler.cs | 3 +- 3 files changed, 59 insertions(+), 2 deletions(-) diff --git a/src/Controls/src/Core/Compatibility/Handlers/VisualElementRenderer.cs b/src/Controls/src/Core/Compatibility/Handlers/VisualElementRenderer.cs index 3e004e1682fa..c9af4d78da53 100644 --- a/src/Controls/src/Core/Compatibility/Handlers/VisualElementRenderer.cs +++ b/src/Controls/src/Core/Compatibility/Handlers/VisualElementRenderer.cs @@ -122,9 +122,19 @@ protected virtual void OnElementPropertyChanged(object sender, PropertyChangedEv { if (Element is TElement element && e.PropertyName != null) { +#if IOS || MACCATALYST + var opacityView = e.PropertyName == nameof(IView.Opacity) + ? ((IElementHandler)this).PlatformView as PlatformView : null; + bool wasNonTransparent = opacityView is not null + && Microsoft.Maui.Platform.SemanticExtensions.IsNonTransparent(this, opacityView); +#endif _mapper.UpdateProperty(this, element, e.PropertyName); #if IOS || MACCATALYST - if (e.PropertyName == nameof(IView.Semantics) && ((IElementHandler)this).PlatformView is PlatformView platformView) + if ((e.PropertyName == nameof(IView.Semantics) || + opacityView is not null) && + ((IElementHandler)this).PlatformView is PlatformView platformView && + (opacityView is null || !ReferenceEquals(opacityView, platformView) || + wasNonTransparent != Microsoft.Maui.Platform.SemanticExtensions.IsNonTransparent(this, platformView))) Microsoft.Maui.Platform.SemanticExtensions.RefreshAncestorContentRoles(platformView); #endif } diff --git a/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs b/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs index 7d5cb3074478..1b4f0883ea56 100644 --- a/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs +++ b/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs @@ -216,6 +216,52 @@ await InvokeOnMainThreadAsync(() => }); } + [Fact] + public async Task AncestorRoleUsesFinalMappedCompatibilityOpacity() + { + var child = new BoxView(); + var view = new ContentView { Content = child }; + SemanticProperties.SetDescription(view, "Actions"); + var renderer = await CreateHandlerAsync(child); + var handler = await CreateHandlerAsync(view); + + await InvokeOnMainThreadAsync(() => + { + Assert.Same(renderer, child.Handler); + Assert.False(handler.PlatformView.IsAccessibilityElement); + var count = handler.SemanticsUpdates; + child.Opacity = 0; + Assert.True(renderer.Alpha > 0); + Assert.False(handler.PlatformView.IsAccessibilityElement); + Assert.Equal(count, handler.SemanticsUpdates); + }); + } + + sealed class MinimumOpacityRenderer : Microsoft.Maui.Controls.Handlers.Compatibility.ViewRenderer + { + public MinimumOpacityRenderer() : base(CreateMapper()) + { + } + + protected override void OnElementChanged(ElementChangedEventArgs e) + { + base.OnElementChanged(e); + if (e.NewElement is not null && Control is null) + SetNativeControl(new UILabel { Text = "Action", IsAccessibilityElement = true }); + } + + static PropertyMapper CreateMapper() + { + var mapper = new PropertyMapper(VisualElementRendererMapper); + mapper.AppendToMapping(nameof(IView.Opacity), (handler, _) => + { + if (handler.ContainerView is UIView wrapper && wrapper.Alpha == 0) + wrapper.Alpha = 0.1f; + }); + return mapper; + } + } + [Fact] public async Task AncestorRoleUsesFinalMappedOpacity() { diff --git a/src/Core/src/Handlers/View/ViewHandler.cs b/src/Core/src/Handlers/View/ViewHandler.cs index d114ac453a67..d19b475a0d5a 100644 --- a/src/Core/src/Handlers/View/ViewHandler.cs +++ b/src/Core/src/Handlers/View/ViewHandler.cs @@ -580,7 +580,8 @@ public static void MapOpacity(IViewHandler handler, IView view) #endif #if __IOS__ || MACCATALYST - var platformView = handler is not ElementHandler ? handler.PlatformView as PlatformView : null; + var platformView = handler is not (ElementHandler or IRefreshesContentRolesAfterMapping) + ? handler.PlatformView as PlatformView : null; bool wasNonTransparent = platformView is not null && SemanticExtensions.IsNonTransparent(handler, platformView); #endif From 979d6b6165bc2ec9b389ae7a1c24551ae8d70182 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Tue, 1 Dec 2026 07:01:00 +0000 Subject: [PATCH 43/62] Refresh accessibility after automation mapper appends Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../Handlers/VisualElementRenderer.cs | 1 + src/Controls/src/Core/Element/Element.iOS.cs | 4 +- .../ContentAccessibilityTests.iOS.cs | 91 +++++++++++++++++++ .../src/Handlers/Element/ElementHandler.cs | 4 + .../src/Platform/iOS/SemanticExtensions.cs | 20 +++- 5 files changed, 116 insertions(+), 4 deletions(-) diff --git a/src/Controls/src/Core/Compatibility/Handlers/VisualElementRenderer.cs b/src/Controls/src/Core/Compatibility/Handlers/VisualElementRenderer.cs index c9af4d78da53..441a79205406 100644 --- a/src/Controls/src/Core/Compatibility/Handlers/VisualElementRenderer.cs +++ b/src/Controls/src/Core/Compatibility/Handlers/VisualElementRenderer.cs @@ -131,6 +131,7 @@ protected virtual void OnElementPropertyChanged(object sender, PropertyChangedEv _mapper.UpdateProperty(this, element, e.PropertyName); #if IOS || MACCATALYST if ((e.PropertyName == nameof(IView.Semantics) || + e.PropertyName == AutomationProperties.IsInAccessibleTreeProperty.PropertyName || opacityView is not null) && ((IElementHandler)this).PlatformView is PlatformView platformView && (opacityView is null || !ReferenceEquals(opacityView, platformView) || diff --git a/src/Controls/src/Core/Element/Element.iOS.cs b/src/Controls/src/Core/Element/Element.iOS.cs index cca8e6ba578f..39b29a392299 100644 --- a/src/Controls/src/Core/Element/Element.iOS.cs +++ b/src/Controls/src/Core/Element/Element.iOS.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; using System.Text; +using Microsoft.Maui.Handlers; using UIKit; namespace Microsoft.Maui.Controls @@ -32,7 +33,8 @@ public static void MapAutomationPropertiesIsInAccessibleTree(IElementHandler han var _defaultIsAccessibilityElement = Control.IsAccessibilityElement || Control is UIControl; Control.IsAccessibilityElement = (bool)((bool?)element.GetValue(AutomationProperties.IsInAccessibleTreeProperty) ?? _defaultIsAccessibilityElement); - Microsoft.Maui.Platform.SemanticExtensions.RefreshAncestorContentRoles(Control); + if (handler is not (ElementHandler or Microsoft.Maui.Platform.IRefreshesContentRolesAfterMapping)) + Microsoft.Maui.Platform.SemanticExtensions.RefreshAncestorContentRoles(Control); } public static void MapAutomationPropertiesExcludedWithChildren(IElementHandler handler, Element view) diff --git a/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs b/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs index 1b4f0883ea56..5833ab508839 100644 --- a/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs +++ b/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs @@ -262,6 +262,97 @@ static PropertyMapper CreateMapper() } } + [Fact] + public async Task AncestorRoleUsesFinalMappedAutomationInclusion() + { + var button = new Button { Text = "Action" }; + AutomationProperties.SetIsInAccessibleTree(button, false); + var view = new ContentView { Content = button }; + SemanticProperties.SetDescription(view, "Actions"); + var buttonHandler = await CreateHandlerAsync(button); + var handler = await CreateHandlerAsync(view); + + await InvokeOnMainThreadAsync(() => + { + Assert.Same(buttonHandler, button.Handler); + Assert.True(handler.PlatformView.IsAccessibilityElement); + AutomationProperties.SetIsInAccessibleTree(button, true); + Assert.False(buttonHandler.PlatformView.IsAccessibilityElement); + Assert.True(handler.PlatformView.IsAccessibilityElement); + Assert.False(handler.PlatformView.ShouldGroupAccessibilityChildren); + }); + } + + [Fact] + public async Task ContentRoleDoesNotRefreshAncestorDuringAutomationAppend() + { + var child = new ContentView { Content = new BoxView() }; + SemanticProperties.SetDescription(child, "Child"); + AutomationProperties.SetIsInAccessibleTree(child, false); + var view = new ContentView { Content = child }; + SemanticProperties.SetDescription(view, "Actions"); + var childHandler = await CreateHandlerAsync(child); + var handler = await CreateHandlerAsync(view); + + await InvokeOnMainThreadAsync(() => + { + Assert.Same(childHandler, child.Handler); + Assert.True(handler.PlatformView.IsAccessibilityElement); + int count = handler.SemanticsUpdates; + childHandler.BeforeExclusion = () => Assert.Equal(count, handler.SemanticsUpdates); + AutomationProperties.SetIsInAccessibleTree(child, true); + Assert.False(childHandler.PlatformView.IsAccessibilityElement); + Assert.True(handler.PlatformView.IsAccessibilityElement); + }); + } + + sealed class AutomationExcludingContentViewHandler : ContentViewHandler + { + public Action? BeforeExclusion { get; set; } + + public AutomationExcludingContentViewHandler() : base(CreateMapper()) + { + } + + static PropertyMapper CreateMapper() + { + var mapper = new PropertyMapper(Mapper); + mapper.AppendToMapping(AutomationProperties.IsInAccessibleTreeProperty.PropertyName, (handler, content) => + { + if (content is BindableObject bindable && AutomationProperties.GetIsInAccessibleTree(bindable) == true) + { + ((AutomationExcludingContentViewHandler)handler).BeforeExclusion?.Invoke(); + handler.PlatformView.IsAccessibilityElement = false; + } + }); + return mapper; + } + } + + sealed class ExcludedButtonHandler : ButtonHandler + { + public ExcludedButtonHandler() : base(CreateMapper()) + { + } + + static PropertyMapper CreateMapper() + { + var mapper = new PropertyMapper(Mapper); + mapper.AppendToMapping(AutomationProperties.IsInAccessibleTreeProperty.PropertyName, + (handler, button) => + { + if (button is BindableObject bindable && AutomationProperties.GetIsInAccessibleTree(bindable) == true) + handler.PlatformView.IsAccessibilityElement = false; + }); + mapper.AppendToMapping(nameof(IView.Semantics), (handler, button) => + { + if (button.Semantics?.Description == "Exclude from semantics") + handler.PlatformView.IsAccessibilityElement = false; + }); + return mapper; + } + } + [Fact] public async Task AncestorRoleUsesFinalMappedOpacity() { diff --git a/src/Core/src/Handlers/Element/ElementHandler.cs b/src/Core/src/Handlers/Element/ElementHandler.cs index 30b9a915a0f7..ed91668489da 100644 --- a/src/Core/src/Handlers/Element/ElementHandler.cs +++ b/src/Core/src/Handlers/Element/ElementHandler.cs @@ -162,6 +162,10 @@ public virtual void UpdateValue(string property) } #endif _mapper?.UpdateProperty(this, VirtualView, property); +#if __IOS__ || MACCATALYST + if (property == nameof(Platform.IContentViewAccessibility.IsInAccessibleTree)) + RefreshAncestorContentRoles(); +#endif } #if __IOS__ || MACCATALYST diff --git a/src/Core/src/Platform/iOS/SemanticExtensions.cs b/src/Core/src/Platform/iOS/SemanticExtensions.cs index 7a5bd8033e79..a02e44399b22 100644 --- a/src/Core/src/Platform/iOS/SemanticExtensions.cs +++ b/src/Core/src/Platform/iOS/SemanticExtensions.cs @@ -27,6 +27,8 @@ public static partial class SemanticExtensions const int MaxAccessibleSubviewDepth = 32; [ThreadStatic] static VisibilityRefreshBatch? s_visibilityRefreshBatch; + [ThreadStatic] + static UIView? s_mappingExplicitRole; internal static VisibilityRefreshBatch? BeginVisibilityRefresh() => s_visibilityRefreshBatch is null ? s_visibilityRefreshBatch = new() : null; @@ -303,7 +305,8 @@ static void ApplyContentRole(UIView platformView, IContentView view, ContentSema internal static void RefreshAncestorContentRoles(UIView platformView) { - if (s_contentSemanticsDefaults.TryGetValue(platformView, out var current) && current.IsRefreshingMapper) + if (ReferenceEquals(s_mappingExplicitRole, platformView) + || (s_contentSemanticsDefaults.TryGetValue(platformView, out var current) && current.IsRefreshingMapper)) return; // Run the effective mapper inside-out, including app appends, before visiting the next host. @@ -383,13 +386,24 @@ internal static bool MapContentAccessibilityRole(IViewHandler handler, bool? rol s_contentRoleDefaults.Remove(platformView); } - RefreshContentSemantics(handler); + var previousMapping = s_mappingExplicitRole; + // This Semantics update is part of the active automation mapping, not its final state. + s_mappingExplicitRole = platformView; + try + { + RefreshContentSemantics(handler); + } + finally + { + s_mappingExplicitRole = previousMapping; + } // A replacement Semantics mapping can map the label and hint without applying the role. if (role.HasValue) platformView.IsAccessibilityElement = role.Value; - RefreshAncestorContentRoles(platformView); + if (handler is not (Handlers.ElementHandler or IRefreshesContentRolesAfterMapping)) + RefreshAncestorContentRoles(platformView); return true; } From e30cdc87c615c5f63e05be97bcde6d4d11f2f7f6 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Tue, 1 Dec 2026 07:01:00 +0000 Subject: [PATCH 44/62] Replay reentrant descendant accessibility invalidation Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../ContentAccessibilityTests.iOS.cs | 37 +++++++++++++++++++ .../src/Platform/iOS/SemanticExtensions.cs | 15 ++++++++ 2 files changed, 52 insertions(+) diff --git a/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs b/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs index 5833ab508839..d33c8b5d89c8 100644 --- a/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs +++ b/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs @@ -353,6 +353,43 @@ static PropertyMapper CreateMapper() } } + [Fact] + public async Task ContentRoleRechecksDescendantVisibilityChangedByItsMapper() + { + var button = new Button { Text = "Action", IsVisible = false }; + var view = new ContentView { Content = button }; + SemanticProperties.SetDescription(view, "Actions"); + var handler = await CreateHandlerAsync(view); + + await InvokeOnMainThreadAsync(() => + { + Assert.False(button.IsVisible); + Assert.True(handler.PlatformView.IsAccessibilityElement); + button.IsVisible = true; + Assert.False(button.IsVisible); + Assert.True(handler.PlatformView.IsAccessibilityElement); + Assert.False(handler.PlatformView.ShouldGroupAccessibilityChildren); + }); + } + + sealed class HidesChildContentViewHandler : ContentViewHandler + { + public HidesChildContentViewHandler() : base(CreateMapper()) + { + } + + static PropertyMapper CreateMapper() + { + var mapper = new PropertyMapper(Mapper); + mapper.AppendToMapping(nameof(IView.Semantics), (_, view) => + { + if (view.PresentedContent is Button button) + button.IsVisible = false; + }); + return mapper; + } + } + [Fact] public async Task AncestorRoleUsesFinalMappedOpacity() { diff --git a/src/Core/src/Platform/iOS/SemanticExtensions.cs b/src/Core/src/Platform/iOS/SemanticExtensions.cs index a02e44399b22..19825bf21187 100644 --- a/src/Core/src/Platform/iOS/SemanticExtensions.cs +++ b/src/Core/src/Platform/iOS/SemanticExtensions.cs @@ -57,7 +57,10 @@ internal void Collect(UIView? ancestor) if (s_contentSemanticsDefaults.TryGetValue(ancestor, out var saved)) { if (saved.IsRefreshingMapper) + { + saved.NeedsRoleRefresh = true; break; + } (_hosts ??= new()).Add(ancestor); } } @@ -327,16 +330,27 @@ static bool RefreshContentHost(UIView ancestor) { // The active walk will continue past this host after its mapper finishes. if (saved.IsRefreshingMapper) + { + saved.NeedsRoleRefresh = true; return false; + } saved.IsRefreshingMapper = true; try { handler.UpdateValue(nameof(IView.Semantics)); + // Replay once with the final descendant state, preserving app mapper overrides. + // A mapper which repeatedly mutates the tree must not cause an endless refresh. + if (saved.NeedsRoleRefresh) + { + saved.NeedsRoleRefresh = false; + handler.UpdateValue(nameof(IView.Semantics)); + } } finally { saved.IsRefreshingMapper = false; + saved.NeedsRoleRefresh = false; } } @@ -452,6 +466,7 @@ sealed class ContentSemanticsDefaults(UIView platformView) public bool HasSemanticHeading { get; private set; } public bool IsRefreshingMapper { get; set; } + public bool NeedsRoleRefresh { get; set; } public void SetContent(IContentView view, bool isHeading) { From 97d09cf3522c96661dfe7c64c53d3db9a7603214 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Tue, 1 Dec 2026 07:01:00 +0000 Subject: [PATCH 45/62] Honor explicit native accessibility elements Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../ContentAccessibilityTests.iOS.cs | 26 +++++++---- .../src/Platform/iOS/SemanticExtensions.cs | 45 ++++++++++++++++--- 2 files changed, 57 insertions(+), 14 deletions(-) diff --git a/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs b/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs index d33c8b5d89c8..00ff53b09f63 100644 --- a/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs +++ b/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs @@ -557,10 +557,13 @@ await InvokeOnMainThreadAsync(() => }); } - [Fact] - public async Task ContentRoleRecognizesExplicitNativeAccessibilityElements() + [Theory] + [InlineData("Eligible", true)] + [InlineData("Ineligible", false)] + [InlineData("Empty", false)] + public async Task ContentRoleRecognizesExplicitNativeAccessibilityElements(string mode, bool hasAccessibleChild) { - var child = new BoxView(); + var child = new BoxView { AutomationId = mode }; var parent = new Border { Content = child }; SemanticProperties.SetDescription(parent, "Chart"); var childHandler = await CreateHandlerAsync(child); @@ -570,9 +573,9 @@ await InvokeOnMainThreadAsync(() => { Assert.Same(childHandler, child.Handler); Assert.False(childHandler.PlatformView.IsAccessibilityElement); - Assert.Empty(childHandler.PlatformView.Subviews); - Assert.False(parentHandler.PlatformView.IsAccessibilityElement); - Assert.True(parentHandler.PlatformView.ShouldGroupAccessibilityChildren); + Assert.Equal(mode == "Empty", childHandler.PlatformView.Subviews.Length != 0); + Assert.Equal(!hasAccessibleChild, parentHandler.PlatformView.IsAccessibilityElement); + Assert.Equal(hasAccessibleChild, parentHandler.PlatformView.ShouldGroupAccessibilityChildren); }); } @@ -586,11 +589,16 @@ protected override UIView CreatePlatformView() { var view = new UIView(); using var key = new Foundation.NSString("accessibilityElements"); - using var elements = Foundation.NSArray.FromNSObjects(new UIAccessibilityElement(view) + using var entry = new UIAccessibilityElement(view) { AccessibilityLabel = "Chart segment", - IsAccessibilityElement = true, - }); + IsAccessibilityElement = VirtualView?.AutomationId == "Eligible", + }; + bool empty = VirtualView?.AutomationId == "Empty"; + if (empty) + view.AddSubview(new UILabel { Text = "Suppressed", IsAccessibilityElement = true }); + using var elements = empty ? Foundation.NSArray.FromNSObjects(Array.Empty()) + : Foundation.NSArray.FromNSObjects(entry); view.SetValueForKey(elements, key); return view; } diff --git a/src/Core/src/Platform/iOS/SemanticExtensions.cs b/src/Core/src/Platform/iOS/SemanticExtensions.cs index 19825bf21187..da66b2919d8a 100644 --- a/src/Core/src/Platform/iOS/SemanticExtensions.cs +++ b/src/Core/src/Platform/iOS/SemanticExtensions.cs @@ -24,6 +24,8 @@ public static partial class SemanticExtensions static readonly ConditionalWeakTable s_contentRoleDefaults = new(); static readonly Selector s_accessibilityElementsSelector = new("accessibilityElements"); static readonly NSString s_accessibilityElementsKey = new("accessibilityElements"); + static readonly Selector s_isAccessibilityElementSelector = new("isAccessibilityElement"); + static readonly NSString s_isAccessibilityElementKey = new("isAccessibilityElement"); const int MaxAccessibleSubviewDepth = 32; [ThreadStatic] static VisibilityRefreshBatch? s_visibilityRefreshBatch; @@ -437,16 +439,49 @@ static bool HasAccessibleSubview(UIView platformView, int depth) if (depth >= MaxAccessibleSubviewDepth || platformView.AccessibilityElementsHidden) return false; + // Even an empty explicit array replaces UIKit's subview traversal. + if (GetExplicitAccessibilityElements(platformView) is { } elements) + return HasAccessibleElement(elements, depth); + foreach (var child in platformView.Subviews) { - if (!child.Hidden && child.Alpha > 0 && !child.AccessibilityElementsHidden - && (child.IsAccessibilityElement || HasAccessibleSubview(child, depth + 1))) + if (IsAccessibleBranch(child) && (child.IsAccessibilityElement || HasAccessibleSubview(child, depth + 1))) return true; } - // UIKit's informal container API also exposes virtual elements with no corresponding UIView. - return platformView.RespondsToSelector(s_accessibilityElementsSelector) - && platformView.ValueForKey(s_accessibilityElementsKey) is NSArray { Count: > 0 }; + return false; + } + + static NSArray? GetExplicitAccessibilityElements(NSObject container) => + container.RespondsToSelector(s_accessibilityElementsSelector) + ? container.ValueForKey(s_accessibilityElementsKey) as NSArray : null; + + static bool HasAccessibleElement(NSArray elements, int depth) + { + if (depth >= MaxAccessibleSubviewDepth) + return false; + + var count = elements.Count; + for (nuint i = 0; i < count; i++) + { + var entry = elements.GetItem(i); + if (entry is UIView view) + { + if (IsAccessibleBranch(view) && (view.IsAccessibilityElement || HasAccessibleSubview(view, depth + 1))) + return true; + } + else if (entry is not null) + { + if (entry is UIAccessibilityElement element ? element.IsAccessibilityElement + : entry.RespondsToSelector(s_isAccessibilityElementSelector) + && entry.ValueForKey(s_isAccessibilityElementKey) is NSNumber { BoolValue: true }) + return true; + if (GetExplicitAccessibilityElements(entry) is { } children && HasAccessibleElement(children, depth + 1)) + return true; + } + } + + return false; } sealed class ContentRoleDefault(bool value) From c4055546d270056f200e978d4a334c32345da8c7 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Tue, 1 Dec 2026 07:01:01 +0000 Subject: [PATCH 46/62] Test accessible Button exclusion after Semantics mapping Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../ContentAccessibilityTests.iOS.cs | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs b/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs index 00ff53b09f63..9d563a4d63ea 100644 --- a/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs +++ b/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs @@ -329,6 +329,27 @@ static PropertyMapper CreateMapper() } } + [Fact] + public async Task ExcludingAnAccessibleButtonFromItsSemanticsMapperRefreshesAncestorRole() + { + var button = new Button { Text = "Action" }; + SemanticProperties.SetDescription(button, "First"); + var view = new ContentView { Content = button }; + SemanticProperties.SetDescription(view, "Actions"); + var buttonHandler = await CreateHandlerAsync(button); + var handler = await CreateHandlerAsync(view); + + await InvokeOnMainThreadAsync(() => + { + Assert.Same(buttonHandler, button.Handler); + Assert.True(buttonHandler.PlatformView.IsAccessibilityElement); + Assert.False(handler.PlatformView.IsAccessibilityElement); + SemanticProperties.SetDescription(button, "Exclude from semantics"); + Assert.False(buttonHandler.PlatformView.IsAccessibilityElement); + Assert.True(handler.PlatformView.IsAccessibilityElement); + }); + } + sealed class ExcludedButtonHandler : ButtonHandler { public ExcludedButtonHandler() : base(CreateMapper()) From 246d31c31f35dfe769af31a64a4749dcf4c62fd1 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Tue, 1 Dec 2026 07:01:01 +0000 Subject: [PATCH 47/62] Test settled collection layouts skip ancestor refresh Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../ContentAccessibilityTests.iOS.cs | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs b/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs index 9d563a4d63ea..8d31eff69d86 100644 --- a/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs +++ b/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs @@ -499,13 +499,19 @@ public async Task DeferredCollectionItemsRemapAncestorAccessibilityRole() var border = new Border { Content = collection, HeightRequest = 120, WidthRequest = 120 }; SemanticProperties.SetDescription(border, "Actions"); - await CreateHandlerAndAddToWindow(border, async handler => + await CreateHandlerAndAddToWindow(border, async handler => { Assert.True(handler.PlatformView.IsAccessibilityElement); collection.ItemsSource = new[] { "Action" }; await AssertEventually(() => !handler.PlatformView.IsAccessibilityElement && handler.PlatformView.ShouldGroupAccessibilityChildren, timeout: 5000); + var native = Assert.IsAssignableFrom(collection.Handler?.PlatformView); + native.LayoutSubviews(); + int count = handler.SemanticsUpdates; + native.LayoutSubviews(); + native.LayoutSubviews(); + Assert.Equal(count, handler.SemanticsUpdates); collection.ItemsSource = Array.Empty(); await AssertEventually(() => handler.PlatformView.IsAccessibilityElement && @@ -513,6 +519,22 @@ await AssertEventually(() => handler.PlatformView.IsAccessibilityElement && }); } + sealed class CountingBorderHandler : BorderHandler + { + public int SemanticsUpdates { get; private set; } + + public CountingBorderHandler() : base(CreateMapper()) + { + } + + static PropertyMapper CreateMapper() + { + var mapper = new PropertyMapper(Mapper); + mapper.AppendToMapping(nameof(IView.Semantics), (handler, _) => ((CountingBorderHandler)handler).SemanticsUpdates++); + return mapper; + } + } + [Theory] [InlineData(true)] [InlineData(false)] From 9792d57b341be8cbb6a82e801412c2707e4c5e9a Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Tue, 1 Dec 2026 08:40:00 +0000 Subject: [PATCH 48/62] [iOS] Batch BindableLayout accessibility role refreshes Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../src/Core/BindableLayout/BindableLayout.cs | 13 +++++ .../src/Core/VisualElement/VisualElement.cs | 2 +- .../ContentAccessibilityTests.iOS.cs | 21 ++++++++ .../src/Platform/iOS/SemanticExtensions.cs | 48 ++++++++++++++----- 4 files changed, 71 insertions(+), 13 deletions(-) diff --git a/src/Controls/src/Core/BindableLayout/BindableLayout.cs b/src/Controls/src/Core/BindableLayout/BindableLayout.cs index 3201169cf6a5..774ab6b24995 100644 --- a/src/Controls/src/Core/BindableLayout/BindableLayout.cs +++ b/src/Controls/src/Core/BindableLayout/BindableLayout.cs @@ -380,6 +380,9 @@ void CreateChildren() return; } +#if IOS || MACCATALYST + using var contentRoleRefresh = BeginContentRoleRefresh(layout); +#endif if (TryAddEmptyView(layout, out IEnumerator enumerator)) { return; @@ -526,6 +529,9 @@ void ItemsSourceCollectionChanged(object sender, NotifyCollectionChangedEventArg return; } +#if IOS || MACCATALYST + using var contentRoleRefresh = BeginContentRoleRefresh(layout); +#endif if (e.Action == NotifyCollectionChangedAction.Replace) { var index = e.OldStartingIndex; @@ -570,6 +576,13 @@ void ItemsSourceCollectionChanged(object sender, NotifyCollectionChangedEventArg reset: CreateChildren); } +#if IOS || MACCATALYST + static Microsoft.Maui.Platform.SemanticExtensions.ContentRoleRefreshBatch BeginContentRoleRefresh(IBindableLayout layout) => + layout is IElement { Handler.PlatformView: UIKit.UIView } + ? Microsoft.Maui.Platform.SemanticExtensions.BeginContentRoleRefresh() + : null; +#endif + void ReplaceChild(object item, IBindableLayout layout, IList layoutChildren, int index) { var template = SelectTemplate(item, layout); diff --git a/src/Controls/src/Core/VisualElement/VisualElement.cs b/src/Controls/src/Core/VisualElement/VisualElement.cs index dfdefb0a6631..800fff3e13ec 100644 --- a/src/Controls/src/Core/VisualElement/VisualElement.cs +++ b/src/Controls/src/Core/VisualElement/VisualElement.cs @@ -1993,7 +1993,7 @@ void IPropertyPropagationController.PropagatePropertyChanged(string propertyName #if IOS || MACCATALYST using var visibilityRefresh = (propertyName == null || propertyName == IsVisibleProperty.PropertyName) && Handler?.PlatformView is UIKit.UIView - ? Microsoft.Maui.Platform.SemanticExtensions.BeginVisibilityRefresh() + ? Microsoft.Maui.Platform.SemanticExtensions.BeginContentRoleRefresh() : null; #endif if (propertyName == null || propertyName == IsVisibleProperty.PropertyName) diff --git a/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs b/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs index 8d31eff69d86..12e1637b3d08 100644 --- a/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs +++ b/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs @@ -150,6 +150,27 @@ await InvokeOnMainThreadAsync(() => }); } + [Fact] + public async Task BindableLayoutPopulationRefreshesContentHostOnce() + { + var layout = new VerticalStackLayout(); + BindableLayout.SetItemTemplate(layout, new DataTemplate(() => new Button { Text = "Action" })); + var view = new ContentView { Content = layout }; + SemanticProperties.SetDescription(view, "Actions"); + var handler = await CreateHandlerAsync(view); + + await InvokeOnMainThreadAsync(() => + { + Assert.True(handler.PlatformView.IsAccessibilityElement); + var count = handler.SemanticsUpdates; + BindableLayout.SetItemsSource(layout, new int[16]); + Assert.Equal(16, layout.Children.Count); + Assert.Equal(count + 1, handler.SemanticsUpdates); + Assert.False(handler.PlatformView.IsAccessibilityElement); + Assert.True(handler.PlatformView.ShouldGroupAccessibilityChildren); + }); + } + [Fact] public async Task ReincludingSubtreeRestoresItsContentRole() { diff --git a/src/Core/src/Platform/iOS/SemanticExtensions.cs b/src/Core/src/Platform/iOS/SemanticExtensions.cs index da66b2919d8a..b9905f173c31 100644 --- a/src/Core/src/Platform/iOS/SemanticExtensions.cs +++ b/src/Core/src/Platform/iOS/SemanticExtensions.cs @@ -28,25 +28,43 @@ public static partial class SemanticExtensions static readonly NSString s_isAccessibilityElementKey = new("isAccessibilityElement"); const int MaxAccessibleSubviewDepth = 32; [ThreadStatic] - static VisibilityRefreshBatch? s_visibilityRefreshBatch; + static ContentRoleRefreshBatch? s_contentRoleRefreshBatch; [ThreadStatic] static UIView? s_mappingExplicitRole; - internal static VisibilityRefreshBatch? BeginVisibilityRefresh() => - s_visibilityRefreshBatch is null ? s_visibilityRefreshBatch = new() : null; + internal const string ExcludedWithChildrenPropertyName = "ExcludedWithChildren"; - internal static void VisibilityChanged(UIView platformView) + [ThreadStatic] + static IElementHandler? s_roleMappingHandler; + [ThreadStatic] + static string? s_roleMappingProperty; + + internal static bool IsMappingContentRole(IElementHandler handler, string property) => + ReferenceEquals(s_roleMappingHandler, handler) && s_roleMappingProperty == property; + + internal static void UpdateContentRoleMapping(IPropertyMapper? mapper, IElementHandler handler, IElement view, string property) { - if (s_visibilityRefreshBatch is { } batch) + var previousHandler = s_roleMappingHandler; + var previousProperty = s_roleMappingProperty; + s_roleMappingHandler = handler; + s_roleMappingProperty = property; + try { - if (!s_contentSemanticsDefaults.TryGetValue(platformView, out var saved) || !saved.IsRefreshingMapper) - batch.Collect(platformView.Superview); + mapper?.UpdateProperty(handler, view, property); + } + finally + { + s_roleMappingHandler = previousHandler; + s_roleMappingProperty = previousProperty; } - else - RefreshAncestorContentRoles(platformView); } - internal sealed class VisibilityRefreshBatch : IDisposable + internal static ContentRoleRefreshBatch? BeginContentRoleRefresh() => + s_contentRoleRefreshBatch is null ? s_contentRoleRefreshBatch = new() : null; + + internal static void VisibilityChanged(UIView platformView) => RefreshAncestorContentRoles(platformView); + + internal sealed class ContentRoleRefreshBatch : IDisposable { HashSet? _visited; List? _hosts; @@ -74,11 +92,11 @@ internal void Collect(UIView? ancestor) public void Dispose() { - s_visibilityRefreshBatch = null; + s_contentRoleRefreshBatch = null; if (_hosts is null) return; - // Descendants finish mapping visibility before their content hosts are evaluated. + // Evaluate content hosts after descendants finish mapping and attaching. for (int i = _hosts.Count - 1; i >= 0; i--) RefreshContentHost(_hosts[i]); } @@ -314,6 +332,12 @@ internal static void RefreshAncestorContentRoles(UIView platformView) || (s_contentSemanticsDefaults.TryGetValue(platformView, out var current) && current.IsRefreshingMapper)) return; + if (s_contentRoleRefreshBatch is { } batch) + { + batch.Collect(platformView.Superview); + return; + } + // Run the effective mapper inside-out, including app appends, before visiting the next host. for (var ancestor = platformView.Superview; ancestor is not null; ancestor = ancestor.Superview) { From 51d09acf7f02caa62b01bad9f91bd05bf0a3248c Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Tue, 1 Dec 2026 08:41:22 +0000 Subject: [PATCH 49/62] [iOS] Skip redundant compatibility renderer accessibility rescans Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../Handlers/VisualElementRenderer.cs | 6 +++++ .../ContentAccessibilityTests.iOS.cs | 25 +++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/src/Controls/src/Core/Compatibility/Handlers/VisualElementRenderer.cs b/src/Controls/src/Core/Compatibility/Handlers/VisualElementRenderer.cs index 441a79205406..3ec97d0b0786 100644 --- a/src/Controls/src/Core/Compatibility/Handlers/VisualElementRenderer.cs +++ b/src/Controls/src/Core/Compatibility/Handlers/VisualElementRenderer.cs @@ -123,6 +123,10 @@ protected virtual void OnElementPropertyChanged(object sender, PropertyChangedEv if (Element is TElement element && e.PropertyName != null) { #if IOS || MACCATALYST + var semanticsView = e.PropertyName == nameof(IView.Semantics) + ? ((IElementHandler)this).PlatformView as PlatformView : null; + bool wasAccessibleLeaf = semanticsView is not null + && Microsoft.Maui.Platform.SemanticExtensions.IsAccessibleLeaf(this, semanticsView); var opacityView = e.PropertyName == nameof(IView.Opacity) ? ((IElementHandler)this).PlatformView as PlatformView : null; bool wasNonTransparent = opacityView is not null @@ -134,6 +138,8 @@ protected virtual void OnElementPropertyChanged(object sender, PropertyChangedEv e.PropertyName == AutomationProperties.IsInAccessibleTreeProperty.PropertyName || opacityView is not null) && ((IElementHandler)this).PlatformView is PlatformView platformView && + (!wasAccessibleLeaf || !ReferenceEquals(semanticsView, platformView) || + !Microsoft.Maui.Platform.SemanticExtensions.IsAccessibleLeaf(this, platformView)) && (opacityView is null || !ReferenceEquals(opacityView, platformView) || wasNonTransparent != Microsoft.Maui.Platform.SemanticExtensions.IsNonTransparent(this, platformView))) Microsoft.Maui.Platform.SemanticExtensions.RefreshAncestorContentRoles(platformView); diff --git a/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs b/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs index 12e1637b3d08..7b0c5914f198 100644 --- a/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs +++ b/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs @@ -283,6 +283,31 @@ static PropertyMapper CreateMapper() } } + [Fact] + public async Task UpdatingAccessibleCompatibilityTextDoesNotRemapAncestorRole() + { + var child = new BoxView(); + SemanticProperties.SetDescription(child, "First"); + var view = new ContentView { Content = new Grid { child } }; + SemanticProperties.SetDescription(view, "Actions"); + var renderer = await CreateHandlerAsync(child); + var handler = await CreateHandlerAsync(view); + + await InvokeOnMainThreadAsync(() => + { + var native = Assert.IsAssignableFrom(((IElementHandler)renderer).PlatformView); + Assert.Same(renderer, child.Handler); + Assert.True(native.IsAccessibilityElement); + Assert.False(handler.PlatformView.IsAccessibilityElement); + var count = handler.SemanticsUpdates; + SemanticProperties.SetDescription(child, "Second"); + Assert.Equal("Second", native.AccessibilityLabel); + Assert.True(native.IsAccessibilityElement); + Assert.Equal(count, handler.SemanticsUpdates); + }); + } + + [Fact] public async Task AncestorRoleUsesFinalMappedAutomationInclusion() { From 4b520c7d64526e2ec78034e33790529df36056ab Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Tue, 1 Dec 2026 08:41:27 +0000 Subject: [PATCH 50/62] [iOS] Refresh accessibility after exclusion mapping Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../Handlers/VisualElementRenderer.cs | 10 +++++- src/Controls/src/Core/Element/Element.iOS.cs | 4 +++ .../ContentAccessibilityTests.iOS.cs | 35 +++++++++++++++++++ .../src/Handlers/Element/ElementHandler.cs | 7 ++++ 4 files changed, 55 insertions(+), 1 deletion(-) diff --git a/src/Controls/src/Core/Compatibility/Handlers/VisualElementRenderer.cs b/src/Controls/src/Core/Compatibility/Handlers/VisualElementRenderer.cs index 3ec97d0b0786..017710298f3f 100644 --- a/src/Controls/src/Core/Compatibility/Handlers/VisualElementRenderer.cs +++ b/src/Controls/src/Core/Compatibility/Handlers/VisualElementRenderer.cs @@ -131,8 +131,16 @@ protected virtual void OnElementPropertyChanged(object sender, PropertyChangedEv ? ((IElementHandler)this).PlatformView as PlatformView : null; bool wasNonTransparent = opacityView is not null && Microsoft.Maui.Platform.SemanticExtensions.IsNonTransparent(this, opacityView); + if (e.PropertyName == AutomationProperties.ExcludedWithChildrenProperty.PropertyName) + { + Microsoft.Maui.Platform.SemanticExtensions.UpdateContentRoleMapping(_mapper, this, element, e.PropertyName); + Microsoft.Maui.Platform.SemanticExtensions.ContentChanged(this); + } + else #endif - _mapper.UpdateProperty(this, element, e.PropertyName); + { + _mapper.UpdateProperty(this, element, e.PropertyName); + } #if IOS || MACCATALYST if ((e.PropertyName == nameof(IView.Semantics) || e.PropertyName == AutomationProperties.IsInAccessibleTreeProperty.PropertyName || diff --git a/src/Controls/src/Core/Element/Element.iOS.cs b/src/Controls/src/Core/Element/Element.iOS.cs index 39b29a392299..bf7a69eaa133 100644 --- a/src/Controls/src/Core/Element/Element.iOS.cs +++ b/src/Controls/src/Core/Element/Element.iOS.cs @@ -46,6 +46,10 @@ public static void MapAutomationPropertiesExcludedWithChildren(IElementHandler h var _defaultAccessibilityElementsHidden = Control.AccessibilityElementsHidden || Control is UIControl; Control.AccessibilityElementsHidden = (bool)((bool?)view.GetValue(AutomationProperties.ExcludedWithChildrenProperty) ?? _defaultAccessibilityElementsHidden); + if (ReferenceEquals(handler.VirtualView, view) + && Microsoft.Maui.Platform.SemanticExtensions.IsMappingContentRole(handler, AutomationProperties.ExcludedWithChildrenProperty.PropertyName)) + return; + if (handler is IViewHandler viewHandler && ReferenceEquals(handler.VirtualView, view)) Microsoft.Maui.Platform.SemanticExtensions.ContentChanged(viewHandler); else diff --git a/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs b/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs index 7b0c5914f198..d68e1820af08 100644 --- a/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs +++ b/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs @@ -308,6 +308,41 @@ await InvokeOnMainThreadAsync(() => } + [Fact] + public async Task AncestorRoleUsesFinalMappedExclusion() + { + var button = new Button { Text = "Action" }; + var view = new ContentView { Content = button }; + SemanticProperties.SetDescription(view, "Actions"); + var buttonHandler = await CreateHandlerAsync(button); + var handler = await CreateHandlerAsync(view); + + await InvokeOnMainThreadAsync(() => + { + Assert.Same(buttonHandler, button.Handler); + Assert.False(handler.PlatformView.IsAccessibilityElement); + AutomationProperties.SetExcludedWithChildren(button, true); + Assert.False(buttonHandler.PlatformView.AccessibilityElementsHidden); + Assert.False(handler.PlatformView.IsAccessibilityElement); + Assert.True(handler.PlatformView.ShouldGroupAccessibilityChildren); + }); + } + + sealed class ExposesExcludedButtonHandler : ButtonHandler + { + public ExposesExcludedButtonHandler() : base(CreateMapper()) + { + } + + static PropertyMapper CreateMapper() + { + var mapper = new PropertyMapper(Mapper); + mapper.AppendToMapping(AutomationProperties.ExcludedWithChildrenProperty.PropertyName, + (handler, _) => handler.PlatformView.AccessibilityElementsHidden = false); + return mapper; + } + } + [Fact] public async Task AncestorRoleUsesFinalMappedAutomationInclusion() { diff --git a/src/Core/src/Handlers/Element/ElementHandler.cs b/src/Core/src/Handlers/Element/ElementHandler.cs index ed91668489da..f853fbe99361 100644 --- a/src/Core/src/Handlers/Element/ElementHandler.cs +++ b/src/Core/src/Handlers/Element/ElementHandler.cs @@ -160,6 +160,13 @@ public virtual void UpdateValue(string property) RefreshAncestorContentRoles(); return; } + + if (this is IViewHandler roleHandler && property == Platform.SemanticExtensions.ExcludedWithChildrenPropertyName) + { + Platform.SemanticExtensions.UpdateContentRoleMapping(_mapper, this, VirtualView, property); + Platform.SemanticExtensions.ContentChanged(roleHandler); + return; + } #endif _mapper?.UpdateProperty(this, VirtualView, property); #if __IOS__ || MACCATALYST From 8bbb17fe42eb556d66cfb60131af16c85a88a518 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Tue, 1 Dec 2026 08:41:44 +0000 Subject: [PATCH 51/62] [iOS] Refresh accessibility after Content mapping Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../ContentAccessibilityTests.iOS.cs | 37 +++++++++++++++++++ .../ContentView/ContentViewHandler.iOS.cs | 4 +- .../src/Handlers/Element/ElementHandler.cs | 14 ++++++- 3 files changed, 52 insertions(+), 3 deletions(-) diff --git a/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs b/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs index d68e1820af08..155908529869 100644 --- a/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs +++ b/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs @@ -96,6 +96,43 @@ await InvokeOnMainThreadAsync(() => }); } + [Fact] + public async Task ContentRoleUsesFinalMappedContent() + { + var view = new ContentView { Content = new Button { Text = "Initial action" } }; + SemanticProperties.SetDescription(view, "Actions"); + var handler = await CreateHandlerAsync(view); + + await InvokeOnMainThreadAsync(() => + { + Assert.True(handler.PlatformView.IsAccessibilityElement); + view.Content = new BoxView(); + view.Content = new Button { Text = "Replaced action" }; + Assert.True(handler.PlatformView.IsAccessibilityElement); + Assert.False(handler.PlatformView.ShouldGroupAccessibilityChildren); + Assert.Equal("Actions", handler.PlatformView.AccessibilityLabel); + }); + } + + sealed class DecorativeContentViewHandler : ContentViewHandler + { + public DecorativeContentViewHandler() : base(CreateMapper()) + { + } + + static PropertyMapper CreateMapper() + { + var mapper = new PropertyMapper(Mapper); + mapper.AppendToMapping(nameof(IContentView.Content), (handler, _) => + { + foreach (var subview in handler.PlatformView.Subviews) + subview.RemoveFromSuperview(); + handler.PlatformView.AddSubview(new UIView()); + }); + return mapper; + } + } + [Fact] public async Task NestedVisibilityAndChildMutationsRemapAccessibilityRole() { diff --git a/src/Core/src/Handlers/ContentView/ContentViewHandler.iOS.cs b/src/Core/src/Handlers/ContentView/ContentViewHandler.iOS.cs index 4b4a07c65353..190e1b0c6a5c 100644 --- a/src/Core/src/Handlers/ContentView/ContentViewHandler.iOS.cs +++ b/src/Core/src/Handlers/ContentView/ContentViewHandler.iOS.cs @@ -67,7 +67,9 @@ static void UpdateContent(IContentViewHandler handler) public static partial void MapContent(IContentViewHandler handler, IContentView page) { UpdateContent(handler); - SemanticExtensions.ContentChanged(handler); + if (handler is not ContentViewHandler || (!handler.IsMappingProperties() + && !SemanticExtensions.IsMappingContentRole(handler, nameof(IContentView.Content)))) + SemanticExtensions.ContentChanged(handler); } protected override void DisconnectHandler(ContentView platformView) diff --git a/src/Core/src/Handlers/Element/ElementHandler.cs b/src/Core/src/Handlers/Element/ElementHandler.cs index f853fbe99361..31cffcd86273 100644 --- a/src/Core/src/Handlers/Element/ElementHandler.cs +++ b/src/Core/src/Handlers/Element/ElementHandler.cs @@ -129,7 +129,16 @@ public virtual void SetVirtualView(IElement view) _handlerState = ElementHandlerState.Connected; #if __IOS__ || MACCATALYST - RefreshAncestorContentRoles(); + if (this is ContentViewHandler contentHandler) + { + using var refresh = Platform.SemanticExtensions.BeginContentRoleRefresh(); + Platform.SemanticExtensions.RefreshContentSemantics(contentHandler); + RefreshAncestorContentRoles(); + } + else + { + RefreshAncestorContentRoles(); + } #endif } @@ -161,7 +170,8 @@ public virtual void UpdateValue(string property) return; } - if (this is IViewHandler roleHandler && property == Platform.SemanticExtensions.ExcludedWithChildrenPropertyName) + if (this is IViewHandler roleHandler && (property == Platform.SemanticExtensions.ExcludedWithChildrenPropertyName + || (property == nameof(IContentView.Content) && this is ContentViewHandler))) { Platform.SemanticExtensions.UpdateContentRoleMapping(_mapper, this, VirtualView, property); Platform.SemanticExtensions.ContentChanged(roleHandler); From d033dded5ebee39c761536a05c28448fee891ac6 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Tue, 1 Dec 2026 08:41:57 +0000 Subject: [PATCH 52/62] [iOS] Refresh ancestor accessibility after Visibility mapping Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../ContentAccessibilityTests.iOS.cs | 39 ++++++++++++++++++- .../src/Handlers/Element/ElementHandler.cs | 7 +++- src/Core/src/Handlers/View/ViewHandler.cs | 5 ++- .../src/Platform/iOS/SemanticExtensions.cs | 2 - 4 files changed, 46 insertions(+), 7 deletions(-) diff --git a/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs b/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs index 155908529869..30f5cbd5422f 100644 --- a/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs +++ b/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs @@ -344,7 +344,6 @@ await InvokeOnMainThreadAsync(() => }); } - [Fact] public async Task AncestorRoleUsesFinalMappedExclusion() { @@ -380,6 +379,44 @@ static PropertyMapper CreateMapper() } } + [Fact] + public async Task ExplicitVisibilityRemapRefreshesAncestorFromFinalState() + { + var button = new Button { Text = "Action" }; + var view = new ContentView { Content = button }; + SemanticProperties.SetDescription(view, "Actions"); + var buttonHandler = await CreateHandlerAsync(button); + var handler = await CreateHandlerAsync(view); + + await InvokeOnMainThreadAsync(() => + { + Assert.Same(buttonHandler, button.Handler); + Assert.False(handler.PlatformView.IsAccessibilityElement); + buttonHandler.HideWhenMapped = true; + buttonHandler.UpdateValue(nameof(IView.Visibility)); + Assert.True(buttonHandler.PlatformView.Hidden); + Assert.True(handler.PlatformView.IsAccessibilityElement); + Assert.False(handler.PlatformView.ShouldGroupAccessibilityChildren); + }); + } + + sealed class VisibilityOverrideButtonHandler : ButtonHandler + { + public bool HideWhenMapped { get; set; } + + public VisibilityOverrideButtonHandler() : base(CreateMapper()) + { + } + + static PropertyMapper CreateMapper() + { + var mapper = new PropertyMapper(Mapper); + mapper.AppendToMapping(nameof(IView.Visibility), + (handler, _) => handler.PlatformView.Hidden = ((VisibilityOverrideButtonHandler)handler).HideWhenMapped); + return mapper; + } + } + [Fact] public async Task AncestorRoleUsesFinalMappedAutomationInclusion() { diff --git a/src/Core/src/Handlers/Element/ElementHandler.cs b/src/Core/src/Handlers/Element/ElementHandler.cs index 31cffcd86273..59ce419793ad 100644 --- a/src/Core/src/Handlers/Element/ElementHandler.cs +++ b/src/Core/src/Handlers/Element/ElementHandler.cs @@ -170,11 +170,14 @@ public virtual void UpdateValue(string property) return; } - if (this is IViewHandler roleHandler && (property == Platform.SemanticExtensions.ExcludedWithChildrenPropertyName + if (this is IViewHandler roleHandler && (property is nameof(IView.Visibility) or Platform.SemanticExtensions.ExcludedWithChildrenPropertyName || (property == nameof(IContentView.Content) && this is ContentViewHandler))) { Platform.SemanticExtensions.UpdateContentRoleMapping(_mapper, this, VirtualView, property); - Platform.SemanticExtensions.ContentChanged(roleHandler); + if (property == nameof(IView.Visibility)) + RefreshAncestorContentRoles(); + else + Platform.SemanticExtensions.ContentChanged(roleHandler); return; } #endif diff --git a/src/Core/src/Handlers/View/ViewHandler.cs b/src/Core/src/Handlers/View/ViewHandler.cs index d19b475a0d5a..853bc4b0d602 100644 --- a/src/Core/src/Handlers/View/ViewHandler.cs +++ b/src/Core/src/Handlers/View/ViewHandler.cs @@ -515,8 +515,9 @@ public static void MapVisibility(IViewHandler handler, IView view) ((PlatformView?)handler.PlatformView)?.UpdateVisibility(view); #if __IOS__ || MACCATALYST - if (handler.PlatformView is PlatformView platformView) - SemanticExtensions.VisibilityChanged(platformView); + if (!SemanticExtensions.IsMappingContentRole(handler, nameof(IView.Visibility)) + && handler.PlatformView is PlatformView platformView) + SemanticExtensions.RefreshAncestorContentRoles(platformView); #endif } diff --git a/src/Core/src/Platform/iOS/SemanticExtensions.cs b/src/Core/src/Platform/iOS/SemanticExtensions.cs index b9905f173c31..bd670860872b 100644 --- a/src/Core/src/Platform/iOS/SemanticExtensions.cs +++ b/src/Core/src/Platform/iOS/SemanticExtensions.cs @@ -62,8 +62,6 @@ internal static void UpdateContentRoleMapping(IPropertyMapper? mapper, IElementH internal static ContentRoleRefreshBatch? BeginContentRoleRefresh() => s_contentRoleRefreshBatch is null ? s_contentRoleRefreshBatch = new() : null; - internal static void VisibilityChanged(UIView platformView) => RefreshAncestorContentRoles(platformView); - internal sealed class ContentRoleRefreshBatch : IDisposable { HashSet? _visited; From a1c0bc04f5ef61194d4a5ce4a21886fc7977d260 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Tue, 1 Dec 2026 08:41:57 +0000 Subject: [PATCH 53/62] [iOS] Cover connected tap button-mask role transitions Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../Accessibility/ContentAccessibilityTests.iOS.cs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs b/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs index 30f5cbd5422f..0177766b3d3c 100644 --- a/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs +++ b/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs @@ -49,6 +49,14 @@ await InvokeOnMainThreadAsync(() => Assert.True((handler.PlatformView.AccessibilityTraits & UIAccessibilityTrait.Button) == 0); tap.NumberOfTapsRequired = 1; Assert.True(handler.PlatformView.IsAccessibilityElement); + tap.Buttons = ButtonsMask.Secondary; + Assert.False(handler.PlatformView.IsAccessibilityElement); + Assert.True(handler.PlatformView.ShouldGroupAccessibilityChildren); + Assert.False((handler.PlatformView.AccessibilityTraits & UIAccessibilityTrait.Button) != 0); + tap.Buttons = ButtonsMask.Primary; + Assert.True(handler.PlatformView.IsAccessibilityElement); + Assert.False(handler.PlatformView.ShouldGroupAccessibilityChildren); + Assert.True((handler.PlatformView.AccessibilityTraits & UIAccessibilityTrait.Button) != 0); border.GestureRecognizers.Remove(tap); Assert.False(handler.PlatformView.IsAccessibilityElement); From b6a88dcfc7d5ea29e6465ffe39f75abb40613a0e Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Tue, 1 Dec 2026 08:42:31 +0000 Subject: [PATCH 54/62] [iOS] Refresh ancestor roles after compatibility Visibility mapping Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../Core/Compatibility/Handlers/VisualElementRenderer.cs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Controls/src/Core/Compatibility/Handlers/VisualElementRenderer.cs b/src/Controls/src/Core/Compatibility/Handlers/VisualElementRenderer.cs index 017710298f3f..8cd0c283948d 100644 --- a/src/Controls/src/Core/Compatibility/Handlers/VisualElementRenderer.cs +++ b/src/Controls/src/Core/Compatibility/Handlers/VisualElementRenderer.cs @@ -131,10 +131,15 @@ protected virtual void OnElementPropertyChanged(object sender, PropertyChangedEv ? ((IElementHandler)this).PlatformView as PlatformView : null; bool wasNonTransparent = opacityView is not null && Microsoft.Maui.Platform.SemanticExtensions.IsNonTransparent(this, opacityView); - if (e.PropertyName == AutomationProperties.ExcludedWithChildrenProperty.PropertyName) + bool isExclusion = e.PropertyName == AutomationProperties.ExcludedWithChildrenProperty.PropertyName; + bool isVisibility = e.PropertyName == nameof(IView.Visibility); + if (isExclusion || isVisibility) { Microsoft.Maui.Platform.SemanticExtensions.UpdateContentRoleMapping(_mapper, this, element, e.PropertyName); - Microsoft.Maui.Platform.SemanticExtensions.ContentChanged(this); + if (isExclusion) + Microsoft.Maui.Platform.SemanticExtensions.ContentChanged(this); + else if (((IElementHandler)this).PlatformView is PlatformView visibleView) + Microsoft.Maui.Platform.SemanticExtensions.RefreshAncestorContentRoles(visibleView); } else #endif From f22287adff93152b15a044a4dbab4a3f1e0b22c0 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Tue, 1 Dec 2026 10:16:26 +0000 Subject: [PATCH 55/62] Avoid eager UIKit subview marshaling in accessibility scans Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../src/Platform/iOS/SemanticExtensions.cs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/Core/src/Platform/iOS/SemanticExtensions.cs b/src/Core/src/Platform/iOS/SemanticExtensions.cs index bd670860872b..bab573ce3391 100644 --- a/src/Core/src/Platform/iOS/SemanticExtensions.cs +++ b/src/Core/src/Platform/iOS/SemanticExtensions.cs @@ -26,6 +26,7 @@ public static partial class SemanticExtensions static readonly NSString s_accessibilityElementsKey = new("accessibilityElements"); static readonly Selector s_isAccessibilityElementSelector = new("isAccessibilityElement"); static readonly NSString s_isAccessibilityElementKey = new("isAccessibilityElement"); + static readonly NSString s_subviewsKey = new("subviews"); const int MaxAccessibleSubviewDepth = 32; [ThreadStatic] static ContentRoleRefreshBatch? s_contentRoleRefreshBatch; @@ -465,12 +466,28 @@ static bool HasAccessibleSubview(UIView platformView, int depth) if (GetExplicitAccessibilityElements(platformView) is { } elements) return HasAccessibleElement(elements, depth); + // The typed Subviews getter marshals every child, even when the first one qualifies. + if (platformView.ValueForKey(s_subviewsKey) is NSArray subviews) + { + var count = subviews.Count; + for (nuint i = 0; i < count; i++) + { + if (subviews.GetItem(i) is { } child && HasAccessibleBranch(child, depth)) + return true; + } + + return false; + } + foreach (var child in platformView.Subviews) { - if (IsAccessibleBranch(child) && (child.IsAccessibilityElement || HasAccessibleSubview(child, depth + 1))) + if (HasAccessibleBranch(child, depth)) return true; } + static bool HasAccessibleBranch(UIView view, int parentDepth) => + IsAccessibleBranch(view) && (view.IsAccessibilityElement || HasAccessibleSubview(view, parentDepth + 1)); + return false; } From d673c6c031d931947e7de2fcd9bb82bde2666686 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Tue, 1 Dec 2026 10:17:00 +0000 Subject: [PATCH 56/62] Refresh Border accessibility after effective Content mapping Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../ContentAccessibilityTests.iOS.cs | 36 +++++++++++++++++++ .../src/Handlers/Border/BorderHandler.iOS.cs | 5 ++- .../src/Handlers/Element/ElementHandler.cs | 4 +-- 3 files changed, 42 insertions(+), 3 deletions(-) diff --git a/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs b/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs index 0177766b3d3c..4fa4e2f164ad 100644 --- a/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs +++ b/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs @@ -141,6 +141,42 @@ static PropertyMapper CreateMapper() } } + [Fact] + public async Task BorderRoleUsesFinalMappedContent() + { + var border = new Border { Content = new BoxView() }; + SemanticProperties.SetDescription(border, "Actions"); + var handler = await CreateHandlerAsync(border); + + await InvokeOnMainThreadAsync(() => + { + Assert.True(handler.PlatformView.IsAccessibilityElement); + border.Content = new Button { Text = "Replaced action" }; + Assert.False(Assert.Single(handler.PlatformView.Subviews).IsAccessibilityElement); + Assert.True(handler.PlatformView.IsAccessibilityElement); + Assert.False(handler.PlatformView.ShouldGroupAccessibilityChildren); + }); + } + + sealed class DecorativeBorderHandler : BorderHandler + { + public DecorativeBorderHandler() : base(CreateMapper()) + { + } + + static PropertyMapper CreateMapper() + { + var mapper = new PropertyMapper(Mapper); + mapper.AppendToMapping(nameof(IBorderView.Content), (handler, _) => + { + foreach (var subview in handler.PlatformView.Subviews) + subview.RemoveFromSuperview(); + handler.PlatformView.AddSubview(new UIView()); + }); + return mapper; + } + } + [Fact] public async Task NestedVisibilityAndChildMutationsRemapAccessibilityRole() { diff --git a/src/Core/src/Handlers/Border/BorderHandler.iOS.cs b/src/Core/src/Handlers/Border/BorderHandler.iOS.cs index b1f8448bdd8d..60417fc3c6d2 100644 --- a/src/Core/src/Handlers/Border/BorderHandler.iOS.cs +++ b/src/Core/src/Handlers/Border/BorderHandler.iOS.cs @@ -69,7 +69,10 @@ static partial void UpdateContent(IBorderHandler handler) } } - SemanticExtensions.ContentChanged(handler); + // Keep direct calls working; ElementHandler handles the end of the effective mapping. + if (handler is not BorderHandler || (!handler.IsMappingProperties() + && !SemanticExtensions.IsMappingContentRole(handler, nameof(IContentView.Content)))) + SemanticExtensions.ContentChanged(handler); } } } \ No newline at end of file diff --git a/src/Core/src/Handlers/Element/ElementHandler.cs b/src/Core/src/Handlers/Element/ElementHandler.cs index 59ce419793ad..561c9763c719 100644 --- a/src/Core/src/Handlers/Element/ElementHandler.cs +++ b/src/Core/src/Handlers/Element/ElementHandler.cs @@ -129,7 +129,7 @@ public virtual void SetVirtualView(IElement view) _handlerState = ElementHandlerState.Connected; #if __IOS__ || MACCATALYST - if (this is ContentViewHandler contentHandler) + if (this is IViewHandler contentHandler && this is ContentViewHandler or BorderHandler) { using var refresh = Platform.SemanticExtensions.BeginContentRoleRefresh(); Platform.SemanticExtensions.RefreshContentSemantics(contentHandler); @@ -171,7 +171,7 @@ public virtual void UpdateValue(string property) } if (this is IViewHandler roleHandler && (property is nameof(IView.Visibility) or Platform.SemanticExtensions.ExcludedWithChildrenPropertyName - || (property == nameof(IContentView.Content) && this is ContentViewHandler))) + || (property == nameof(IContentView.Content) && this is ContentViewHandler or BorderHandler))) { Platform.SemanticExtensions.UpdateContentRoleMapping(_mapper, this, VirtualView, property); if (property == nameof(IView.Visibility)) From b2c96a266b5674dfb1390983a4013561b1bb9b1d Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Tue, 1 Dec 2026 10:17:26 +0000 Subject: [PATCH 57/62] Refresh ancestor accessibility after effective layout commands Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../ContentAccessibilityTests.iOS.cs | 49 +++++++++++++++++++ .../src/Handlers/Element/ElementHandler.cs | 10 ++++ 2 files changed, 59 insertions(+) diff --git a/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs b/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs index 4fa4e2f164ad..4596bc7092c5 100644 --- a/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs +++ b/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs @@ -2,6 +2,7 @@ using System.Threading.Tasks; using Microsoft.Maui.Controls; using Microsoft.Maui.Handlers; +using Microsoft.Maui.Platform; using UIKit; using Xunit; using static Microsoft.Maui.DeviceTests.AssertHelpers; @@ -177,6 +178,54 @@ static PropertyMapper CreateMapper() } } + [Theory] + [InlineData(false)] + [InlineData(true)] + public async Task LayoutAddRefreshesAncestorAfterEffectiveCommand(bool replaceMapping) + { + var layout = new Grid { AutomationId = replaceMapping ? "ReplaceAdd" : "AppendAdd" }; + var view = new ContentView { Content = layout }; + SemanticProperties.SetDescription(view, "Actions"); + var layoutHandler = await CreateHandlerAsync(layout); + var handler = await CreateHandlerAsync(view); + + await InvokeOnMainThreadAsync(() => + { + Assert.Same(layoutHandler, layout.Handler); + Assert.True(handler.PlatformView.IsAccessibilityElement); + var count = handler.SemanticsUpdates; + layout.Add(new Button { Text = "Action" }); + Assert.Equal(!replaceMapping, Assert.Single(layoutHandler.PlatformView.Subviews).AccessibilityElementsHidden); + Assert.Equal(!replaceMapping, handler.PlatformView.IsAccessibilityElement); + Assert.Equal(count + 1, handler.SemanticsUpdates); + }); + } + + sealed class ExcludingLayoutHandler : LayoutHandler + { + public ExcludingLayoutHandler() : base(commandMapper: CreateCommandMapper()) + { + } + + static CommandMapper CreateCommandMapper() + { + var mapper = new CommandMapper(CommandMapper); + mapper.ModifyMapping(nameof(ILayoutHandler.Add), (handler, layout, args, next) => + { + if (layout.AutomationId == "ReplaceAdd" && args is LayoutHandlerUpdate replacement) + { + handler.PlatformView.AddSubview(replacement.View.ToPlatform(handler.MauiContext!)); + return; + } + + next?.Invoke(handler, layout, args); + if (args is LayoutHandlerUpdate update && update.View.Handler?.PlatformView is UIView child) + child.AccessibilityElementsHidden = true; + }); + return mapper; + } + } + [Fact] public async Task NestedVisibilityAndChildMutationsRemapAccessibilityRole() { diff --git a/src/Core/src/Handlers/Element/ElementHandler.cs b/src/Core/src/Handlers/Element/ElementHandler.cs index 561c9763c719..0b7c2029e935 100644 --- a/src/Core/src/Handlers/Element/ElementHandler.cs +++ b/src/Core/src/Handlers/Element/ElementHandler.cs @@ -201,6 +201,16 @@ public virtual void Invoke(string command, object? args) if (VirtualView == null) return; +#if __IOS__ || MACCATALYST + if (this is LayoutHandler && command is nameof(ILayoutHandler.Add) or nameof(ILayoutHandler.Remove) + or nameof(ILayoutHandler.Insert) or nameof(ILayoutHandler.Update) or nameof(ILayoutHandler.Clear)) + { + using var refresh = Platform.SemanticExtensions.BeginContentRoleRefresh(); + _commandMapper?.Invoke(this, VirtualView, command, args); + RefreshAncestorContentRoles(); + return; + } +#endif _commandMapper?.Invoke(this, VirtualView, command, args); } From f059c555a53a8c6b1f8f2daddcad8bbb835fe059 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Tue, 1 Dec 2026 10:17:50 +0000 Subject: [PATCH 58/62] Refresh compatibility accessibility after renderer callbacks Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../Handlers/VisualElementRenderer.cs | 64 ++++++++++--------- .../ContentAccessibilityTests.iOS.cs | 53 +++++++++++++++ 2 files changed, 88 insertions(+), 29 deletions(-) diff --git a/src/Controls/src/Core/Compatibility/Handlers/VisualElementRenderer.cs b/src/Controls/src/Core/Compatibility/Handlers/VisualElementRenderer.cs index 8cd0c283948d..78e4ff6af467 100644 --- a/src/Controls/src/Core/Compatibility/Handlers/VisualElementRenderer.cs +++ b/src/Controls/src/Core/Compatibility/Handlers/VisualElementRenderer.cs @@ -13,6 +13,7 @@ using Android.Content; using PlatformView = Android.Views.View; #elif IOS +using ContentSemantics = Microsoft.Maui.Platform.SemanticExtensions; using PlatformView = UIKit.UIView; #endif @@ -123,40 +124,14 @@ protected virtual void OnElementPropertyChanged(object sender, PropertyChangedEv if (Element is TElement element && e.PropertyName != null) { #if IOS || MACCATALYST - var semanticsView = e.PropertyName == nameof(IView.Semantics) - ? ((IElementHandler)this).PlatformView as PlatformView : null; - bool wasAccessibleLeaf = semanticsView is not null - && Microsoft.Maui.Platform.SemanticExtensions.IsAccessibleLeaf(this, semanticsView); - var opacityView = e.PropertyName == nameof(IView.Opacity) - ? ((IElementHandler)this).PlatformView as PlatformView : null; - bool wasNonTransparent = opacityView is not null - && Microsoft.Maui.Platform.SemanticExtensions.IsNonTransparent(this, opacityView); - bool isExclusion = e.PropertyName == AutomationProperties.ExcludedWithChildrenProperty.PropertyName; - bool isVisibility = e.PropertyName == nameof(IView.Visibility); - if (isExclusion || isVisibility) - { - Microsoft.Maui.Platform.SemanticExtensions.UpdateContentRoleMapping(_mapper, this, element, e.PropertyName); - if (isExclusion) - Microsoft.Maui.Platform.SemanticExtensions.ContentChanged(this); - else if (((IElementHandler)this).PlatformView is PlatformView visibleView) - Microsoft.Maui.Platform.SemanticExtensions.RefreshAncestorContentRoles(visibleView); - } + if (e.PropertyName == AutomationProperties.ExcludedWithChildrenProperty.PropertyName + || e.PropertyName == nameof(IView.Visibility)) + ContentSemantics.UpdateContentRoleMapping(_mapper, this, element, e.PropertyName); else #endif { _mapper.UpdateProperty(this, element, e.PropertyName); } -#if IOS || MACCATALYST - if ((e.PropertyName == nameof(IView.Semantics) || - e.PropertyName == AutomationProperties.IsInAccessibleTreeProperty.PropertyName || - opacityView is not null) && - ((IElementHandler)this).PlatformView is PlatformView platformView && - (!wasAccessibleLeaf || !ReferenceEquals(semanticsView, platformView) || - !Microsoft.Maui.Platform.SemanticExtensions.IsAccessibleLeaf(this, platformView)) && - (opacityView is null || !ReferenceEquals(opacityView, platformView) || - wasNonTransparent != Microsoft.Maui.Platform.SemanticExtensions.IsNonTransparent(this, platformView))) - Microsoft.Maui.Platform.SemanticExtensions.RefreshAncestorContentRoles(platformView); -#endif } ElementPropertyChanged?.Invoke(sender, e); @@ -356,7 +331,38 @@ void IElementHandler.UpdateValue(string property) { if (Element is IElement element) { +#if IOS || MACCATALYST + bool isSemantics = property == nameof(IView.Semantics); + bool isOpacity = property == nameof(IView.Opacity); + bool isVisibility = property == nameof(IView.Visibility); + bool isAutomationRole = property == AutomationProperties.IsInAccessibleTreeProperty.PropertyName; + var previousView = isSemantics || isOpacity ? ((IElementHandler)this).PlatformView as PlatformView : null; + bool wasAccessibleLeaf = isSemantics && previousView is not null && ContentSemantics.IsAccessibleLeaf(this, previousView); + bool wasNonTransparent = isOpacity && previousView is not null && ContentSemantics.IsNonTransparent(this, previousView); + bool contentChanged = property == AutomationProperties.ExcludedWithChildrenProperty.PropertyName; + bool affectsRole = contentChanged || isSemantics || isOpacity || isVisibility || isAutomationRole; + using var refresh = affectsRole ? ContentSemantics.BeginContentRoleRefresh() : null; +#endif OnElementPropertyChanged(element, new PropertyChangedEventArgs(property)); +#if IOS || MACCATALYST + if (!affectsRole || !ReferenceEquals(Element, element) || ((IElementHandler)this).PlatformView is not PlatformView platformView) + return; + + // Derived renderers and event subscribers can change the native role after the mapper. + if (contentChanged) + { + ContentSemantics.RefreshContentSemantics(this); + ContentSemantics.RefreshAncestorContentRoles(platformView); + } + else if (isVisibility || isAutomationRole + || (isSemantics && (!wasAccessibleLeaf || !ReferenceEquals(previousView, platformView) + || !ContentSemantics.IsAccessibleLeaf(this, platformView))) + || (isOpacity && (!ReferenceEquals(previousView, platformView) + || wasNonTransparent != ContentSemantics.IsNonTransparent(this, platformView)))) + { + ContentSemantics.RefreshAncestorContentRoles(platformView); + } +#endif } } diff --git a/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs b/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs index 4596bc7092c5..46a3eb4b8dee 100644 --- a/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs +++ b/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs @@ -1,4 +1,5 @@ using System; +using System.ComponentModel; using System.Threading.Tasks; using Microsoft.Maui.Controls; using Microsoft.Maui.Handlers; @@ -1074,6 +1075,58 @@ static PropertyMapper CreateMapper() } } + [Theory] + [InlineData(false)] + [InlineData(true)] + public async Task AncestorRoleUsesFinalRendererCallbackState(bool useEvent) + { + var inner = new BoxView(); + SemanticProperties.SetDescription(inner, "Show"); + var outer = new ContentView { Content = inner }; + SemanticProperties.SetDescription(outer, "Actions"); + var renderer = await CreateHandlerAsync(inner); + var handler = await CreateHandlerAsync(outer); + + await InvokeOnMainThreadAsync(() => + { + var native = Assert.IsAssignableFrom(((IElementHandler)renderer).PlatformView); + Assert.True(native.IsAccessibilityElement); + Assert.False(handler.PlatformView.IsAccessibilityElement); + if (useEvent) + renderer.ElementPropertyChanged += (_, e) => + { + if (e.PropertyName == nameof(IView.Semantics)) + native.IsAccessibilityElement = false; + }; + else + renderer.ExcludeOnSemantics = true; + + SemanticProperties.SetHint(inner, "Hide"); + + Assert.False(native.IsAccessibilityElement); + Assert.True(handler.PlatformView.IsAccessibilityElement); + }); + } + + sealed class CallbackExcludingRenderer : Microsoft.Maui.Controls.Handlers.Compatibility.ViewRenderer + { + public bool ExcludeOnSemantics { get; set; } + + protected override void OnElementChanged(ElementChangedEventArgs e) + { + base.OnElementChanged(e); + if (e.NewElement is not null && Control is null) + SetNativeControl(new UILabel { Text = "Action", IsAccessibilityElement = true }); + } + + protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e) + { + base.OnElementPropertyChanged(sender, e); + if (ExcludeOnSemantics && e.PropertyName == nameof(IView.Semantics)) + Control!.IsAccessibilityElement = false; + } + } + sealed class ExcludedContentViewHandler : ContentViewHandler { public ExcludedContentViewHandler() : base(CreateMapper()) From 74b470b195e2c4498104a138fa7d6d3ad7292c44 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Tue, 1 Dec 2026 10:18:01 +0000 Subject: [PATCH 59/62] Refresh compatibility content role after content replacement Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../Handlers/VisualElementRenderer.cs | 3 ++- .../ContentAccessibilityTests.iOS.cs | 23 +++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/Controls/src/Core/Compatibility/Handlers/VisualElementRenderer.cs b/src/Controls/src/Core/Compatibility/Handlers/VisualElementRenderer.cs index 78e4ff6af467..4c2ab47145b8 100644 --- a/src/Controls/src/Core/Compatibility/Handlers/VisualElementRenderer.cs +++ b/src/Controls/src/Core/Compatibility/Handlers/VisualElementRenderer.cs @@ -339,7 +339,8 @@ void IElementHandler.UpdateValue(string property) var previousView = isSemantics || isOpacity ? ((IElementHandler)this).PlatformView as PlatformView : null; bool wasAccessibleLeaf = isSemantics && previousView is not null && ContentSemantics.IsAccessibleLeaf(this, previousView); bool wasNonTransparent = isOpacity && previousView is not null && ContentSemantics.IsNonTransparent(this, previousView); - bool contentChanged = property == AutomationProperties.ExcludedWithChildrenProperty.PropertyName; + bool contentChanged = property == AutomationProperties.ExcludedWithChildrenProperty.PropertyName + || (property == nameof(IContentView.Content) && element is IContentView); bool affectsRole = contentChanged || isSemantics || isOpacity || isVisibility || isAutomationRole; using var refresh = affectsRole ? ContentSemantics.BeginContentRoleRefresh() : null; #endif diff --git a/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs b/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs index 46a3eb4b8dee..eb553a335ef7 100644 --- a/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs +++ b/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs @@ -1127,6 +1127,29 @@ protected override void OnElementPropertyChanged(object sender, PropertyChangedE } } +#pragma warning disable CS0618 // Frame and its renderer are obsolete but supported for compatibility. + [Fact] + public async Task ReplacingCompatibilityContentRestoresParentFocus() + { + var frame = new Frame { Content = new Button { Text = "Action" } }; + var renderer = await CreateHandlerAsync(frame); + + await InvokeOnMainThreadAsync(() => + { + SemanticProperties.SetDescription(frame, "Actions"); + var native = Assert.IsAssignableFrom(((IElementHandler)renderer).PlatformView); + Assert.False(native.IsAccessibilityElement); + Assert.True(native.ShouldGroupAccessibilityChildren); + + frame.Content = new BoxView(); + + Assert.True(native.IsAccessibilityElement); + Assert.False(native.ShouldGroupAccessibilityChildren); + Assert.Equal("Actions", native.AccessibilityLabel); + }); + } +#pragma warning restore CS0618 + sealed class ExcludedContentViewHandler : ContentViewHandler { public ExcludedContentViewHandler() : base(CreateMapper()) From e938f768c35000b767b6a6ad4803f29927b1110a Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Tue, 1 Dec 2026 10:18:13 +0000 Subject: [PATCH 60/62] Cover batched BindableLayout accessibility range notifications Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../ContentAccessibilityTests.iOS.cs | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs b/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs index eb553a335ef7..c6d722411d51 100644 --- a/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs +++ b/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs @@ -1,4 +1,6 @@ using System; +using System.Collections.ObjectModel; +using System.Collections.Specialized; using System.ComponentModel; using System.Threading.Tasks; using Microsoft.Maui.Controls; @@ -302,6 +304,40 @@ await InvokeOnMainThreadAsync(() => }); } + [Fact] + public async Task BindableLayoutRangeAddRefreshesContentHostOnce() + { + var items = new RangeObservableCollection(); + var layout = new VerticalStackLayout(); + BindableLayout.SetItemTemplate(layout, new DataTemplate(() => new Button { Text = "Action" })); + BindableLayout.SetItemsSource(layout, items); + var view = new ContentView { Content = layout }; + SemanticProperties.SetDescription(view, "Actions"); + var handler = await CreateHandlerAsync(view); + + await InvokeOnMainThreadAsync(() => + { + Assert.True(handler.PlatformView.IsAccessibilityElement); + var count = handler.SemanticsUpdates; + items.AddRange(new[] { 1, 2, 3 }); + Assert.Equal(3, layout.Children.Count); + Assert.Equal(count + 1, handler.SemanticsUpdates); + Assert.False(handler.PlatformView.IsAccessibilityElement); + Assert.True(handler.PlatformView.ShouldGroupAccessibilityChildren); + }); + } + + sealed class RangeObservableCollection : ObservableCollection + { + public void AddRange(int[] values) + { + var index = Count; + foreach (var value in values) + Items.Add(value); + OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, values, index)); + } + } + [Fact] public async Task ReincludingSubtreeRestoresItsContentRole() { From ea92b541d8e0ff88bd629d4f528c149ed899d7d1 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Tue, 1 Dec 2026 10:18:26 +0000 Subject: [PATCH 61/62] Cover compatibility renderer accessible-leaf exclusion Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../ContentAccessibilityTests.iOS.cs | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs b/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs index c6d722411d51..9c50c0a7f4c2 100644 --- a/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs +++ b/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs @@ -1186,6 +1186,52 @@ await InvokeOnMainThreadAsync(() => } #pragma warning restore CS0618 + [Fact] + public async Task AncestorRoleTracksCompatibilityLeafExclusion() + { + var child = new BoxView(); + SemanticProperties.SetDescription(child, "Included"); + var view = new ContentView { Content = child }; + SemanticProperties.SetDescription(view, "Actions"); + var renderer = await CreateHandlerAsync(child); + var handler = await CreateHandlerAsync(view); + + await InvokeOnMainThreadAsync(() => + { + var native = Assert.IsAssignableFrom(((IElementHandler)renderer).PlatformView); + Assert.True(native.IsAccessibilityElement); + Assert.False(handler.PlatformView.IsAccessibilityElement); + SemanticProperties.SetDescription(child, "Excluded"); + Assert.False(native.IsAccessibilityElement); + Assert.True(handler.PlatformView.IsAccessibilityElement); + }); + } + + sealed class ConditionalLeafRenderer : Microsoft.Maui.Controls.Handlers.Compatibility.ViewRenderer + { + public ConditionalLeafRenderer() : base(CreateMapper()) + { + } + + protected override void OnElementChanged(ElementChangedEventArgs e) + { + base.OnElementChanged(e); + if (e.NewElement is not null && Control is null) + SetNativeControl(new UILabel { Text = "Action", IsAccessibilityElement = true }); + } + + static PropertyMapper CreateMapper() + { + var mapper = new PropertyMapper(VisualElementRendererMapper); + mapper.AppendToMapping(nameof(IView.Semantics), (handler, child) => + { + if (handler.PlatformView is UILabel native && SemanticProperties.GetDescription(child) == "Excluded") + native.IsAccessibilityElement = false; + }); + return mapper; + } + } + sealed class ExcludedContentViewHandler : ContentViewHandler { public ExcludedContentViewHandler() : base(CreateMapper()) From d7a9194cd1781fa874c8bfb1f3ffbe23adedd2a8 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Tue, 1 Dec 2026 11:48:01 +0000 Subject: [PATCH 62/62] Refresh iOS accessibility after effective Content mappings Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../ContentAccessibilityTests.iOS.cs | 58 +++++++++++++++++++ .../src/Handlers/Border/BorderHandler.iOS.cs | 5 +- .../ContentView/ContentViewHandler.iOS.cs | 4 +- .../src/Handlers/Element/ElementHandler.cs | 4 +- .../RefreshView/RefreshViewHandler.iOS.cs | 2 +- .../ScrollView/ScrollViewHandler.iOS.cs | 2 +- .../SwipeItemView/SwipeItemViewHandler.iOS.cs | 2 +- .../SwipeView/SwipeViewHandler.iOS.cs | 2 +- .../src/Platform/iOS/SemanticExtensions.cs | 12 ++++ 9 files changed, 78 insertions(+), 13 deletions(-) diff --git a/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs b/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs index 9c50c0a7f4c2..1f0d184ee89d 100644 --- a/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs +++ b/src/Controls/tests/DeviceTests/Elements/Accessibility/ContentAccessibilityTests.iOS.cs @@ -181,6 +181,64 @@ static PropertyMapper CreateMapper() } } + [Theory] + [InlineData(false)] + [InlineData(true)] + public async Task ScrollViewRoleUsesFinalMappedContent(bool replaceMapping) + { + var scrollView = new ScrollView + { + AutomationId = replaceMapping ? "ReplaceContent" : "AppendContent", + Content = new Button { AutomationId = "HiddenAction", Text = "Initial action" }, + }; + SemanticProperties.SetDescription(scrollView, "Actions"); + var handler = await CreateHandlerAsync(scrollView); + + await InvokeOnMainThreadAsync(() => + { + Assert.True(handler.PlatformView.GetContentView()?.AccessibilityElementsHidden); + Assert.True(handler.PlatformView.IsAccessibilityElement); + + scrollView.Content = new Button { Text = "Visible action" }; + Assert.False(handler.PlatformView.IsAccessibilityElement); + Assert.True(handler.PlatformView.ShouldGroupAccessibilityChildren); + + scrollView.Content = new Button { AutomationId = "HiddenAction", Text = "Replaced action" }; + Assert.True(handler.PlatformView.GetContentView()?.AccessibilityElementsHidden); + Assert.True(handler.PlatformView.IsAccessibilityElement); + Assert.False(handler.PlatformView.ShouldGroupAccessibilityChildren); + Assert.Equal("Actions", handler.PlatformView.AccessibilityLabel); + }); + } + + sealed class CustomizedScrollViewHandler : ScrollViewHandler + { + public CustomizedScrollViewHandler() : base(CreateMapper()) + { + } + + static PropertyMapper CreateMapper() + { + var mapper = new PropertyMapper(Mapper); + mapper.ModifyMapping(nameof(IScrollView.Content), (handler, scrollView, next) => + { + if (scrollView.AutomationId == "ReplaceContent") + { + handler.PlatformView.GetContentView()?.RemoveFromSuperview(); + handler.PlatformView.AddSubview(new UIView { Tag = MauiScrollView.ContentTag, IsAccessibilityElement = true }); + } + else + { + next?.Invoke(handler, scrollView); + } + + if (handler.PlatformView.GetContentView() is { } content) + content.AccessibilityElementsHidden = scrollView.PresentedContent?.AutomationId == "HiddenAction"; + }); + return mapper; + } + } + [Theory] [InlineData(false)] [InlineData(true)] diff --git a/src/Core/src/Handlers/Border/BorderHandler.iOS.cs b/src/Core/src/Handlers/Border/BorderHandler.iOS.cs index 60417fc3c6d2..97f4afd3edd7 100644 --- a/src/Core/src/Handlers/Border/BorderHandler.iOS.cs +++ b/src/Core/src/Handlers/Border/BorderHandler.iOS.cs @@ -69,10 +69,7 @@ static partial void UpdateContent(IBorderHandler handler) } } - // Keep direct calls working; ElementHandler handles the end of the effective mapping. - if (handler is not BorderHandler || (!handler.IsMappingProperties() - && !SemanticExtensions.IsMappingContentRole(handler, nameof(IContentView.Content)))) - SemanticExtensions.ContentChanged(handler); + SemanticExtensions.ContentMapped(handler); } } } \ No newline at end of file diff --git a/src/Core/src/Handlers/ContentView/ContentViewHandler.iOS.cs b/src/Core/src/Handlers/ContentView/ContentViewHandler.iOS.cs index 190e1b0c6a5c..1847f1e6334b 100644 --- a/src/Core/src/Handlers/ContentView/ContentViewHandler.iOS.cs +++ b/src/Core/src/Handlers/ContentView/ContentViewHandler.iOS.cs @@ -67,9 +67,7 @@ static void UpdateContent(IContentViewHandler handler) public static partial void MapContent(IContentViewHandler handler, IContentView page) { UpdateContent(handler); - if (handler is not ContentViewHandler || (!handler.IsMappingProperties() - && !SemanticExtensions.IsMappingContentRole(handler, nameof(IContentView.Content)))) - SemanticExtensions.ContentChanged(handler); + SemanticExtensions.ContentMapped(handler); } protected override void DisconnectHandler(ContentView platformView) diff --git a/src/Core/src/Handlers/Element/ElementHandler.cs b/src/Core/src/Handlers/Element/ElementHandler.cs index 0b7c2029e935..0631af4bc0e8 100644 --- a/src/Core/src/Handlers/Element/ElementHandler.cs +++ b/src/Core/src/Handlers/Element/ElementHandler.cs @@ -129,7 +129,7 @@ public virtual void SetVirtualView(IElement view) _handlerState = ElementHandlerState.Connected; #if __IOS__ || MACCATALYST - if (this is IViewHandler contentHandler && this is ContentViewHandler or BorderHandler) + if (this is IViewHandler contentHandler && Platform.SemanticExtensions.RefreshesAfterContentMapping(this)) { using var refresh = Platform.SemanticExtensions.BeginContentRoleRefresh(); Platform.SemanticExtensions.RefreshContentSemantics(contentHandler); @@ -171,7 +171,7 @@ public virtual void UpdateValue(string property) } if (this is IViewHandler roleHandler && (property is nameof(IView.Visibility) or Platform.SemanticExtensions.ExcludedWithChildrenPropertyName - || (property == nameof(IContentView.Content) && this is ContentViewHandler or BorderHandler))) + || (property == nameof(IContentView.Content) && Platform.SemanticExtensions.RefreshesAfterContentMapping(this)))) { Platform.SemanticExtensions.UpdateContentRoleMapping(_mapper, this, VirtualView, property); if (property == nameof(IView.Visibility)) diff --git a/src/Core/src/Handlers/RefreshView/RefreshViewHandler.iOS.cs b/src/Core/src/Handlers/RefreshView/RefreshViewHandler.iOS.cs index e4fafe377b7a..2a6d09c1829d 100644 --- a/src/Core/src/Handlers/RefreshView/RefreshViewHandler.iOS.cs +++ b/src/Core/src/Handlers/RefreshView/RefreshViewHandler.iOS.cs @@ -55,7 +55,7 @@ public static void MapIsRefreshing(IRefreshViewHandler handler, IRefreshView ref public static void MapContent(IRefreshViewHandler handler, IRefreshView refreshView) { UpdateContent(handler); - SemanticExtensions.ContentChanged(handler); + SemanticExtensions.ContentMapped(handler); } public static void MapRefreshColor(IRefreshViewHandler handler, IRefreshView refreshView) diff --git a/src/Core/src/Handlers/ScrollView/ScrollViewHandler.iOS.cs b/src/Core/src/Handlers/ScrollView/ScrollViewHandler.iOS.cs index 72f290e8d014..b55084cf5c2f 100644 --- a/src/Core/src/Handlers/ScrollView/ScrollViewHandler.iOS.cs +++ b/src/Core/src/Handlers/ScrollView/ScrollViewHandler.iOS.cs @@ -136,7 +136,7 @@ public static void MapContent(IScrollViewHandler handler, IScrollView scrollView // We'll use the local cross-platform layout methods defined in our handler (which wrap the ScrollView's default methods) // so we can normalize the behavior of the scrollview to match the other platforms UpdateContentView(scrollView, handler); - SemanticExtensions.ContentChanged(handler); + SemanticExtensions.ContentMapped(handler); } // We don't actually have this mapped because we don't need it, but we can't remove it because it's public diff --git a/src/Core/src/Handlers/SwipeItemView/SwipeItemViewHandler.iOS.cs b/src/Core/src/Handlers/SwipeItemView/SwipeItemViewHandler.iOS.cs index 22579f57a194..ed3cb4cbcfd2 100644 --- a/src/Core/src/Handlers/SwipeItemView/SwipeItemViewHandler.iOS.cs +++ b/src/Core/src/Handlers/SwipeItemView/SwipeItemViewHandler.iOS.cs @@ -41,7 +41,7 @@ public static void MapContent(ISwipeItemViewHandler handler, ISwipeItemView page if (handler is SwipeItemViewHandler platformHandler) { platformHandler.UpdateContent(); - SemanticExtensions.ContentChanged(handler); + SemanticExtensions.ContentMapped(handler); } } diff --git a/src/Core/src/Handlers/SwipeView/SwipeViewHandler.iOS.cs b/src/Core/src/Handlers/SwipeView/SwipeViewHandler.iOS.cs index 59e72fc08f30..2f099bd0a74f 100644 --- a/src/Core/src/Handlers/SwipeView/SwipeViewHandler.iOS.cs +++ b/src/Core/src/Handlers/SwipeView/SwipeViewHandler.iOS.cs @@ -22,7 +22,7 @@ public static void MapContent(ISwipeViewHandler handler, ISwipeView view) _ = handler.VirtualView ?? throw new InvalidOperationException($"{nameof(VirtualView)} should have been set by base class."); handler.PlatformView.UpdateContent(view, handler.MauiContext); - SemanticExtensions.ContentChanged(handler); + SemanticExtensions.ContentMapped(handler); } public static void MapIsEnabled(ISwipeViewHandler handler, ISwipeView swipeView) diff --git a/src/Core/src/Platform/iOS/SemanticExtensions.cs b/src/Core/src/Platform/iOS/SemanticExtensions.cs index bab573ce3391..f668d0ac4310 100644 --- a/src/Core/src/Platform/iOS/SemanticExtensions.cs +++ b/src/Core/src/Platform/iOS/SemanticExtensions.cs @@ -3,6 +3,7 @@ using System.Runtime.CompilerServices; using System.Text; using Foundation; +using Microsoft.Maui.Handlers; using ObjCRuntime; using UIKit; @@ -43,6 +44,17 @@ public static partial class SemanticExtensions internal static bool IsMappingContentRole(IElementHandler handler, string property) => ReferenceEquals(s_roleMappingHandler, handler) && s_roleMappingProperty == property; + internal static bool RefreshesAfterContentMapping(IElementHandler handler) => + handler is ContentViewHandler or BorderHandler or ScrollViewHandler or RefreshViewHandler or SwipeViewHandler or SwipeItemViewHandler; + + internal static void ContentMapped(IViewHandler handler) + { + // ElementHandler refreshes after app mappings; keep direct mapper calls working too. + if (!RefreshesAfterContentMapping(handler) + || (!handler.IsMappingProperties() && !IsMappingContentRole(handler, nameof(IContentView.Content)))) + ContentChanged(handler); + } + internal static void UpdateContentRoleMapping(IPropertyMapper? mapper, IElementHandler handler, IElement view, string property) { var previousHandler = s_roleMappingHandler;