File tree Expand file tree Collapse file tree 1 file changed +26
-0
lines changed
Sources/ContainerController Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change 77//
88
99import UIKit
10+ import SwiftUI
1011
1112@available ( iOS 13 . 0 , * )
1213open class ContainerController : NSObject {
@@ -25,6 +26,8 @@ open class ContainerController: NSObject {
2526
2627 public var footerView : UIView ?
2728
29+ public var hostingController : UIHostingController < AnyView > ?
30+
2831 // MARK: Layout
2932
3033 public var layout : ContainerLayout = ContainerLayout ( )
@@ -452,6 +455,29 @@ open class ContainerController: NSObject {
452455 calculationViews ( )
453456 }
454457
458+ // MARK: - Add SwiftUI View
459+
460+ public func removeSwiftUIView( ) {
461+ // self.hostingController?.willMove(toParent: nil)
462+ self . hostingController? . view. removeFromSuperview ( )
463+ // self.hostingController?.removeFromParent()
464+ self . hostingController = nil
465+ }
466+
467+ public func add< V: View > ( swiftUIView: V ) {
468+ guard let contentView = self . view. contentView else {
469+ return
470+ }
471+ removeSwiftUIView ( )
472+ let hostingController = UIHostingController ( rootView: AnyView ( swiftUIView) )
473+ self . hostingController = hostingController
474+ // self.controller?.addChild(hostingController)
475+ hostingController. view. frame = contentView. bounds
476+ hostingController. view. autoresizingMask = [ . flexibleWidth, . flexibleBottomMargin]
477+ contentView. addSubview ( hostingController. view)
478+ // hostingController.didMove(toParent: self.controller)
479+ }
480+
455481 // MARK: - Pan Gesture
456482
457483 @objc private func handlePan( _ gesture: UIPanGestureRecognizer ) {
You can’t perform that action at this time.
0 commit comments