diff --git a/DemoApp/DemoApp/TestViews/EmptyView.swift b/DemoApp/DemoApp/TestViews/EmptyView.swift index a9862f67..62b483e4 100644 --- a/DemoApp/DemoApp/TestViews/EmptyView.swift +++ b/DemoApp/DemoApp/TestViews/EmptyView.swift @@ -20,8 +20,18 @@ struct EmptyViewTest: View { } } +struct EmptyIfTest: View { + var body: some View { + if true { + EmptyView() + } + Text("Hello World") + } +} + struct EmptyViewTest_Previews: PreviewProvider { static var previews: some View { EmptyViewTest() + EmptyIfTest() } } diff --git a/Sources/SnapshotPreviewsCore/ViewInspection.swift b/Sources/SnapshotPreviewsCore/ViewInspection.swift index 2abe03e1..801e3b73 100644 --- a/Sources/SnapshotPreviewsCore/ViewInspection.swift +++ b/Sources/SnapshotPreviewsCore/ViewInspection.swift @@ -31,7 +31,11 @@ public enum ViewInspection { private static func children(of view: some View) -> [(any View, [any ViewModifier])] { let viewType = type(of: view) let typeName = String(reflecting: viewType) - if typeName.starts(with: "SwiftUI._ConditionalContent") { + if typeName.starts(with: "Swift.Optional<") { + if let child = Mirror(reflecting: view).children.first?.value as? any View { + return children(of: child) + } + } else if typeName.starts(with: "SwiftUI._ConditionalContent") { let storage = Self.attribute(label: "storage", value: view)! if let trueContent = Self.attribute(label: "trueContent", value: storage) as? any View { return childrenIfMultiple(of: trueContent)