Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support stateful popovers #73

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions Sources/PopoverGestureContainer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ class PopoverGestureContainer: UIView {
/// Store the bounds for later.
previousBounds = bounds
}

private lazy var host: UIHostingController<AnyView> = UIHostingController(rootView: AnyView(PopoverContainerView(popoverModel: popoverModel)))

override func didMoveToWindow() {
super.didMoveToWindow()
Expand All @@ -45,15 +47,13 @@ class PopoverGestureContainer: UIView {
guard let window = window else { return }

/// Create the SwiftUI view that contains all the popovers.
let popoverContainerView = PopoverContainerView(popoverModel: popoverModel)
.environment(\.window, window) /// Inject the window.

let hostingController = UIHostingController(rootView: popoverContainerView)
hostingController.view.frame = bounds
hostingController.view.backgroundColor = .clear
hostingController.view.autoresizingMask = [.flexibleWidth, .flexibleHeight]
host.rootView = AnyView(host.rootView.environment(\.window, window)) // Inject the window.
host.view.frame = bounds
host.view.backgroundColor = .clear
host.view.autoresizingMask = [.flexibleWidth, .flexibleHeight]

addSubview(hostingController.view)
addSubview(host.view)

/// Ensure the view is laid out so that SwiftUI animations don't stutter.
setNeedsLayout()
Expand Down