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

Question: How to check the Shape type #158

Closed
gedaiu opened this issue Jan 30, 2022 · 2 comments
Closed

Question: How to check the Shape type #158

gedaiu opened this issue Jan 30, 2022 · 2 comments

Comments

@gedaiu
Copy link

gedaiu commented Jan 30, 2022

Is there a way to query all the shapes of certain type or check if a Shape view is of a certain type?

maybe something like this?

let elements = try subject
                        .inspect()
                        .findAll(ViewType.Shape.self, where: { shape in return shape.isCircle })

or

let elements = try subject
                        .inspect()
                        .findAll(ViewType.Circle.self, where: { _ in true })

@nalexn
Copy link
Owner

nalexn commented Jan 31, 2022

Hey, the way SwiftUI stores Shape views does not allow to reliably judge on its type, however, as a workaround you can try to compare the returned Shape's path(in rect: CGRect).

@gedaiu
Copy link
Author

gedaiu commented Jan 31, 2022

hmmm... I actually want a component that based on it's state to render different shapes of the same size... not sure if path(in rect: CGRect) will work. But I think I can wrap the shapes in some other views and query those wrappers to check the right thing is happening

@nalexn nalexn closed this as completed Sep 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants