Skip to content

[NET12] Show ContextFlyout context menus on iOS and Android - #40482

Open
jfversluis wants to merge 9 commits into
mainfrom
jfversluis-context-menus-all-elements
Open

jfversluis wants to merge 9 commits into
mainfrom
jfversluis-context-menus-all-elements

Conversation

@jfversluis

@jfversluis jfversluis commented Nov 20, 2026 •

Copy link
Copy Markdown
Member

Agent assessment

Self-reported assessment, not an independent review.

Assessed revision: 299baba4fef8b9445e41228b8284cbfdde2372d4

Dimension Assessment Rationale
Change confidence 8/10 ↑ Device tests pass on Android (45/45), iOS 26.5 (20/20) and Mac Catalyst (28/28); the new tests fail without their fixes.
↑ iOS (11/11) and Android (21/22, resolution guard only) ContextActions UI tests pass locally.
↓ The Mac Catalyst and Windows UI tests changed to send a real right-click but couldn't run locally; CI for this revision is pending.
↓ Windows and VoiceOver on a device are untested.

Note

Are you waiting for the changes in this PR to be merged?
It would be very helpful if you could test the resulting artifacts from this PR and let us know in a comment if this change resolves your issue. Thank you!

Target Branch

This PR is for Initial base
New features, API changes, or .NET 12 work (including .NET 12 fixes) main
.NET 11 servicing fixes net11, for review
Older servicing, release integration, infrastructure, or documentation The branch designated for that work

For .NET 11 fixes, only a maintainer retargets the approved PR to the active
inflight lane and merges it after CI validates that final base. Do not merge
individual fixes directly into net11; agents must not retarget or merge.

Description of Change

FlyoutBase.ContextFlyout now works on every view on iOS and Android, not only on Windows and Mac Catalyst. It reuses the existing MenuFlyout, MenuFlyoutItem, MenuFlyoutSubItem and MenuFlyoutSeparator API, so items, submenus, separators, Command/CommandParameter, IsEnabled and bindings all work as they do on desktop. Icons work on iOS and Mac Catalyst; Android context menus don't show icons natively, so they're left out there. This is similar to what Plugin.Maui.NativeContextMenus offers, but built in.

<Border>
    <FlyoutBase.ContextFlyout>
        <MenuFlyout>
            <MenuFlyoutItem Text="{Binding PinText}" Command="{Binding PinCommand}" />
            <MenuFlyoutSubItem Text="Share">
                <MenuFlyoutItem Text="Copy link" IconImageSource="{FontImageSource Glyph=...}" />
            </MenuFlyoutSubItem>
            <MenuFlyoutSeparator />
            <MenuFlyoutItem Text="Delete" Command="{Binding DeleteCommand}" />
        </MenuFlyout>
    </FlyoutBase.ContextFlyout>
    ...
</Border>

It only lights up for views that set a ContextFlyout. Views without one get no interaction, listener or tracking, so they behave exactly as before.

Context menu on iOS and Android

Submenus on iOS and Android

Behavior matches each platform

The goal was to behave the way a native app on each platform does, and to keep everything that works today working.

iOS (UIContextMenuInteraction)

  • Opens on long press, with the system lift preview. The preview follows the view's clip and corner radius.
  • Like native, the context menu takes over the long press, including from a LongPressGestureRecognizer. Reordering a CollectionView keeps its long press.
  • Separators are rendered as inline sections, which is how UIKit draws menu dividers. Submenus and icons work.

Android (the platform's own context menu, View.ShowContextMenu)

  • Opens on long press at the press point, as well as with a secondary (right) mouse click and by holding Enter or the D-pad center on a focused view (at its center). Like native, it opens as a dialog for TalkBack and on Android 6 and earlier.
  • Like native View.createContextMenu, the menus of the view's ancestors are added after its own.
  • Long press priority follows Android: a view that already handles a long click (for example a LongPressGestureRecognizer, or CollectionView reordering) keeps it. The menu still opens with a secondary click or the keyboard.
  • An accessibility action is added so the menu is reachable with TalkBack.
  • Submenus, separators (dividers between groups, Android 9+) and IsEnabled work. Like native Android context menus, items have no icons.
  • Long presses are detected by MAUI rather than by making views long-clickable (see Related PRs for why); only showing the menu is left to Android.

Text inputs (Entry, Editor, SearchBar) on all three platforms

Native text fields keep their own selection on long press, so these don't get a separate menu. Instead, the ContextFlyout items (theirs or an ancestor's) are added to the system's text menus, as native apps do:

  • iOS and Mac Catalyst 16+: added to the edit menu (GetEditMenu). On earlier versions the context menu opens on long press.
  • Android: added to the selection and insertion toolbars, and to the native context menu shown for a secondary click.

Flyout items in the text menus on iOS and Android

Lift preview on a rounded card on iOS and Android

Mac Catalyst fixes

The iOS path is shared with Mac Catalyst, so these are fixed there as well:

  • Context menu submenus were merged into the main menu bar. They are now standalone menus.
  • An unsupported icon source crashed while building the menu. The item is now shown without an icon.
  • The interaction and the flyout handler were not cleaned up when the view's handler was disconnected.

Opt-out

Apps that already set ContextFlyout for Windows or Mac Catalyst will now also see those menus on iOS and Android, and the items in the text menus on all three. To keep the previous behavior, set this in the project file:

<MauiEnableMobileContextFlyouts>false</MauiEnableMobileContextFlyouts>

It's a trimmable feature switch (RuntimeFeature.AreMobileContextFlyoutsEnabled), documented in docs/design/FeatureSwitches.md. With it off, iOS and Android show no context menus and the text menus only show system items. Windows is unaffected.

Public API

The only public API change is two overrides, for both net-ios and net-maccatalyst:

override Microsoft.Maui.Platform.MauiTextField.GetEditMenu(UIKit.UITextRange! textRange, UIKit.UIMenuElement![]! suggestedActions) -> UIKit.UIMenu?
override Microsoft.Maui.Platform.MauiTextView.GetEditMenu(UIKit.UITextRange! textRange, UIKit.UIMenuElement![]! suggestedActions) -> UIKit.UIMenu?

Limitations

  • Platform limitations are documented on FlyoutBase.SetContextFlyout and MenuItem.IconImageSource: no icons on Android, a dialog on Android 6 and earlier and for accessibility services, dividers only on Android 9+, and only file and font icons on iOS and Mac Catalyst.
  • To add the flyout items, an OnCreateContextMenuListener is temporarily set on the window's decor view while Android builds the context menu (Android builds it from the view up to the decor view). Android has no getter for it, so an app's own listener on the decor view would be replaced. Apps don't normally set one there, as it would make the whole window long-clickable.
  • Android hosts that aren't a MauiAppCompatActivity (embedding) can't observe touches before they're dispatched. There, a long press opens the menu only on views that already take taps (like a Button), because making other views long-clickable would stop their taps from reaching their parents. All views keep the accessibility long-click action.

Tests

  • Device tests in Controls.DeviceTests (ContextFlyoutTests*.cs): menu building, merging, priority rules, text menus, key and touch handling, CollectionView reordering, embedded hosts, and the opt-out switch.
    • Android: 45/45 on an API 36 emulator. Earlier revisions passed on a Pixel 10 (API 36) and on API 37 and API 29 emulators.
    • iOS 26.5 simulator: 20/20
    • Mac Catalyst: 28/28
    • The tests added for review feedback were checked to fail without their fixes.
  • UI tests (Issue33402, 6 tests), covering:
    • bound commands on items and submenu items;
    • parent taps and CollectionView selection still working;
    • long press on a view with a gesture following the platform;
    • an Entry keeping native text selection (Android) or cursor placement (iOS), with the system text actions, while showing the flyout items.
    • On Mac Catalyst and Windows the tests send a real secondary click. App.RightClick sends a click command that the mouse actions perform as a primary click.
  • Regression runs:
    • ContextActions UI tests: iOS 11/11. Android 21/22: the failure is ActionModeMenuShouldNotBeVisibleAfterSwitchingTab, a visual test that requires a specific emulator resolution.
    • Android CollectionView (146 passed, 0 failed) and Gesture (3/3) device tests.
    • Android DragAndDrop and Gestures UI tests: every failure passed on a rerun, except PanGestureDoesNotFlickerWhenResizingView and SwipeGesture, which fail the same way without this PR on that emulator.
  • Manually tested at runtime on the iOS simulator, a Pixel 10, an Android emulator, and Mac Catalyst with a right-click. Also tested with TalkBack (before Android switched to its native context menu; the accessibility action is covered by device tests since), and with the opt-out switch on a device.
  • Not yet tested: Windows (its code path is unchanged) and VoiceOver on a physical device. The Mac Catalyst and Windows UI tests couldn't run locally (the Mac2 driver doesn't start on this machine), so they rely on CI.

Recordings

iOS:

ios-context-menus.mp4

Android:

android-context-menus.mp4

Related PRs

#40470 (draft) also targets #33402. Both show Android's own context menu. The difference is how it's opened: #40470 sets OnCreateContextMenuListener on the view, which makes it long-clickable, and lets Android open the menu. That's much smaller, and Android then provides ancestor merging, right-click, keyboard and TalkBack itself. But long-clickable views also consume taps, and views with MAUI gesture recognizers never get the native long click, so this PR detects the long press itself and only lets Android show the menu.

Comparison
#40470 This PR
Android menu Android's own context menu Android's own context menu
Android icons No No (native context menus don't show them)
Taps on Android The view becomes long-clickable and consumes taps: a parent's tap gesture or CollectionView selection stops working on items with a menu Unchanged (UI tests)
Views with MAUI gesture recognizers (Android) No menu: the gesture touch listener stops the native long click Menu opens
LongPressGestureRecognizer, CollectionView reordering Not handled Each platform's native priority
Text inputs The menu replaces text selection Selection is kept; items are added to the system text menus
iOS submenus Menu-bar code path; titles that parse as a UIMenuIdentifier ("Share", "Edit", ...) look like they could crash Standalone context menus
iOS separators Empty sections, likely not drawn Inline sections (dividers)
Mac Catalyst fixes, opt-out switch No Yes
Tests 3 device tests Device tests on Android, iOS and Mac Catalyst; 6 UI tests; runtime verification
Size ~240 lines ~3,900 lines (~1,600 of them tests)
Android detection Android's own (right-click, keyboard, TalkBack for free) MAUI's own touch, key and accessibility handling

The #40470 iOS rows come from reading its code, not from running it.

Issues Fixed

Fixes #33402

jfversluis and others added 6 commits November 18, 2026 14:00
FlyoutBase.ContextFlyout (MenuFlyout, MenuFlyoutItem, MenuFlyoutSubItem,
MenuFlyoutSeparator) previously only worked on Windows and Mac Catalyst.
It now opens native context menus on iOS and Android too, using the
existing API. Views without a ContextFlyout are unaffected.

iOS / Mac Catalyst
- Enable the existing UIContextMenuInteraction path on iOS (long press)
  and register MenuFlyoutHandler on iOS.
- Build context sub menus as standalone UIMenus instead of going through
  the main menu bar builder (NRE on iPhone; on Catalyst, sub items titled
  like a main menu, e.g. "Edit", were merged into the menu bar).
- Draw separators as inline sections, ignore unsupported/empty icons
  instead of throwing, skip menus for disabled, input transparent or
  empty flyouts, and clean up the interaction on handler disconnect.

Android
- New ContextFlyoutManager shows an AndroidX PopupMenu built from the
  flyout each time it opens (sub menus, group dividers for separators,
  icons, disabled items, commands).
- New ContextFlyoutTouchTracker observes touches before
  MauiAppCompatActivity / modal dialogs dispatch them, so views keep
  their touch behavior (parent taps, CollectionView selection,
  scrolling). Long press and secondary click open the menu, then the
  in-flight touch is cancelled. Shift+F10 / Menu key and the TalkBack
  long-click action are supported; a native long-click listener is used
  outside MauiAppCompatActivity.

Tests: device tests for Android and iOS/Catalyst and an Appium UI test
(Issue33402).

Fixes #33402

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…lyout

A context flyout is purely additive: everything a long press did before
keeps working, and Mac Catalyst behaves as it did before iOS support.

- iOS and Android: when the element, an ancestor or the view under the
  finger already handles long press, it keeps priority over the context
  flyout: LongPressGestureRecognizer, drag (Android), text selection in
  Entry/Editor, CollectionView reordering, ListView context actions and
  tooltips (Android). The menu still opens with a secondary click or
  Shift+F10, and the TalkBack long-click action falls back to the view's
  own behavior. MAUI marks its own long-press recognizers instead of
  guessing, because UIKit adds long-press recognizers to some views
  (e.g. collection view cells).
- Android: drop the Menu key trigger, which opens the options menu.
- Mac Catalyst: disabled controls keep opening their context menu.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
- Keyboard: holding Enter / D-pad center on a focused, clickable control
  opens its context flyout (or the closest ancestor's), like a native
  long click; the key release then doesn't click. A short press still
  clicks. Shift+F10 was removed: Android doesn't use it.
- Position: menus open where the view was pressed or right-clicked
  (and at the center of the view for the keyboard), like native context
  menus, instead of at the view's corner. An invisible 1x1 anchor is
  removed once all menus, including sub menus, are closed.
- Icons: items without an icon are laid out like a native popup menu,
  without reserved icon space.

Keys are observed on the focused view through its KeyPress event, set
up from the activity's existing OnPostCreate, so no public API changes.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
iOS: let UIKit arbitrate like native apps, so the context menu wins over
long-press gestures and text selection. Only CollectionView reordering keeps
the long press, including when the menu is on the collection or around it.

Android: follow View.performLongClickInternal. The innermost view under the
finger that takes touches handles the long press: its own long-press handler
(gesture recognizer or long-click listener) comes first, then the context
menu of that view or its closest ancestor, before text selection and
tooltips. Touch targets follow ViewGroup's Z order, disabled and input
transparent gesture views and views whose menu can't show let touches
through, and pending gesture long presses under the finger are cancelled
when the menu opens. Holding a confirm key also works on views whose input
comes from tap gestures.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Text inputs keep their own text selection, like native apps, and the items
of their context flyout (or an ancestor's) join the system's text menus:
- iOS/Mac Catalyst 16+: Entry, Editor and SearchBar add the items to their
  edit menu (MauiTextField/MauiTextView override GetEditMenu); a long press
  on them selects text instead of opening the context menu.
- Android: long press keeps selecting text and the selection/insertion
  toolbars show the items; a secondary click opens the native text context
  menu with the items added. Read-only text and text-based controls that
  don't select text (pickers) keep opening the context menu.

Android also follows native context menu composition: the menus of a view's
ancestors are added after its own. Keyboard long presses are tracked per
window and match native modifier handling per API level, touches reset when
their window goes away, and context menu actions on iOS keep working when
the menu is requested again.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Lets apps turn off the new iOS/Android context menus and the text menu
integration, restoring the previous behavior.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 20, 2026 15:10
@github-actions

This comment has been minimized.

@azure-pipelines

This comment has been minimized.

@github-actions github-actions Bot added area-controls-general General issues that span multiple controls, or common base classes such as View or Element platform/android platform/ios platform/macos macOS / Mac Catalyst labels Nov 20, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Unresolved Android flyout bugs can block keyboard and long-press activation, misplace popups in RTL, and display executable items from detached flyouts after asynchronous icon loading.

5 open issues
What changed in this PR

Extends .NET MAUI’s existing FlyoutBase.ContextFlyout API to iOS and Android for #33402, while integrating with native text menus and preserving existing gesture behavior.

Changes:

  • Adds mobile context-menu presentation, Android keyboard/accessibility support, and text-menu integration.
  • Fixes shared iOS/Mac Catalyst submenu handling, unsupported icons, and handler cleanup.
  • Adds an opt-out feature switch, documentation, samples, and device/UI regression coverage.
File Description
src/​Core/​src/​RuntimeFeature.cs Defines the mobile context-flyout feature switch.
src/​Core/​src/​PublicAPI/​net-maccatalyst/​PublicAPI.Unshipped.txt Records text edit-menu overrides for Mac Catalyst.
src/​Core/​src/​PublicAPI/​net-ios/​PublicAPI.Unshipped.txt Records text edit-menu overrides for iOS.
src/​Core/​src/​Platform/​iOS/​MenuExtensions.cs Builds separator sections and handles unsupported icons.
src/​Core/​src/​Platform/​iOS/​MauiUIContextMenuInteraction.cs Coordinates menu creation, text inputs, and reordering priority.
src/​Core/​src/​Platform/​iOS/​MauiTextView.cs Adds flyout items to Editor edit menus.
src/​Core/​src/​Platform/​iOS/​MauiTextField.cs Adds flyout items to Entry edit menus.
src/​Core/​src/​Platform/​iOS/​MauiSearchBar.cs Extends SearchBar text edit menus.
src/​Core/​src/​Platform/​iOS/​ContextFlyoutEditMenu.cs Merges flyout actions into native text menus.
src/​Core/​src/​Platform/​Android/​MauiAppCompatActivity.Lifecycle.cs Starts keyboard focus observation.
src/​Core/​src/​Platform/​Android/​MauiAppCompatActivity.cs Routes touch events through context-menu tracking.
src/​Core/​src/​Platform/​Android/​ContextFlyoutTouchTracker.cs Detects long presses and secondary clicks.
src/​Core/​src/​Platform/​Android/​ContextFlyoutTextMenus.cs Extends text toolbars and secondary-click menus.
src/​Core/​src/​Platform/​Android/​ContextFlyoutManager.cs Builds and presents menus with targeting and accessibility support.
src/​Core/​src/​Platform/​Android/​ContextFlyoutKeyTracker.cs Opens menus when confirm keys are held.
src/​Core/​src/​Handlers/​View/​ViewHandler.iOS.cs Enables iOS mapping and cleans up interactions.
src/​Core/​src/​Handlers/​View/​ViewHandler.cs Registers context-flyout mapping across platforms.
src/​Core/​src/​Handlers/​View/​ViewHandler.Android.cs Attaches and detaches Android menu managers.
src/​Core/​src/​Handlers/​MenuFlyoutSubItem/​MenuFlyoutSubItemHandler.iOS.cs Builds standalone context submenus.
src/​Core/​src/​Handlers/​MenuFlyoutItem/​MenuFlyoutItemHandler.iOS.cs Safely handles icons and actions from earlier menus.
src/​Controls/​tests/​TestCases.Shared.Tests/​Tests/​Issues/​Issue33402.cs Adds menu-command and input-behavior UI tests.
src/​Controls/​tests/​TestCases.HostApp/​Issues/​Issue33402.xaml.cs Supplies commands and state for the test page.
src/​Controls/​tests/​TestCases.HostApp/​Issues/​Issue33402.xaml Defines bound menus and gesture test scenarios.
src/​Controls/​tests/​DeviceTests/​Elements/​ContextFlyout/​ContextFlyoutTests.iOS.cs Tests Apple menu construction, text integration, and priority.
src/​Controls/​tests/​DeviceTests/​Elements/​ContextFlyout/​ContextFlyoutTests.cs Adds shared fixtures and switch-testing helpers.
src/​Controls/​tests/​DeviceTests/​Elements/​ContextFlyout/​ContextFlyoutTests.Android.cs Tests Android menus, input routing, and accessibility.
src/​Controls/​src/​Core/​Platform/​ModalNavigationManager/​ModalNavigationManager.Android.cs Enables touch and keyboard tracking in modal windows.
src/​Controls/​src/​Core/​Platform/​GestureManager/​GesturePlatformManager.Android.cs Shares gesture priority and suppresses consumed key releases.
src/​Controls/​src/​Core/​Platform/​Android/​TapAndPanGestureDetector.cs Supports cancelling pending gesture long presses.
src/​Controls/​src/​Core/​Menu/​FlyoutBase.cs Documents platform behavior and opt-out configuration.
src/​Controls/​src/​Core/​Hosting/​AppHostBuilderExtensions.cs Registers the iOS MenuFlyout handler.
src/​Controls/​src/​Core/​Handlers/​Items2/​iOS/​ReorderableItemsViewController2.cs Preserves reordering priority in the current Apple handler.
src/​Controls/​src/​Core/​Handlers/​Items/​iOS/​ReorderableItemsViewController.cs Preserves reordering priority in the legacy Apple handler.
src/​Controls/​src/​Core/​Handlers/​Items/​Android/​MauiRecyclerView.cs Marks reordering as taking long-press priority.
src/​Controls/​src/​Build.Tasks/​nuget/​buildTransitive/​netstandard2.0/​Microsoft.Maui.Controls.targets Exposes the opt-out through MSBuild configuration.
src/​Controls/​samples/​Controls.Sample/​Pages/​Core/​ContextFlyoutPage.xaml Updates sample labels to mention long press.
docs/​design/​FeatureSwitches.md Documents the switch, default, and platform scope.

Review effort: Balanced

@kubaflo

This comment has been minimized.

@github-actions github-actions Bot added the s/agent-review-in-progress AI review is currently running for this PR label Nov 20, 2026
Show the flyout with View.ShowContextMenu instead of an AndroidX PopupMenu,
like native Android context menus: at the press point on Android 7.0+,
as a dialog for accessibility services and earlier versions. The items
are added by a listener on the window's decor view while the menu is
built. Native context menus don't show icons, so they're no longer shown
on Android; this and the other platform limitations are documented.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@MauiBot

MauiBot commented Nov 20, 2026

Copy link
Copy Markdown
Collaborator

PR Test Gate

@jfversluis — existing-test verification; Setup did not capture a tested commit.

Result INCONCLUSIVE Platform iOS


🧪 Gate analysis — click to expand

⚠ Inconclusive. Setup, build, or execution did not produce a conclusive result. This does not prove the fix is incorrect.

No interpretable test-group summary was produced. No additional test execution is inferred.

Setup did not capture a verified PR head; no commit is claimed as tested.

No immutable without-fix baseline was prepared.

@MauiBot MauiBot removed the s/agent-review-in-progress AI review is currently running for this PR label Nov 20, 2026
Copilot AI balanced review requested due to automatic review settings November 20, 2026 16:02

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Unresolved context-flyout regressions suppress header/footer menus when reordering is enabled, break Android keyboard access, and allow stale menu ownership to dismiss unrelated text menus.

6 open issues
2 resolved since last review

Review effort: Balanced

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

Unresolved Android flyout defects can bypass wrapper gestures, misroute app menu commands, omit newly added actions, and close unrelated text menus.

No open issues 🎉

4 previously missed issues

In code that hasn't changed since last review

Medium severity Wrapped labels miss flyout gestures and keyboard lookup

src/​Core/​src/​Handlers/​View/​ViewHandler.Android.cs:266

For a Label with a Clip or Shadow, gestures attach to the handler's WrapperView, but the flyout manager attaches to the inner PlatformView. Long-press lookup therefore misses the wrapper's long-press or drag gesture and opens the menu instead; a focused wrapper with a tap gesture also cannot find its flyout through the ancestor-only keyboard lookup. Make registration and lookup account for the effective container view, including container changes, and cover wrapped labels in the priority and keyboard tests.

Medium severity Dismissed context menus leave stale flyout ownership

src/​Core/​src/​Platform/​Android/​ContextFlyoutManager.cs:527

Ownership survives native menu dismissal, so reopening the window's reused menu on an Entry with no flyout leaves the previous flyout registered as owner: that path never runs ContextMenuListener to clear it. Removing or disconnecting the previous flyout then closes the Entry's unrelated text menu. Clear ownership when native context menus close in both activity and modal windows, and add a regression test using an Entry without a flyout.

Medium severity Empty Entry flyouts miss toolbar callbacks when later populated

src/​Core/​src/​Platform/​Android/​ContextFlyoutTextMenus.cs:45

An initially empty flyout on an Entry gets no toolbar callbacks here. If it is populated or replaced while the Entry remains focused, the manager-reuse and unchanged-focus paths skip preparation, and keyboard selection never calls Prepare. The text toolbar therefore omits the newly available flyout actions until another touch or focus change. Install the callbacks whenever a flyout is attached, including an empty one; ToolbarCallback.Update already reads the current items when the toolbar opens.

Medium severity Flyout item IDs collide with app action-mode items

src/​Core/​src/​Platform/​Android/​ContextFlyoutTextMenus.cs:154

These fixed IDs can collide with items supplied by the app's existing action-mode callback. For example, an app item with group/item ID 1000 is mistaken for the first flyout item by OnActionItemClicked, so tapping it executes the flyout command instead; the next Update also deletes the app item via RemoveGroup(1000). Allocate IDs that do not overlap existing menu entries and cover this case with a custom-callback regression test.

6 resolved since last review

Review effort: Balanced

@kubaflo

This comment has been minimized.

@kubaflo

This comment has been minimized.

@github-actions

Copy link
Copy Markdown
Contributor

Selected Tests

@kubaflo — AI-selected UI tests and device tests (GPT-6.2 Sol + MAI Code 2) for commit 299baba4.

Result NOT QUEUED Platforms Android, iOS, MacCatalyst, Windows Tests all UI, 102 device Commit 299baba4


🧪 Test selection — click to expand
Suite Result Selected Build
UI tests ❌ not queued all 77 categories —
Device tests ❌ not queued 102 of 105 units —
🧪 UI tests — the full suite on every platform

❌ Could not queue maui-pr-uitests: This PR has merge conflicts with main, so there is no test-merge commit to build. Resolve the conflicts, then comment /review run-tests again.

GPT-6.2 Sol: Run the full UI suite because default-on ContextFlyout changes base view mapping and Android window-wide input dispatch.
MAI Code 2: Runs cross-platform ContextActions UI tests for the new mobile ContextFlyout behavior and preserved desktop interactions.

🧪 Running — 77 categories on Android, iOS, MacCatalyst, Windows

The complete maui-pr-uitests suite runs on every platform (same as /azp run).

🧪 Device tests — Controls.Accessibility, Controls.Animations, Controls.Application, Controls.Behavior +98 on Android, iOS, MacCatalyst, Windows

❌ Could not queue maui-pr-devicetests: This PR has merge conflicts with main, so there is no test-merge commit to build. Resolve the conflicts, then comment /review run-tests again.

GPT-6.2 Sol: Run Controls and Core device tests for the base handler and input changes, including the shared MenuFlyout fixture on Windows.
MAI Code 2: Runs Android, iOS, and Mac Catalyst device tests for menu flyouts, view handlers, gestures, collections, and text inputs affected by mobile context menus.

🧪 Running — 102 categories on Android, iOS, MacCatalyst, Windows

Platform Categories
Android Controls.Accessibility, Controls.Animations, Controls.Application, Controls.Behavior, Controls.Border, Controls.BoxView, Controls.Button, Controls.CarouselView, Controls.CheckBox, Controls.CollectionView, Controls.Compatibility, Controls.ContentView, Controls.DatePicker, Controls.Dispatcher, Controls.Editor, Controls.Element, Controls.Entry, Controls.FlexLayout, Controls.FlyoutPage, Controls.Frame, Controls.Gesture, Controls.HybridWebView, Controls.Image, Controls.Label, Controls.Layout, Controls.Lifecycle, Controls.Map, Controls.Mapper, Controls.Memory, Controls.MenuFlyout, Controls.Modal, Controls.NavigationPage, Controls.Page, Controls.PageTransitions, Controls.Path, Controls.Picker, Controls.RadioButton, Controls.RefreshView, Controls.ScrollView, Controls.SearchBar, Controls.Shape, Controls.Shell, Controls.Slider, Controls.SwipeView, Controls.Switch, Controls.TabbedPage, Controls.TemplatedView, Controls.TextInput, Controls.Toolbar, Controls.View, Controls.VisualElement, Controls.VisualElementTree, Controls.WebView, Controls.Window, Controls.WindowOverlay, Controls.Xaml, Core.ActivityIndicator, Core.Animation, Core.Application, Core.Border, Core.BoxView, Core.Button, Core.CheckBox, Core.ContentView, Core.DatePicker, Core.Dispatcher, Core.Editor, Core.Element, Core.Entry, Core.FlowDirection, Core.FlyoutView, Core.Fonts, Core.Formatting, Core.Graphics, Core.GraphicsView, Core.Image, Core.ImageButton, Core.ImageSource, Core.IndicatorView, Core.Label, Core.Layout, Core.Lifecycle, Core.MauiContext, Core.Memory, Core.NavigationPage, Core.Page, Core.Picker, Core.ProgressBar, Core.RadioButton, Core.RefreshView, Core.ScrollView, Core.SearchBar, Core.ShapeView, Core.Slider, Core.Stepper, Core.SwipeView, Core.Switch, Core.TimePicker, Core.View, Core.WebView, Core.Window, Core.WindowOverlay
iOS Controls.Accessibility, Controls.Animations, Controls.Application, Controls.Behavior, Controls.Border, Controls.BoxView, Controls.Button, Controls.CarouselView, Controls.CheckBox, Controls.CollectionView, Controls.Compatibility, Controls.ContentView, Controls.DatePicker, Controls.Dispatcher, Controls.Editor, Controls.Element, Controls.Entry, Controls.FlexLayout, Controls.FlyoutPage, Controls.Frame, Controls.Gesture, Controls.HybridWebView, Controls.Image, Controls.Label, Controls.Layout, Controls.Lifecycle, Controls.Map, Controls.Mapper, Controls.Memory, Controls.MenuFlyout, Controls.Modal, Controls.NavigationPage, Controls.Page, Controls.PageTransitions, Controls.Path, Controls.Picker, Controls.RadioButton, Controls.RefreshView, Controls.ScrollView, Controls.SearchBar, Controls.Shape, Controls.Shell, Controls.Slider, Controls.SwipeView, Controls.Switch, Controls.TabbedPage, Controls.TemplatedView, Controls.TextInput, Controls.Toolbar, Controls.View, Controls.VisualElement, Controls.VisualElementTree, Controls.WebView, Controls.Window, Controls.WindowOverlay, Controls.Xaml, Core.ActivityIndicator, Core.Animation, Core.Application, Core.Border, Core.BoxView, Core.Button, Core.CheckBox, Core.ContentView, Core.DatePicker, Core.Dispatcher, Core.Editor, Core.Element, Core.Entry, Core.FlowDirection, Core.FlyoutView, Core.Fonts, Core.Formatting, Core.Graphics, Core.GraphicsView, Core.Image, Core.ImageButton, Core.ImageSource, Core.IndicatorView, Core.Label, Core.Layout, Core.Lifecycle, Core.MauiContext, Core.Memory, Core.NavigationPage, Core.Page, Core.Picker, Core.ProgressBar, Core.RadioButton, Core.RefreshView, Core.ScrollView, Core.SearchBar, Core.ShapeView, Core.Slider, Core.Stepper, Core.SwipeView, Core.Switch, Core.TimePicker, Core.View, Core.WebView, Core.Window, Core.WindowOverlay
MacCatalyst Controls.Accessibility, Controls.Animations, Controls.Application, Controls.Behavior, Controls.Border, Controls.BoxView, Controls.Button, Controls.CarouselView, Controls.CheckBox, Controls.CollectionView, Controls.Compatibility, Controls.ContentView, Controls.DatePicker, Controls.Dispatcher, Controls.Editor, Controls.Element, Controls.Entry, Controls.FlexLayout, Controls.FlyoutPage, Controls.Frame, Controls.Gesture, Controls.HybridWebView, Controls.Image, Controls.Label, Controls.Layout, Controls.Lifecycle, Controls.Map, Controls.Mapper, Controls.Memory, Controls.MenuFlyout, Controls.Modal, Controls.NavigationPage, Controls.Page, Controls.PageTransitions, Controls.Path, Controls.Picker, Controls.RadioButton, Controls.RefreshView, Controls.ScrollView, Controls.SearchBar, Controls.Shape, Controls.Shell, Controls.Slider, Controls.SwipeView, Controls.Switch, Controls.TabbedPage, Controls.TemplatedView, Controls.TextInput, Controls.Toolbar, Controls.View, Controls.VisualElement, Controls.VisualElementTree, Controls.WebView, Controls.Window, Controls.WindowOverlay, Controls.Xaml, Core.ActivityIndicator, Core.Animation, Core.Application, Core.Border, Core.BoxView, Core.Button, Core.CheckBox, Core.ContentView, Core.DatePicker, Core.Dispatcher, Core.Editor, Core.Element, Core.Entry, Core.FlowDirection, Core.FlyoutView, Core.Fonts, Core.Formatting, Core.Graphics, Core.GraphicsView, Core.Image, Core.ImageButton, Core.ImageSource, Core.IndicatorView, Core.Label, Core.Layout, Core.Lifecycle, Core.MauiContext, Core.Memory, Core.NavigationPage, Core.Page, Core.Picker, Core.ProgressBar, Core.RadioButton, Core.RefreshView, Core.ScrollView, Core.SearchBar, Core.ShapeView, Core.Slider, Core.Stepper, Core.SwipeView, Core.Switch, Core.TimePicker, Core.View, Core.WebView, Core.Window, Core.WindowOverlay
Windows Controls.Accessibility, Controls.Animations, Controls.Application, Controls.Behavior, Controls.Border, Controls.BoxView, Controls.Button, Controls.CarouselView, Controls.CheckBox, Controls.CollectionView, Controls.Compatibility, Controls.ContentView, Controls.DatePicker, Controls.Dispatcher, Controls.Editor, Controls.Element, Controls.Entry, Controls.FlexLayout, Controls.FlyoutPage, Controls.Frame, Controls.Gesture, Controls.HybridWebView, Controls.Image, Controls.Label, Controls.Layout, Controls.Lifecycle, Controls.Map, Controls.Mapper, Controls.Memory, Controls.MenuFlyout, Controls.Modal, Controls.NavigationPage, Controls.Page, Controls.PageTransitions, Controls.Path, Controls.Picker, Controls.RadioButton, Controls.RefreshView, Controls.ScrollView, Controls.SearchBar, Controls.Shape, Controls.Shell, Controls.Slider, Controls.SwipeView, Controls.Switch, Controls.TabbedPage, Controls.TemplatedView, Controls.TextInput, Controls.Toolbar, Controls.View, Controls.VisualElement, Controls.VisualElementTree, Controls.WebView, Controls.Window, Controls.WindowOverlay, Controls.Xaml, Core.ActivityIndicator, Core.Animation, Core.Application, Core.Border, Core.BoxView, Core.Button, Core.CheckBox, Core.ContentView, Core.DatePicker, Core.Dispatcher, Core.Editor, Core.Element, Core.Entry, Core.FlowDirection, Core.FlyoutView, Core.Fonts, Core.Formatting, Core.Graphics, Core.GraphicsView, Core.Image, Core.ImageButton, Core.ImageSource, Core.IndicatorView, Core.Label, Core.Layout, Core.Lifecycle, Core.MauiContext, Core.Memory, Core.NavigationPage, Core.Page, Core.Picker, Core.ProgressBar, Core.RadioButton, Core.RefreshView, Core.ScrollView, Core.SearchBar, Core.ShapeView, Core.Slider, Core.Stepper, Core.SwipeView, Core.Switch, Core.TimePicker, Core.View, Core.WebView, Core.Window, Core.WindowOverlay
⏭️ Skipped — what neither suite runs

Device tests — 3 categories, 0 platforms

Categories not run: Graphics, Essentials, BlazorWebView

Each skipped platform and project is listed as a maui-pr-devicetests (skipped) … status on this commit. Use /azp run maui-pr-devicetests for the full suite.

🤖 Why these tests — AI rationale (GPT-6.2 Sol + MAI Code 2)

UI tests

Each model chose independently; every test that runs was selected by at least one of them.

Platform GPT-6.2 Sol MAI Code 2
Android all categories ContextActions
iOS all categories ContextActions
MacCatalyst all categories ContextActions
Windows all categories ContextActions

GPT-6.2 Sol — Run the full UI suite because default-on ContextFlyout changes base view mapping and Android window-wide input dispatch.

  • ViewHandler maps ContextFlyout by default; Android activity and modal hooks change input dispatch.
  • Issue33402 adds ContextActions coverage on all four platforms.
  • No separate build or Material3 lane: the targets file only forwards an optional setting.

MAI Code 2 — Runs cross-platform ContextActions UI tests for the new mobile ContextFlyout behavior and preserved desktop interactions.

  • The changed shared Issue33402 tests are runnable on all four platforms and explicitly validate commands, subitems, CollectionView selection, gesture priority, and text-input menus.
  • Android production code adds long-press/menu routing, while iOS and Mac Catalyst code adds UIKit interactions and edit-menu integration.
  • The shared test also exercises the existing Windows/Mac Catalyst secondary-click paths, whose test helper behavior was changed.
  • No broader categories are needed because ContextActions directly covers the affected interactions; the opt-in, view-specific feature does not warrant a full run.

Device tests

Each model chose independently; every test that runs was selected by at least one of them.

Platform GPT-6.2 Sol MAI Code 2
Android Controls.Accessibility, Controls.Animations, Controls.Application, Controls.Behavior, Controls.Border, Controls.BoxView, Controls.Button, Controls.CarouselView, Controls.CheckBox, Controls.CollectionView, Controls.Compatibility, Controls.ContentView, Controls.DatePicker, Controls.Dispatcher, Controls.Editor, Controls.Element, Controls.Entry, Controls.FlexLayout, Controls.FlyoutPage, Controls.Frame, Controls.Gesture, Controls.HybridWebView, Controls.Image, Controls.Label, Controls.Layout, Controls.Lifecycle, Controls.Map, Controls.Mapper, Controls.Memory, Controls.MenuFlyout, Controls.Modal, Controls.NavigationPage, Controls.Page, Controls.PageTransitions, Controls.Path, Controls.Picker, Controls.RadioButton, Controls.RefreshView, Controls.ScrollView, Controls.SearchBar, Controls.Shape, Controls.Shell, Controls.Slider, Controls.SwipeView, Controls.Switch, Controls.TabbedPage, Controls.TemplatedView, Controls.TextInput, Controls.Toolbar, Controls.View, Controls.VisualElement, Controls.VisualElementTree, Controls.WebView, Controls.Window, Controls.WindowOverlay, Controls.Xaml, Core.ActivityIndicator, Core.Animation, Core.Application, Core.Border, Core.BoxView, Core.Button, Core.CheckBox, Core.ContentView, Core.DatePicker, Core.Dispatcher, Core.Editor, Core.Element, Core.Entry, Core.FlowDirection, Core.FlyoutView, Core.Fonts, Core.Formatting, Core.Graphics, Core.GraphicsView, Core.Image, Core.ImageButton, Core.ImageSource, Core.IndicatorView, Core.Label, Core.Layout, Core.Lifecycle, Core.MauiContext, Core.Memory, Core.NavigationPage, Core.Page, Core.Picker, Core.ProgressBar, Core.RadioButton, Core.RefreshView, Core.ScrollView, Core.SearchBar, Core.ShapeView, Core.Slider, Core.Stepper, Core.SwipeView, Core.Switch, Core.TimePicker, Core.View, Core.WebView, Core.Window, Core.WindowOverlay Controls.MenuFlyout, Controls.Gesture, Controls.CollectionView, Controls.CarouselView, Controls.Entry, Controls.Editor, Controls.SearchBar, Controls.TextInput, Controls.View, Core.View, Core.Entry, Core.Editor, Core.SearchBar
iOS Controls.Accessibility, Controls.Animations, Controls.Application, Controls.Behavior, Controls.Border, Controls.BoxView, Controls.Button, Controls.CarouselView, Controls.CheckBox, Controls.CollectionView, Controls.Compatibility, Controls.ContentView, Controls.DatePicker, Controls.Dispatcher, Controls.Editor, Controls.Element, Controls.Entry, Controls.FlexLayout, Controls.FlyoutPage, Controls.Frame, Controls.Gesture, Controls.HybridWebView, Controls.Image, Controls.Label, Controls.Layout, Controls.Lifecycle, Controls.Map, Controls.Mapper, Controls.Memory, Controls.MenuFlyout, Controls.Modal, Controls.NavigationPage, Controls.Page, Controls.PageTransitions, Controls.Path, Controls.Picker, Controls.RadioButton, Controls.RefreshView, Controls.ScrollView, Controls.SearchBar, Controls.Shape, Controls.Shell, Controls.Slider, Controls.SwipeView, Controls.Switch, Controls.TabbedPage, Controls.TemplatedView, Controls.TextInput, Controls.Toolbar, Controls.View, Controls.VisualElement, Controls.VisualElementTree, Controls.WebView, Controls.Window, Controls.WindowOverlay, Controls.Xaml, Core.ActivityIndicator, Core.Animation, Core.Application, Core.Border, Core.BoxView, Core.Button, Core.CheckBox, Core.ContentView, Core.DatePicker, Core.Dispatcher, Core.Editor, Core.Element, Core.Entry, Core.FlowDirection, Core.FlyoutView, Core.Fonts, Core.Formatting, Core.Graphics, Core.GraphicsView, Core.Image, Core.ImageButton, Core.ImageSource, Core.IndicatorView, Core.Label, Core.Layout, Core.Lifecycle, Core.MauiContext, Core.Memory, Core.NavigationPage, Core.Page, Core.Picker, Core.ProgressBar, Core.RadioButton, Core.RefreshView, Core.ScrollView, Core.SearchBar, Core.ShapeView, Core.Slider, Core.Stepper, Core.SwipeView, Core.Switch, Core.TimePicker, Core.View, Core.WebView, Core.Window, Core.WindowOverlay Controls.MenuFlyout, Controls.Gesture, Controls.CollectionView, Controls.CarouselView, Controls.Entry, Controls.Editor, Controls.SearchBar, Controls.TextInput, Controls.View, Core.View, Core.Entry, Core.Editor, Core.SearchBar
MacCatalyst Controls.Accessibility, Controls.Animations, Controls.Application, Controls.Behavior, Controls.Border, Controls.BoxView, Controls.Button, Controls.CarouselView, Controls.CheckBox, Controls.CollectionView, Controls.Compatibility, Controls.ContentView, Controls.DatePicker, Controls.Dispatcher, Controls.Editor, Controls.Element, Controls.Entry, Controls.FlexLayout, Controls.FlyoutPage, Controls.Frame, Controls.Gesture, Controls.HybridWebView, Controls.Image, Controls.Label, Controls.Layout, Controls.Lifecycle, Controls.Map, Controls.Mapper, Controls.Memory, Controls.MenuFlyout, Controls.Modal, Controls.NavigationPage, Controls.Page, Controls.PageTransitions, Controls.Path, Controls.Picker, Controls.RadioButton, Controls.RefreshView, Controls.ScrollView, Controls.SearchBar, Controls.Shape, Controls.Shell, Controls.Slider, Controls.SwipeView, Controls.Switch, Controls.TabbedPage, Controls.TemplatedView, Controls.TextInput, Controls.Toolbar, Controls.View, Controls.VisualElement, Controls.VisualElementTree, Controls.WebView, Controls.Window, Controls.WindowOverlay, Controls.Xaml, Core.ActivityIndicator, Core.Animation, Core.Application, Core.Border, Core.BoxView, Core.Button, Core.CheckBox, Core.ContentView, Core.DatePicker, Core.Dispatcher, Core.Editor, Core.Element, Core.Entry, Core.FlowDirection, Core.FlyoutView, Core.Fonts, Core.Formatting, Core.Graphics, Core.GraphicsView, Core.Image, Core.ImageButton, Core.ImageSource, Core.IndicatorView, Core.Label, Core.Layout, Core.Lifecycle, Core.MauiContext, Core.Memory, Core.NavigationPage, Core.Page, Core.Picker, Core.ProgressBar, Core.RadioButton, Core.RefreshView, Core.ScrollView, Core.SearchBar, Core.ShapeView, Core.Slider, Core.Stepper, Core.SwipeView, Core.Switch, Core.TimePicker, Core.View, Core.WebView, Core.Window, Core.WindowOverlay Controls.MenuFlyout, Controls.Gesture, Controls.CollectionView, Controls.CarouselView, Controls.Entry, Controls.Editor, Controls.SearchBar, Controls.TextInput, Controls.View, Core.View, Core.Entry, Core.Editor, Core.SearchBar
Windows Controls.Accessibility, Controls.Animations, Controls.Application, Controls.Behavior, Controls.Border, Controls.BoxView, Controls.Button, Controls.CarouselView, Controls.CheckBox, Controls.CollectionView, Controls.Compatibility, Controls.ContentView, Controls.DatePicker, Controls.Dispatcher, Controls.Editor, Controls.Element, Controls.Entry, Controls.FlexLayout, Controls.FlyoutPage, Controls.Frame, Controls.Gesture, Controls.HybridWebView, Controls.Image, Controls.Label, Controls.Layout, Controls.Lifecycle, Controls.Map, Controls.Mapper, Controls.Memory, Controls.MenuFlyout, Controls.Modal, Controls.NavigationPage, Controls.Page, Controls.PageTransitions, Controls.Path, Controls.Picker, Controls.RadioButton, Controls.RefreshView, Controls.ScrollView, Controls.SearchBar, Controls.Shape, Controls.Shell, Controls.Slider, Controls.SwipeView, Controls.Switch, Controls.TabbedPage, Controls.TemplatedView, Controls.TextInput, Controls.Toolbar, Controls.View, Controls.VisualElement, Controls.VisualElementTree, Controls.WebView, Controls.Window, Controls.WindowOverlay, Controls.Xaml, Core.ActivityIndicator, Core.Animation, Core.Application, Core.Border, Core.BoxView, Core.Button, Core.CheckBox, Core.ContentView, Core.DatePicker, Core.Dispatcher, Core.Editor, Core.Element, Core.Entry, Core.FlowDirection, Core.FlyoutView, Core.Fonts, Core.Formatting, Core.Graphics, Core.GraphicsView, Core.Image, Core.ImageButton, Core.ImageSource, Core.IndicatorView, Core.Label, Core.Layout, Core.Lifecycle, Core.MauiContext, Core.Memory, Core.NavigationPage, Core.Page, Core.Picker, Core.ProgressBar, Core.RadioButton, Core.RefreshView, Core.ScrollView, Core.SearchBar, Core.ShapeView, Core.Slider, Core.Stepper, Core.SwipeView, Core.Switch, Core.TimePicker, Core.View, Core.WebView, Core.Window, Core.WindowOverlay —

GPT-6.2 Sol — Run Controls and Core device tests for the base handler and input changes, including the shared MenuFlyout fixture on Windows.

  • ViewHandler and Android activity/modal dispatch affect Controls and Core broadly.
  • MenuFlyout fixture changes cover Android, iOS, Mac Catalyst, and Windows setup.
  • Graphics, Essentials, and BlazorWebView are unaffected.

MAI Code 2 — Runs Android, iOS, and Mac Catalyst device tests for menu flyouts, view handlers, gestures, collections, and text inputs affected by mobile context menus.

  • ContextFlyout device tests cover menu construction, commands, enablement, binding, accessibility, and attachment, mapping to Controls.MenuFlyout.
  • Generic ViewHandler and gesture-routing changes require Controls/Core View plus Controls.Gesture coverage on mobile platforms.
  • Android Items and iOS Items/Items2 reorder handling directly affects CollectionView and CarouselView long-press behavior.
  • Entry, Editor, and SearchBar native text-menu integrations require their Controls/TextInput and Core test units.
  • Windows is omitted because production changes are Android/iOS-specific, with only Mac Catalyst sharing the iOS implementation.

Generated by /review run-tests. A targeted run is a fast signal, not full-suite certification.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Expert Review — 9 findings

Reviewed commit 299baba.

See inline comments for details.

if (manager._usesLongClickFallback || !view.IsAttachedToWindow || !view.IsShown || !view.Enabled || view.RootView != root || !manager.CanShow())
continue;

if (!TryMapToLocal(root, view, x, y, out _, out _))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[major] Performance-Critical Path Optimization - Every ordinary ACTION_DOWN runs this lookup before native touch dispatch. It scans all registered flyouts and calls TryMapToLocal for each eligible view; that helper allocates an ancestor List and backing storage and traverses native parents before rejecting a point outside the view. A ScrollView containing 100 attached, shown rows with nonempty flyouts therefore incurs at least 100 lists/backing arrays and 100 JNI parent-chain traversals on each tap or scroll start, including offscreen rows because IsShown does not check viewport clipping. Restrict lookup to the touched branch and avoid allocating an ancestor chain per candidate. The single-target tests do not cover this scaling case.

/// Makes the selection and insertion toolbars of the text show the items of the context flyouts that apply
/// to it. The app's own toolbar callbacks keep working.
/// </summary>
internal static void Prepare(AView? view)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[major] Logic and Correctness Verification - Focus an Android Entry with an empty ContextFlyout, then populate or replace the flyout without moving focus and select text with the hardware keyboard. This guard skips installing toolbar callbacks while the flyout is empty. Attach returns early for an existing manager, UpdateListenedView returns before Prepare when focus is unchanged, and key events never prepare the text callbacks. The toolbar consequently omits the new actions until another touch or focus change. Install callbacks based on an attached flyout, leaving current item eligibility to toolbar construction. HoldingConfirmKeyFollowsFlyoutChanges tests a Button rather than this Entry transition.

}
else
{
ContextFlyoutManager.Attach(handler, platformView);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[major] Logic and Correctness Verification - For an Android Label with Clip or Shadow, GesturePlatformManager attaches gestures and records their priority on handler.ToPlatform(), which is the WrapperView, but this registers the flyout on the inner PlatformView. DefersLongPress checks the inner label rather than its wrapper, so a long-press/drag gesture on that same MAUI label loses priority and the menu opens instead. A wrapper focused for a TapGestureRecognizer also cannot find its inner flyout through the ancestor-only keyboard lookup. Account for the effective container in registration and lookup, including container changes, and cover wrapped labels in the priority and keyboard tests.

var writer = new ContextFlyoutManager.MenuWriter((menuItem, element) => items[menuItem.ItemId] = new WeakReference<IMenuElement>(element))
{
FirstGroupId = FirstGroupId,
FirstItemId = FirstGroupId,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[major] Logic and Correctness Verification - These fixed group/item IDs can collide with entries added by the app's existing action-mode callback. If that callback adds an item with group ID 1000 and item ID 1000, the first flyout leaf uses the same IDs. OnActionItemClicked then treats the app item as the flyout leaf and executes the wrong command; the next Update also deletes the app item with RemoveGroup(1000). Allocate noncolliding IDs and remove only owned entries. ToolbarCallbackStub uses group 0/item 1, so the custom-callback test cannot detect this collision.


static bool IsShowing(ContextFlyoutManager manager, IContextMenu? menu) =>
menu is not null && menu.IsAlive() && s_menuOwners.TryGetValue(menu, out var owner) &&
owner.TryGetTarget(out var current) && current == manager;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[major] Logic and Correctness Verification - Ownership is cleared only when another flyout's ContextMenuListener rebuilds the menu or Dismiss is called. After a label opens its flyout, an Entry without any flyout can open its native text context menu using the window's reused IContextMenu. That path has no ContextMenuListener, so this ownership entry still identifies the label. Removing or disconnecting the label then closes the Entry's unrelated menu. Invalidate ownership when the native menu closes or is replaced, including replacement by a view without a flyout. TextMenuIsNotOwnedByPreviousFlyout gives the Entry a flyout, so it always runs the clearing listener and misses this case.

}

_pendingNativeMenu = null;
SetMenu(scope.Menu, scope.SubMenus, null);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[moderate] Async and Threading Safety - Pending native-long-click adoption can overwrite a newer menu's owner in the same window. In an embedded host, call PerformLongClick on flyout-bearing button A, then invoke button B's accessibility long-click action before yielding. B synchronously rebuilds the reused context menu and becomes its owner, but A's pending scope is unchanged. This queued SetMenu adopts B's menu for A, so removing A closes B's menu. Dismiss also closes a pending scope's reused menu without checking whether another request replaced it. Track a window/menu generation so superseded scopes cannot adopt or close newer menus. The fallback-removal test covers teardown before adoption, not another menu replacing it.

static void OnKeyPress(object? sender, AView.KeyEventArgs e)
{
// The event is handled by default; the view must still receive the key
e.Handled = false;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[moderate] Backward Compatibility and Migration - This clears handling by earlier native KeyPress subscribers even for short presses and non-confirm keys. An existing custom Button handler can set Handled=true on Enter down/up to suppress native activation. After the button or an ancestor receives a ContextFlyout and the button is focused, UpdateListenedView appends this subscriber, which resets Handled=false on both events; a short Enter now also raises Button.Clicked. Preserve earlier subscribers' consuming behavior while observing keys. The keyboard fixtures do not include an existing consuming native subscriber.

itemView = itemView.Parent as AView;

return itemView is not null && GetChildViewHolder(itemView) is { } holder &&
_itemTouchHelperCallback.GetMovementFlags(this, holder) != 0;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[moderate] CollectionView - Android (Items/) - With CanReorderItems=true, an empty ItemsSource and an EmptyView, UpdateEmptyViewVisibility swaps in EmptyViewAdapter. Its header/footer/placeholder view types are negative, whereas SimpleItemTouchHelperCallback.GetMovementFlags excludes only the normal adapter's positive header/footer constants. This predicate consequently treats empty-state holders as reorderable and suppresses their context flyouts even though there are no source items to reorder. Require the active items adapter before deferring to item reordering. ReorderingKeepsHeaderContextFlyout uses a populated source and misses this adapter swap.

return null;
}

partial void DisconnectingHandler(PlatformView platformView)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[moderate] Regression Prevention and Test Coverage - The iOS/Mac Catalyst disconnect-cleanup fix has no discriminating regression test. InteractionIsAddedAndRemovedWithContextFlyout clears the flyout while its owning handler stays connected; the other menu tests do not assert teardown. Build a menu, disconnect the owning view's handler with ContextFlyout still set, assert that the interaction is removed and the flyout handler is disconnected, then verify reconnection restores the menu. Omitting this cleanup leaves the current assertions unchanged, so the previously retained interaction/flyout-handler lifecycle is unprotected.

kubaflo added a commit that referenced this pull request Nov 30, 2026
…#40829)

<!-- copilot-assessment:v1 -->
### Agent assessment

Self-reported assessment, not an independent review.

Assessed revision: `7ee14bce88236c49b0e3145e239c43937783dded`

| Dimension | Assessment | Rationale |
|---|---|---|
| Change confidence | 8/10 | ↑ All five affected tests passed on initial
attempts in Catalyst CI; no skips<br>↓ Shared drag-helper timing has
wider test impact |
| Diagnosis confidence | 7/10 | ↑ CI validates active-window fixture
initialization and slower native drag delivery<br>↓ Exact OS scheduling
cause is inferred, not independently reproduced locally |
| Evidence fit | 8/10 | ↑ Raw initial-run TRX confirms the three target
tests plus Clicked and removed-element drag passed<br>↓ One validating
build, not two independent runs; no local Catalyst UI execution |
<!-- /copilot-assessment -->

<!-- Please let the below note in for people that find this PR -->
> [!NOTE]
> Are you waiting for the changes in this PR to be merged?
> It would be very helpful if you could [test the resulting
artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from
this PR and let us know in a comment if this change resolves your issue.
Thank you!

<!--
Open .NET 11 fix PRs against net11 for review; target main for
next-major features.
After approval, a maintainer manually retargets the fix PR to the active
inflight
branch and merges it directly there. Do not merge individual fixes into
net11.
Bots must not retarget or merge. Candidate integration into net11 and
release/*
changes are separate, explicitly coordinated release work.
-->

### Target Branch

| This PR is for | Initial base |
| --- | --- |
| New features, API changes, or .NET 12 work (including .NET 12 fixes) |
`main` |
| .NET 11 servicing fixes | `net11`, for review |
| Older servicing, release integration, infrastructure, or documentation
| The branch designated for that work |

- [x] I selected the applicable base branch using the [contribution
guide](https://github.com/dotnet/maui/blob/main/.github/CONTRIBUTING.md#choose-your-pr-base-before-starting).

For .NET 11 fixes, only a maintainer retargets the approved PR to the
active
inflight lane and merges it after CI validates that final base. Do not
merge
individual fixes directly into `net11`; agents must not retarget or
merge.

### Description of Change

Fix repeating Catalyst UI-test failures without ignoring tests or
changing product behavior.

- **Issue20685:** initialize its menu through a real button click after
the window is active, rather than requesting a menu rebuild during
`Loaded`. UIKit's `BuildMenu` selects only active window scenes; an
early rebuild can produce no custom menu. All three tests still open the
real native menu and verify Clicked/Command/CommandParameter callbacks.
Windows initialization is unchanged.
- **Catalyst drag helper:** slow the drag from 2500 to 500 points/s and
hold at the target for 1s rather than 0.1s, allowing Catalyst to
recognize the drag and deliver target events before release. This also
covers `DragAndDropWithAnElementThatIsRemoved`.
- **Issue12060:** require an actual `DragOver` before reporting success,
so a cancelled drag outside the target cannot falsely pass the
accepted-operation regression test.

#### Evidence

[main build
1704474](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1704474),
logs 5701 and 3989:

- Both menu command tests fail on original/retry in `OpenMenuAndTapItem`
line 25, waiting for **MenuItems**, before tapping the menu. Failure
screenshots and accessibility page sources show the test page loaded and
the stock menu bar, but **no MenuItems**. This is not an unexposed
result label or a failed command callback.
- `AcceptedOperationNoneDisablesDropOperation` fails on original/retry
at line 24 waiting for **Success**. Screenshots and page sources show
both boxes and Result=Running. The Mac2 log sends `macos:
clickAndDragAndHold` with duration=1, velocity=2500 and
holdDuration=0.1, returns success, then repeatedly finds no Success.
Gesture delivery, not element discovery, is the suspected failure.
- `DragAndDropWithAnElementThatIsRemoved` times out at line 24 waiting
for **DropResult** on the initial run; it passes the in-job retry.

This does not establish a recent product regression: the tests
previously passed and the provided PR build sometimes recovered on
retry. The changes address fixture initialization and gesture timing;
The passing CI run below supports the hypotheses, but does not
independently establish the exact OS scheduling cause.

#### Duplicate search

Searched open and closed/merged PRs across all bases for Issue20685,
Issue12060, the target test names, MenuFlyoutItem, menu rebuild, Mac2
drag, and clickAndDragAndHold. No equivalent open fix found. #40190
(candidate/11.0.1xx-sr2, now merged) addresses runtime Text changes, not
initial active-window menu construction; #39912 addresses screenshot
geometry, not drag timing/menu initialization. Context-menu enhancements
#40439/#40482 do not cover these menu-bar tests.

#### Validation

- `git diff --check` — passed.
- `dotnet format Microsoft.Maui.sln --no-restore --include
src/Controls/tests/TestCases.HostApp/Issues/Issue20685.cs
src/Controls/tests/TestCases.HostApp/Issues/Issue12060.cs
src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue20685.cs
src/TestUtils/src/UITest.Appium/Actions/AppiumCatalystTouchActions.cs
--exclude Templates/src --exclude-diagnostics CA1822` — attempted;
project references were not loaded (new checkout has no restored
assets). Not claimed as a successful compiler/analyzer validation.
- No local Catalyst Appium/XCTest UI automation was run. PR CI was
requested with `/azp run maui-pr-uitests`. Initial build 1704524
canceled immediately without running tests; a second comment started
validating build 1704526.


#### Validating Catalyst CI — build 1704526

[Build
1704526](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1704526)
compiled the CoreCLR sample successfully. All three relevant Catalyst
jobs finished **succeeded**. Downloaded their published artifact TRX
files, including the **initial-run raw TRX**, rather than inferring
execution from a green job badge:

| Test | Initial outcome | Duration |
|---|---|---|
| MenuFlyoutItem_CommandWorks | Passed | 4.54s |
| MenuFlyoutItem_CommandWithParameterWorks | Passed | 4.04s |
| MenuFlyoutItem_ClickedEventWorks (Shell1) | Passed | 4.29s |
| AcceptedOperationNoneDisablesDropOperation | Passed | 4.12s |
| DragAndDropWithAnElementThatIsRemoved | Passed | 5.16s |

Evidence artifacts: `drop-maccatalyst_ui_tests_coreclr-Shell2-1`,
`drop-maccatalyst_ui_tests_coreclr-Shell1-1`, and
`drop-maccatalyst_ui_tests_coreclr-Job11-1` →
`test-results/n-*/raw/*.trx`. No target test required an in-job retry.
Assessed/tested head remains `7ee14bce88236c49b0e3145e239c43937783dded`.

**Evidence limit:** this is one validating CI build, not two independent
builds, and is not a claim that the entire cross-platform pipeline is
green. No local Catalyst UI automation was run.

### Issues Fixed

<!-- Please make sure that there is a bug logged for the issue being
fixed. The bug should describe the problem and how to reproduce it. -->

No new issue is closed. Stabilizes existing regression coverage for
#20685, #12060 and #28416.

### Let AI finish this PR

- [ ] **Let the MAUI agent address review feedback and fix remaining
issues on this PR.** Maintainers still decide whether it is merged. For
PRs from forks, keep "Allow edits by maintainers" on so the agent can
push to your branch; otherwise it opens a follow-up PR that keeps your
commits.

<!--
Verify the target branch follows the release workflow in
docs/ReleaseBranchWorkflow.md.
Infrastructure and documentation changes should target the branch where
they apply.
-->

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@kubaflo

This comment has been minimized.

@github-actions github-actions Bot added the s/autopilot-running MAUI Autopilot loop is running; remove this label to stop it label Nov 30, 2026
@github-actions

This comment has been minimized.

@github-actions github-actions Bot added the s/autopilot-fixing MAUI Autopilot: fixing review findings or failing tests (GPT-6.2 Sol vs MAI Code 2) label Nov 30, 2026
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

# Conflicts:
#	src/Controls/src/Core/Hosting/AppHostBuilderExtensions.cs
#	src/Controls/src/Core/Platform/GestureManager/GesturePlatformManager.Android.cs
#	src/Core/src/PublicAPI/net-ios/PublicAPI.Unshipped.txt
#	src/Core/src/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txt
#	src/Core/src/RuntimeFeature.cs
Copilot AI balanced review requested due to automatic review settings November 30, 2026 22:09
@github-actions github-actions Bot added s/autopilot-reviewing MAUI Autopilot: MAUI expert review in progress and removed s/autopilot-fixing MAUI Autopilot: fixing review findings or failing tests (GPT-6.2 Sol vs MAI Code 2) labels Nov 30, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Active issues leave iOS context-menu image updates throwing, Android wrapped controls bypassing long-press gesture priority, and key tracking replacing native listeners and breaking keyboard behavior.

3 open issues

Review effort: Balanced

if (VirtualView.IsInContextFlyout())
{
UIImage? contextUiImage = VirtualView.Source.GetPlatformMenuImage(MauiContext!);
UIImage? contextUiImage = VirtualView.Source.GetPlatformContextMenuImage(MauiContext!);
if (!ContextFlyoutManager.HasFlyoutFor(focused))
return;

focused.KeyPress += OnKeyPress;
return true;
}

return HasLongPressHandler(target, Get(target));

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Expert Review — 14 findings

Reviewed commit 9e3d3fa.

See inline comments for details.

if (VirtualView.IsInContextFlyout())
{
UIImage? contextUiImage = VirtualView.Source.GetPlatformMenuImage(MauiContext!);
UIImage? contextUiImage = VirtualView.Source.GetPlatformContextMenuImage(MauiContext!);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[critical] Logic and Correctness Verification - Opening an iOS context flyout containing a UriImageSource or StreamImageSource still throws InvalidOperationException. This helper ignores the icon during creation, but ElementHandler.SetVirtualView subsequently runs the Source mapper: MapSource -> UpdateImageSource -> GetPlatformMenuImage, which throws for the same source. The Source mapping from #40072 is present in the pinned head, so the creation-only fallback also fails for text edit menus and subsequent icon updates on iOS/Mac Catalyst. Apply the context-menu image policy in the mapper too. UnsupportedIconSourceIsIgnored already supplies the triggering input.

if (manager._usesLongClickFallback || !view.IsAttachedToWindow || !view.IsShown || !view.Enabled || view.RootView != root || !manager.CanShow())
continue;

if (!TryMapToLocal(root, view, x, y, out _, out _))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[major] Performance-Critical Path Optimization - Every ordinary ACTION_DOWN scans all registered flyouts before native touch dispatch. For each eligible view, TryMapToLocal allocates an ancestor List and backing storage and traverses native parents before rejecting an out-of-bounds point. A ScrollView containing 100 attached, shown rows with nonempty flyouts therefore adds at least 100 lists/backing arrays and 100 JNI parent-chain traversals to every tap or scroll start, even without opening a menu; IsShown does not exclude offscreen rows clipped by the viewport. Restrict lookup to the touched branch and avoid an allocated ancestor chain per candidate. The touch tests do not exercise this scaling case.

}
else
{
ContextFlyoutManager.Attach(handler, platformView);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[major] Logic and Correctness Verification - For an Android Label with Clip or Shadow, gestures attach to handler.ToPlatform(), the WrapperView, but this registers the flyout on the inner PlatformView. DefersLongPress checks the inner label's gesture state instead of its wrapper's, so the same label's long-press/drag recognizer loses priority and the menu opens instead. A wrapper focused for a TapGestureRecognizer also cannot find its inner flyout through the ancestor-only keyboard lookup. Account for the effective container in registration and lookup, including container changes. The priority and keyboard fixtures use unwrapped labels.

itemView = itemView.Parent as AView;

return itemView is not null && GetChildViewHolder(itemView) is { } holder &&
_itemTouchHelperCallback.GetMovementFlags(this, holder) != 0;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[major] CollectionView - Android (Items/) - With CanReorderItems=true, SelectionMode=None, plain non-interactive rows, and a flyout on the CollectionView, FindTouchTargetAt skips the row and falls back to the RecyclerView itself. CanStartReorderAt then walks outside the recycler and returns false, so the menu timer opens first and cancels reordering. Resolve the holder from the press location, not only a touch-consuming descendant. The opposite error occurs with EmptyViewAdapter: its negative header/footer/placeholder types receive nonzero flags because GetMovementFlags excludes only the normal adapter's header/footer constants, suppressing empty-state flyouts despite there being no source item to reorder. Check the active adapter too. The real-collection fixture uses populated rows with item-level flyouts and misses both cases.


var writer = new ContextFlyoutManager.MenuWriter((menuItem, element) => items[menuItem.ItemId] = new WeakReference<IMenuElement>(element))
{
FirstGroupId = FirstGroupId,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[major] Logic and Correctness Verification - The app's existing action-mode callback can add an item with group ID 1000 and item ID 1000. These fixed starting IDs give the first flyout leaf the same identifiers: OnActionItemClicked mistakes the app item for the flyout leaf and executes the wrong command, and the next Update deletes the app item through RemoveGroup(1000). Allocate identifiers that do not collide with existing entries and remove only owned items. ToolbarCallbackStub uses group 0/item 1, so the custom-callback test cannot detect this collision.

}

_pendingNativeMenu = null;
SetMenu(scope.Menu, scope.SubMenus, null);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[moderate] Async and Threading Safety - In an embedded Android host, call PerformLongClick on flyout-bearing button A, then invoke button B's accessibility long-click action before yielding. B rebuilds the window's reused menu and becomes its owner, but A's pending scope is unchanged. This queued SetMenu then assigns B's menu to A, so removing A closes B's menu. Dismiss also closes a pending scope's menu without checking whether another request replaced it. Track a menu/request generation so superseded scopes cannot adopt or close newer menus. The fallback-removal fixture covers teardown before adoption, not replacement by another menu.

if (!ShowNativeContextMenuCore(view, position, CollectFlyouts(view), out var menu, out var subMenus))
return false;

SetMenu(menu, subMenus, position);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[moderate] Async and Threading Safety - A synchronous ContextMenuCreated subscriber can clear the target's ContextFlyout while Show is constructing the menu. Detach calls Dismiss before this request has populated either _menu or _pendingNativeMenu, so nothing is closed. The root listener still holds the collected flyout and adds its items, and this SetMenu adopts the result after teardown, leaving the removed flyout's menu open. Track the synchronous request through teardown and revalidate attachment before adopting its result. The removal regression test exercises posted native-long-click adoption, not removal from a menu-construction callback.

return null;
}

partial void DisconnectingHandler(PlatformView platformView)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[moderate] Regression Prevention and Test Coverage - The iOS/Mac Catalyst disconnect-cleanup fix has no discriminating regression test. InteractionIsAddedAndRemovedWithContextFlyout clears the flyout while its owning handler stays connected; no added test disconnects that handler with ContextFlyout still set and asserts teardown. Omitting this cleanup therefore leaves the current assertions unchanged. Build a menu, disconnect the owning view handler, assert that the interaction is removed and the flyout handler is disconnected, then verify reconnection restores the menu.

Assert.Equal(1, copyClicks);

// Disabled items do nothing
Assert.True(callback.OnActionItemClicked(null, FindItem(menu, "Disabled")));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[moderate] Regression Prevention and Test Coverage - This disabled-action assertion cannot detect activation of the disabled item: copyClicks observes only Copy, while Disabled has neither a Clicked subscriber nor a command. Removing ToolbarCallback.OnActionItemClicked's IsEnabled guard still satisfies this assertion even though MenuItem.Activate raises Clicked for disabled items. Observe the disabled item's Clicked event directly, including an item disabled after the toolbar was built, to discriminate the current-state rejection path.

{

#if WINDOWS || MACCATALYST
#if WINDOWS || IOS || MACCATALYST

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[moderate] Backward Compatibility and Migration - This unconditional iOS default changes custom-handler resolution even with MauiEnableMobileContextFlyouts=false. In an app using UseMauiApp, TryAddHandler(typeof(MenuFlyout), typeof(CustomFlyoutHandler)) previously installed the custom handler on iOS; HasEnabledElementHandlerDefault now sees this attribute and skips that registration, selecting MenuFlyoutHandler instead. Preserve the previous resolution when disabled, or document migration to AddHandler in HandlerResolution.md's Behavior changes section; the opt-out guidance does not explain this difference.

[moderate] Trimming and AOT Compatibility - The PublicConstructors-annotated attribute also roots MenuFlyoutHandler independently of the disabled mapping branch in full-trim/NativeAOT apps that construct MenuFlyout in shared XAML. Use the existing conditional nested-attribute pattern to return null on iOS when the feature is disabled, preserving Windows/Mac Catalyst defaults. The device fixtures explicitly register MenuFlyoutHandler and bypass this attribute.

@github-actions github-actions Bot added s/autopilot-fixing MAUI Autopilot: fixing review findings or failing tests (GPT-6.2 Sol vs MAI Code 2) and removed s/autopilot-reviewing MAUI Autopilot: MAUI expert review in progress s/autopilot-running MAUI Autopilot loop is running; remove this label to stop it s/autopilot-fixing MAUI Autopilot: fixing review findings or failing tests (GPT-6.2 Sol vs MAI Code 2) labels Nov 30, 2026
@github-actions

Copy link
Copy Markdown
Contributor

MAUI Autopilot — Stopped

@kubaflo ❌ The last fix round found nothing more it could fix. Decide how to continue, or comment /review autopilot to run it again. Run.

@github-actions github-actions Bot added the s/autopilot-needs-maintainer-decision MAUI Autopilot stopped: a maintainer needs to decide how to continue label Nov 30, 2026
kubaflo added a commit that referenced this pull request Dec 1, 2026
<!-- Please let the below note in for people that find this PR -->
> [!NOTE]
> Are you waiting for the changes in this PR to be merged?
> It would be very helpful if you could [test the resulting
artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from
this PR and let us know in a comment if this change resolves your issue.
Thank you!

<!--
Open .NET 11 fix PRs against net11 for review; target main for
next-major features.
After approval, a maintainer manually retargets the fix PR to the active
inflight
branch and merges it directly there. Do not merge individual fixes into
net11.
Bots must not retarget or merge. Candidate integration into net11 and
release/*
changes are separate, explicitly coordinated release work.
-->

### Target Branch

| This PR is for | Initial base |
| --- | --- |
| New features, API changes, or .NET 12 work (including .NET 12 fixes) |
`main` |
| .NET 11 servicing fixes | `net11`, for review |
| Older servicing, release integration, infrastructure, or documentation
| The branch designated for that work |

- [x] I selected the applicable base branch using the [contribution
guide](https://github.com/dotnet/maui/blob/main/.github/CONTRIBUTING.md#choose-your-pr-base-before-starting).

For .NET 11 fixes, only a maintainer retargets the approved PR to the
active
inflight lane and merges it after CI validates that final base. Do not
merge
individual fixes directly into `net11`; agents must not retarget or
merge.

### Description of Change

Proposes an opt-in cross-platform `Picker.PresentationMode` API with
`PickerPresentationMode.Default` and `Menu`. `Default` preserves the
existing presentation; the default interface member also preserves
existing custom `IPicker` implementations.

```xaml
<Picker PresentationMode="Menu" ItemsSource="{Binding Choices}" />
```

| Platform | Menu presentation |
| --- | --- |
| iOS / Mac Catalyst | Native UIButton menu over the existing styled
picker field |
| Android | Anchored AppCompat ListPopupWindow, shared by classic and
Material picker handlers |
| Windows | Existing native ComboBox dropdown |

Synchronizes selection, open/focus state, item changes, enabled state
and Apple accessibility. Changing mode dismisses the active presenter
without changing selection. Menu contents use system styling; the closed
field keeps its existing text/title/font/color mappings. Includes
bindable validation, API entries for every platform partition, unit
coverage and platform device coverage. No Sandbox changes.

**Apple limitation:** Native menu activation via `IsOpen`/`Focus`
requires iOS or Mac Catalyst 17.4+. Earlier supported versions can open
the menu through user interaction; unsupported programmatic opening logs
a warning and resets `IsOpen`. This is documented on the API. Native
presentation completion is observed before reporting the menu open, so
immediate dismissal works correctly.

Designed independently before searching other proposals. No open PR
implementing this Picker API was found; #40439 and #40482 concern
general context menus rather than this Picker selection presentation.

**Local validation** (repository-pinned .NET 12 SDK):

- `.dotnet/dotnet
artifacts/bin/Controls.Core.UnitTests/Debug/net12.0/Microsoft.Maui.Controls.Core.UnitTests.dll
--filter-class Microsoft.Maui.Controls.Core.UnitTests.PickerTests` —
passed, 67 tests.
- `.dotnet/dotnet build src/Core/src/Core.csproj -f net12.0-android37.0
--no-restore -p:PublicApiType=Validate -m:1 -v:q` — passed, zero
warnings/errors.
- `.dotnet/dotnet build src/Core/src/Core.csproj -f net12.0-ios27.1
--no-restore -p:PublicApiType=Validate -m:1 -v:q` — passed, zero
warnings/errors.
- `PublicApiType=Validate DOTNET_ROOT="$PWD/.dotnet"
DOTNET_ROLL_FORWARD=Major .dotnet/dotnet tool run pwsh -- -NoProfile
-File .github/skills/run-device-tests/scripts/Run-DeviceTests.ps1
-Project Core -Platform maccatalyst -IncludeClasses
Microsoft.Maui.DeviceTests.PickerHandlerTests -IncludeMethods
MenuPresentationTracksItemsSelectionAndAccessibility,MenuPresentationOpensAndDismissesWithoutChangingSelection
-Configuration Debug -SkipXcodeVersionCheck -OutputDirectory
artifacts/log/picker-menu -Timeout 00:15:00` — passed, 2 tests, genuine
native TRX verified. Used installed Xcode 27.2 with a workload expecting
27.1; the version-check override is explicit.
- Scoped `dotnet format whitespace` and `git diff --check` — passed.

Android device execution, iOS simulator execution and Windows
build/device execution were not run locally; platform CI remains
required. An additional Android device-test BuildOnly attempt and an
isolated single-node compile both stalled without compiler output and
were stopped; they are not passing validation evidence. The Android
framework build above did complete successfully.

- Re-run on final head `8f50764074` (Mac Catalyst device tests above,
same command): passed 2/2 per native TRX; Android `Core.csproj` build at
head: passed, 0 warnings/errors.

**Initial CI:** [Pester
scripts](https://github.com/dotnet/maui/actions/runs/46619448948)
reports 18 failures. All 18 failing identities match the [latest
completed main
baseline](https://github.com/dotnet/maui/actions/runs/46459374473)
(2,476 passed / 18 failed in both runs); they concern unchanged
release/automation scripts. Native Azure DevOps results are not yet
available. Full CI is not claimed green. The optional `ci-analysis`
skill/script was unavailable in this session; the GitHub workflow logs
were inspected directly.

### Issues Fixed

<!-- Please make sure that there is a bug logged for the issue being
fixed. The bug should describe the problem and how to reproduce it. -->

Fixes #23999

### Let AI finish this PR

- [ ] **Let the MAUI agent address review feedback and fix remaining
issues on this PR.** Maintainers still decide whether it is merged. For
PRs from forks, keep "Allow edits by maintainers" on so the agent can
push to your branch; otherwise it opens a follow-up PR that keeps your
commits.

<!--
Verify the target branch follows the release workflow in
docs/ReleaseBranchWorkflow.md.
Infrastructure and documentation changes should target the branch
designated for that work.
-->

---------

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Jakub Florkowski <kubaflo123@gmail.com>

This branch was previously deployed

1 inactive (outdated) deployment
copilot-pat-pool — b231e891 Deployed Nov 20, 2026 by jfversluis via conclusion #3176
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-controls-general General issues that span multiple controls, or common base classes such as View or Element platform/android platform/ios platform/macos macOS / Mac Catalyst s/autopilot-needs-maintainer-decision MAUI Autopilot stopped: a maintainer needs to decide how to continue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Show ContextMenu on long press on visual element in mobile platform

4 participants