Improving view.edgesToSuperview(excluding:)
xinatanil opened this issue · comments
A very common case is when a view is stretched horizontally in superview, but top and bottom are tied to sibling views. E.g.
// stretching horizontally
myView.leadingToSuperview()
myView.trailingToSuperview()
myView.topToBottom(of: sibling1)
myView.bottomToTop(of: sibling2)
// stretching vertically
myView.topToSuperview()
myView.bottomToSuperview()
myView.leadingToTrailing(of: sibling1)
myView.trailingToLeading(of: sibling2)
It would be very cool to have a method like stretchHorizontallyInSuperview()
and stretchVerticallyInSuperview
because this operation is very frequent.
But while these methods are desirable, one of the side ways we can implement it is by improving edgesToSuperview(excluding:)
by making LayoutEdge
conform to OptionSetType
, so that we could do something like this
// stretching horizontally
myView.edgesToSuperview(excluding: [.top, .bottom])
myView.topToBottom(of: sibling1)
myView.bottomToTop(of: sibling2)
// stretching vertically
myView.edgesToSuperview(excluding: [.leading, .trailing])
myView.leadingToTrailing(of: sibling1)
myView.trailingToLeading(of: sibling2)
While this is a very tiny improvement, I feel like it would still be needed for this great library.
Hey @xinatanil, thank you for you kind words and this great idea, I ❤️ it!
I will add it as soon as I have some time, or would you like to make a PR?
Hey @roberthein, unfortunately I also don't have time at the moment, but as soon as I'll find some time, I'll make a PR
So yeah, I wouldn't mind to make a PR, but it might take up to a month.
I think I can do it faster, probably this weekend.. 😉
Lovely! 😍 Looks great! I'll merge this ASAP.
Thanks again! 💯 It's all in 3.1