nalexn / ViewInspector

Runtime introspection and unit testing of SwiftUI views
MIT License
2.09k stars 145 forks source link

iOS 17: Button style check #277

Closed ichikmarev closed 7 months ago

ichikmarev commented 7 months ago

Hey, thanks for amazing library, spotted interesting case for iOS17 buttonStyle check

@available(iOS 13.0, macOS 10.15, tvOS 13.0, *)
public extension InspectableView {

    func buttonStyle() throws -> Any {
        let modifier = try self.modifier({ modifier -> Bool in
            return [
                "PrimitiveButtonStyleContainerModifier",
                "ButtonStyleContainerModifier",
                "ButtonStyleModifier",
            ].contains(where: { modifier.modifierType.hasPrefix($0) })
        }, call: "buttonStyle")
        if let style = try? Inspector.attribute(path: "modifier|style|style", value: modifier) {
            return style
        }
        return try Inspector.attribute(path: "modifier|style", value: modifier)
    }
}

We utilize a custom ButtonStyle with an internal style property. However, when conducting tests on iOS 17, it fails at the modifier|style|style path. Perhaps we could consider updating this to directly check the iOS version at this specific point?

nalexn commented 7 months ago

Released in v0.9.9