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] Dynamic constraints/Removing constraints #3

Open
theSherwood opened this issue Jan 19, 2024 · 7 comments
Open

[Question] Dynamic constraints/Removing constraints #3

theSherwood opened this issue Jan 19, 2024 · 7 comments

Comments

@theSherwood
Copy link

Looking at the API, there don't seem to be any options for removing constraints or subviews. I didn't see anything in the docs or examples about how to handle the case of subviews getting removed or their relationships to other subviews changing. Is there any way to do that with this library?

@trusktr
Copy link
Member

trusktr commented Jan 19, 2024

Currently we just make a new auto layout view with the new constraints like so:

https://github.com/lume/lume/blob/deb0d9a90db442dd4793e6e0920a252c31c5cce6/src/layouts/Autolayout.ts#L149-L152

@trusktr
Copy link
Member

trusktr commented Jan 19, 2024

For now that's the only official way, as the View only has addConstraint() and no reciprocal removeConstraint():

The underlying kiwi.Solver does have both add and remove methods though:

To optimize this so that we don't have to recreate the whole View to change constraints, we need to hook up a new removeConstraints method to kiwi.Solver's.

@theSherwood
Copy link
Author

Hey, thanks for the quick reply.

The underlying kiwi.Solver does have both add and remove methods though

I noticed that about the kiwi solver. Is adding removeConstraint on the roadmap or are you saying that you'd be open to the right PR?

I guess another wrinkle might be making sure that the VFL/EVFL parsers return the constraints they create so that they can be removed. It would also be nice to be able to remove a SubView and have it automatically remove all associated constraints.

@theSherwood
Copy link
Author

I guess another wrinkle might be making sure that the VFL/EVFL parsers return the constraints they create so that they can be removed.

Looks like this is already the case.

I notice that there are also some constraints created implicitly in SubView. Those may or may not be the kinds of constraints that a user might want to remove. I don't know.

@trusktr
Copy link
Member

trusktr commented Jan 21, 2024

Yeah, that would be robust. Add or remove things and it updates as we'd expect.

I don't have the time at the moment to get to this, but would be happy to merge a PR!

@theSherwood
Copy link
Author

Looking more at this, I think it might make some sense to make some changes to Kiwi first. Are you open to PRs? There's no public API in Kiwi to return the constraints, for example.

@trusktr
Copy link
Member

trusktr commented Jan 22, 2024

Yeah, totally open to PRs. Would be great to add that.

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