Skip to content

Commit

Permalink
Improve SwiftUIWrapperView performance (#322)
Browse files Browse the repository at this point in the history
  • Loading branch information
bryankeller authored Nov 14, 2024
1 parent b7ebeee commit 8c36887
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions Sources/Public/ItemViews/SwiftUIWrapperView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public final class SwiftUIWrapperView<Content: View>: UIView {

public init(contentAndID: ContentAndID) {
self.contentAndID = contentAndID
hostingController = UIHostingController(rootView: AnyView(contentAndID.content))
hostingController = UIHostingController(rootView: contentAndID.content)
hostingController._disableSafeArea = true

super.init(frame: .zero)
Expand Down Expand Up @@ -59,7 +59,9 @@ public final class SwiftUIWrapperView<Content: View>: UIView {
public override var isHidden: Bool {
didSet {
if isHidden {
hostingController.rootView = AnyView(EmptyView())
hostingControllerView.removeFromSuperview()
} else {
addSubview(hostingControllerView)
}
}
}
Expand Down Expand Up @@ -99,14 +101,14 @@ public final class SwiftUIWrapperView<Content: View>: UIView {

fileprivate var contentAndID: ContentAndID {
didSet {
hostingController.rootView = AnyView(contentAndID.content)
hostingController.rootView = contentAndID.content
configureGestureRecognizers()
}
}

// MARK: Private

private let hostingController: UIHostingController<AnyView>
private let hostingController: UIHostingController<Content>

private var hostingControllerView: UIView {
hostingController.view
Expand Down

0 comments on commit 8c36887

Please sign in to comment.