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

Make superview relationship implicit #1

Open
ajfigueroa opened this issue Mar 8, 2018 · 3 comments
Open

Make superview relationship implicit #1

ajfigueroa opened this issue Mar 8, 2018 · 3 comments

Comments

@ajfigueroa
Copy link
Contributor

For example, when we want to layout a view with respect to it's superview we usually have to explicitly pass in the view which doesn't look as readable

Given a viewA and a subview viewB that we're trying to make the top match

viewB.applyLayout([
    .matchTopTo(viewA, withOffset: 10.0)
])

This could be better expressed by inferring the superview relationship:

view.applyLayout([
    .matchTopToParent(withOffset: 10.0)
])
@gyfelton
Copy link
Contributor

gyfelton commented Dec 6, 2019

If parent is nil (no superview), what's the expected behaviour of this call matchTopToParent?

@ajfigueroa
Copy link
Contributor Author

Let's look at this example:

// viewA has no superview
viewA.applyLayout([
    .matchTopToParent(withOffset: 10.0)
])

We would be saying "match the top of viewA to nil with an offset of 10".

If a view has no superview and someone calls matchTopToParent then I would expect this method to either throw an exception or perform a no-op.
What do you think?

@gyfelton
Copy link
Contributor

gyfelton commented Dec 6, 2019

I say no op so matchToParent is just a convenience call to matchTopTo() with return early if cannot resolve superview

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