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

Update view inspection #52

Merged
merged 1 commit into from Sep 28, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 12 additions & 1 deletion Sources/SnapshotPreviewsCore/ViewInspection.swift
Expand Up @@ -68,7 +68,8 @@ public enum ViewInspection {
}

private static func getModifier<T>(of view: some View, parseModifier: (Any) -> T?) -> T? {
let typeName = String(reflecting: type(of: view))
let viewType = type(of: view)
let typeName = String(reflecting: viewType)
if typeName.starts(with: "SwiftUI.ModifiedContent") {
let modifier = Self.attribute(label: "modifier", value: view)!
if let result = parseModifier(modifier) {
Expand All @@ -80,6 +81,16 @@ public enum ViewInspection {
let storage = Self.attribute(label: "storage", value: view)!
let storageView = Self.attribute(label: "view", value: storage) as! any View
return getModifier(of: storageView, parseModifier: parseModifier)
} else if typeName.starts(with: "SwiftUI.Tuple") {
return getModifier(of: tupleChildren(view)[0], parseModifier: parseModifier)
} else if typeName.starts(with: "SwiftUI.Group") {
let content = Self.attribute(label: "content", value: view) as! any View
return getModifier(of: content, parseModifier: parseModifier)
} else if typeName.starts(with: "SwiftUI.ForEach"), let provider = view as? ViewsProvider {
return getModifier(of: provider.views()[0], parseModifier: parseModifier)
}
if viewType.Body != Never.self && !typeName.starts(with: "SwiftUI.") {
return getModifier(of: view.body, parseModifier: parseModifier)
}
return nil
}
Expand Down