Skip to content

Commit

Permalink
Update view inspection (#52)
Browse files Browse the repository at this point in the history
  • Loading branch information
noahsmartin authored Sep 28, 2023
1 parent 2052d94 commit 8a1e2ae
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion Sources/SnapshotPreviewsCore/ViewInspection.swift
Original file line number Diff line number Diff line change
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

0 comments on commit 8a1e2ae

Please sign in to comment.