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

Additional operators for LayoutAnchors? #152

Open
ydnar opened this issue Sep 14, 2020 · 2 comments
Open

Additional operators for LayoutAnchors? #152

ydnar opened this issue Sep 14, 2020 · 2 comments

Comments

@ydnar
Copy link

ydnar commented Sep 14, 2020

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
Copy link
Member

s4cha commented Nov 19, 2020

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

@ydnar
Copy link
Author

ydnar commented Nov 19, 2020

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!

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