Skip to content

Fix issue where introspecting within a LazyVStack would silently fail #153

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

Merged
merged 1 commit into from
Aug 21, 2022
Merged
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
17 changes: 13 additions & 4 deletions Introspect/UIKitIntrospectionView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import SwiftUI
@available(iOS 13.0, *)
public class IntrospectionUIView: UIView {

var moveToWindowHandler: (() -> Void)?

required init() {
super.init(frame: .zero)
isHidden = true
Expand All @@ -16,6 +18,11 @@ public class IntrospectionUIView: UIView {
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

override public func didMoveToWindow() {
super.didMoveToWindow()
moveToWindowHandler?()
}
}

/// Introspection View that is injected into the UIKit hierarchy alongside the target view.
Expand Down Expand Up @@ -53,11 +60,13 @@ public struct UIKitIntrospectionView<TargetViewType: UIView>: UIViewRepresentabl
_ uiView: IntrospectionUIView,
context: UIViewRepresentableContext<UIKitIntrospectionView>
) {
DispatchQueue.main.async {
guard let targetView = self.selector(uiView) else {
return
uiView.moveToWindowHandler = {
DispatchQueue.main.async {
guard let targetView = self.selector(uiView) else {
return
}
self.customize(targetView)
}
self.customize(targetView)
}
}
}
Expand Down