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