-
Notifications
You must be signed in to change notification settings - Fork 18
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
Extensions, Spacing, IsInverted and Others 🙂 #6
Comments
Also maybe properties of the Anchor type could be public so that we could access them in our own extensions? 🌚
|
AddSubview
Safe Area It's for the same reasons I kept safe area (and margins guides) helpers out of the library. I think the existing API is reasonable clear: view.anchors.edges.pin()
view.anchors.edges.pin(to: container.layoutMarginsGuide)
view.anchors.edges.pin(to: container.safeAreaLayoutGuide) If you use these a lot, I think it's worth adding a few extension directly to the view: // or whichever naming you prefer
view.pinEdgesToSuperviewEdges()
view.pinEdgesToLayoutMargins()
view.pinEdgesToSafeArea() I prefer Naming The idea is, for better or worse, to have two separate sets of APIs. The first set is what I call "Core API". These APIs just mechanically add the constraints and don't have any additional logic or special meaning behind them. And then there are "Semantic" APIs that do.
a.anchors.bottom.spacing(10, to: b.anchors.top)
b.anchors.top.spacing(10, to: a.anchors.bottom) You can add spacings in a similar way in the Interface Builder, and that's where I took the inspiration from. The So, I'm not sure it's worth using a separate word for axis – it makes the API slightly harder to learn. And in hindsight, IsInverted I designed it to be used for adding spacings between views that are adjacent to each other. So only "top' to "bottom" and "left" to "right" combinations are considered valid. For other scenarios, you can use I'm not sure I understand the |
Do you have an example where you'd like to access them? I was going for the smallest API surface possible in the framework to make sure it's easy to learn. I found other frameworks a bit unwieldy with their massive APIs and implementations: sometimes 10x the size of Align. This is the main reason I built my own. |
Thank you for all the answers, really appreciate 🙌
In my example I've found a way to setup constraints properly, but my point is that the
So I wanted to try and see if I can create a function that would solve the problem that I've described in the point above. But I couldn't access the
That's actually why we have chosen your framework 💯 |
Hi!
Thanks for building a small and simple Auto Layout library. I've been integrating it into our project and came up with couple thoughts/questions about the implementation 🙂
Thanks in advance for having a look at them!
AddSubview
I've found this extension in the tests part of the project and I think it's very useful. What was the motivation to remove it from the project itself?
LayoutAnchors
I've been able to easily pin anchors to the superview, but for the
SafeArea
I didn't find a simple way to do that. So I've implemented this extension. Though I've been wondering if it fits the Align philosophy. Maybe I don't see some big picture here 🤔Combining AddSubview + LayoutAnchors
Combining the above 2 I've been able to write code like this:
Or this:
So from my perspective the
UIView+AddSubview
is super nice addition 🙂Align/Spacing -> Pin
I wanted to have the same interface so I've created couple more extensions:
Is there some specific reasons why you kept
spacing
andalign
and didn't rename them topin
?IsInverted
I've been looking at the source code and found that the implementation of the variable
isInverted
is different inpin
andspacing
functions.For example
spacing
has this check:But doesn't have this one:
Which in my opinion is also needed to make sure we invert the spacing in this case. So maybe we can simplify it and use the same logic as in the
pin
?While writing the last point about the
IsInverted
I've noticed thatspacing
also inverts therelation
. Which is probably the reason whyisInverted
is calculated differently here.But still the
spacing
function allows to write the following:Which will produce wrong layout 🤔
The text was updated successfully, but these errors were encountered: