freshOS / Stevia

:leaves: Concise Autolayout code
https://freshos.github.io/SteviaDocs/
MIT License
3.38k stars 213 forks source link

Additional operators for LayoutAnchors? #152

Open ydnar opened 4 years ago

ydnar commented 4 years ago

Would it be possible to add support for additional operators other than == to layout anchors (SteviaLayoutXAxisAnchor, SteviaLayoutYAxisAnchor), such as < <= > >=?

We work around this now by using multiple constraints with differing priorities.

s4cha commented 3 years ago

@ydnar Please excuse the late reply. Could you show the code you write at the moment and how you would ideally write it ?

ydnar commented 3 years ago

Thanks!

We use Stevia to lay out views with respect to the layout guides and safe area. We often want to express a bottom constraint as <=. For instance, from some code we’re currently using:

        textView.Bottom <= Bottom - 12
        (textView.Bottom == layoutMarginsGuide.Bottom + 10).priority = .defaultHigh

Ideally we could express this as:

        textView.Bottom <= Bottom - 12
        textView.Bottom <= layoutMarginsGuide.Bottom + 10

I tried to implement ourselves, e.g.:

@available(iOS 9.0, *)
@discardableResult
public func <= (left: SteviaAttribute, right: SteviaLayoutYAxisAnchor) -> NSLayoutConstraint {
…

…but couldn’t because SteviaAttribute.attribute is internal, which prevents anyone from extending this. Could you make these attributes public?

Related: thanks for adding the operators in #155!