File tree 1 file changed +26
-0
lines changed
Sources/ContainerController
1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change 7
7
//
8
8
9
9
import UIKit
10
+ import SwiftUI
10
11
11
12
@available ( iOS 13 . 0 , * )
12
13
open class ContainerController : NSObject {
@@ -25,6 +26,8 @@ open class ContainerController: NSObject {
25
26
26
27
public var footerView : UIView ?
27
28
29
+ public var hostingController : UIHostingController < AnyView > ?
30
+
28
31
// MARK: Layout
29
32
30
33
public var layout : ContainerLayout = ContainerLayout ( )
@@ -452,6 +455,29 @@ open class ContainerController: NSObject {
452
455
calculationViews ( )
453
456
}
454
457
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
+
455
481
// MARK: - Pan Gesture
456
482
457
483
@objc private func handlePan( _ gesture: UIPanGestureRecognizer ) {
You can’t perform that action at this time.
0 commit comments