-
Notifications
You must be signed in to change notification settings - Fork 21
Open
Description
Description
When using NXNavigationExtension with UIHostingController (SwiftUI views embedded in UIKit navigation), the console shows this warning:
[SwiftUI] Attempting to add elements to UIHostingController's view is not supported...
This happens because nx_setupNavigationBar adds nx_navigationBar directly to self.view, but for UIHostingController, self.view is a private _UIHostingView which Apple explicitly warns against modifying.
Environment
- iOS 15+ / iOS 17+
- Xcode 15+
- NXNavigationExtension 4.2.6
- Using
UIHostingControllersubclass pushed ontoUINavigationController
Steps to Reproduce
- Create a custom
UIHostingControllersubclass - Push it onto a
UINavigationControllerthat usesNXNavigationExtension - Observe the warning in console
class MyHostingVC<Content: View>: UIHostingController<Content> {
// ...
}
// Push to navigation stack
let vc = MyHostingVC(rootView: MySwiftUIView())
navigationController?.pushViewController(vc, animated: true)
Root Cause
In UIViewController+NXNavigationExtension.m, line ~292:
- (void)nx_setupNavigationBar {
// ...
if (![self.view isKindOfClass:[UIScrollView class]]) {
[self.view addSubview:self.nx_navigationBar]; // ⚠️ Triggers warning for UIHostingController
}
}
Since the current project architecture targets iOS 15+ and the main project heavily uses UIKit, embedding SwiftUI pages within a UIKit navigation stack is the best implementation approach for me right now.Metadata
Metadata
Assignees
Labels
No labels