@@ -458,24 +458,25 @@ open class ContainerController: NSObject {
458
458
// MARK: - Add SwiftUI View
459
459
460
460
public func removeSwiftUIView( ) {
461
- // self.hostingController?.willMove(toParent: nil)
461
+ self . hostingController? . willMove ( toParent: nil )
462
462
self . hostingController? . view. removeFromSuperview ( )
463
- // self.hostingController?.removeFromParent()
463
+ self . hostingController? . removeFromParent ( )
464
464
self . hostingController = nil
465
465
}
466
466
467
- public func add< V: View > ( swiftUIView: V ) {
467
+ public func add< V: View > ( swiftUIView: V , parentViewController : UIViewController ? = nil ) {
468
468
guard let contentView = self . view. contentView else {
469
469
return
470
470
}
471
471
removeSwiftUIView ( )
472
472
let hostingController = UIHostingController ( rootView: AnyView ( swiftUIView) )
473
473
self . hostingController = hostingController
474
- // self.controller?.addChild(hostingController)
474
+ let parent = parentViewController ?? self . controller
475
+ parent? . addChild ( hostingController)
475
476
hostingController. view. frame = contentView. bounds
476
- hostingController. view. autoresizingMask = [ . flexibleWidth, . flexibleBottomMargin ]
477
+ hostingController. view. autoresizingMask = [ . flexibleWidth, . flexibleHeight ]
477
478
contentView. addSubview ( hostingController. view)
478
- // hostingController.didMove(toParent: self.controller )
479
+ hostingController. didMove ( toParent: parent )
479
480
}
480
481
481
482
// MARK: - Pan Gesture
0 commit comments