Menu presentation in UIHostingController issues

Looking to see if anyone has experienced this issue, and is aware of any workarounds.

With an app migrating towards SwiftUI Views but still using UIKit for primary navigation, my app makes use of UIHostingController to push SwiftUI Views onto a UINavigationController stack in a lot of areas. With iOS 26, I notice that SwiftUI's Menu view really struggles to present when contained in a UIHostingController. An error is logged to the console on presentation, and depending on the UI, the Menu won't present inside of it's container, or will jump around the screen.

The bug, it seems is based in a private class UIReparentingView and I am curious if anyone has found a work around for this issue. The error reported is:

Adding '_UIReparentingView' as a subview of UIHostingController.view is not supported and may result in a broken view hierarchy. Add your view above UIHostingController.view in a common superview or insert it into your SwiftUI content in a UIViewRepresentable instead.

The simplest way to see this issue is to create a new storyboard based project. From the ViewController present a UIHostingController with a SwiftUI view that has a Menu and then simply tap to open the Menu. Thanks for any input!

Could you please open a bug report and include an example that reproduces the issue? Post the FB number here once you do.Bug Reporting: How and Why? has tips on creating your bug report.

Found this thread when researching an issue with the same log message in a pure SwiftUI app. There's a nasty layout/animation associated with what I'm seeing (but I'm not sure it's related to the log). A sample project to repro is attached to FB20272800

(apologies for hijacking OP's thread, but I thought it might perhaps be interesting to them that issue reproduces in iOS 26 without using a UIHostingController in our own code. A simple Menu suffices)

Thank you for the response, and sorry for the delay. I filed FB20262535 with a sample project. @j_salling I notice a lot of jumping around or the "bubble" that hosts the menu content will can laid out on the screen in a variety of ways depending on the content around it.

I did find something that may work around this issue, though it's a bit of a hack and I don't know if it would cause other issues itself. The most basic way to experience this is present a UIHostingController with ContentView and have ContentView contain something like the following:

Menu {
  Button("Sample action") {}
  Button("Other action") {}

} label: {
  HStack {
    Text("Press ME!")
    Image(systemName: "arrowtriangle.down.fill")
  }
}

This causes the error log, but since the View is simple, and contains no other elements, it does not cause jumpy animations or oddities. Feel free to decorate this view as much as you want to probably get the animation oddities (header, a scrollable list...).

What's interesting though, is the error does not appear if this menu is wrapped in a ScrollView.

ScrollView {
  ... // same menu code above
}
.fixedSize()

This prevents the error, and may, prevent view jumping. I'm going to test in my main app to see if the visual glitches are resolved, but may be a work aroundf or the time being if so.

The ScrollView does not impact the result so I wouldn't put much into that. Just silences the error.

But in case it helps anyone else, I did notice a difference while working on reproducing the issue.

A consistent issue is animation oddities rending the label of the button when it changes as a result of a Menu selection. Imagine a button that's title changes based on the option that is picked. If the text changes from a short string to a long string, the animation partially updates, then snaps back into place.

But the stranger thing is the Menu itself. This doesn't happen for a simple screen with just the menu. But with a more complicated screen, when attached to Xcode and running with the debugger attached, the Menu renders its options fine. I mean, the selectable options within the Menu are laid out inside of the menu.

But when the app is run not via Xcode, I notice the menu really misbehaves. The options may lay out to the bottom left of the button that presented the menu, but the menu's platter will start in the top right. Then after half a second or so it'll jump to the bottom left and encapsulate the menu options, though it may be sized wrong. I could reliably reproduce this while not connected to Xcode. Just in case it helps someone else as they work around this.

That was what lead me to the Scroll fix attempt, but just turned out I got the correct menu layout while connected to Xcode.

Menu presentation in UIHostingController issues
 
 
Q