GithubHelp home page GithubHelp logo

uptech / constraid Goto Github PK

View Code? Open in Web Editor NEW
11.0 11.0 3.0 451 KB

Your friendly NSLayoutConstraint Aid

License: MIT License

Objective-C 0.11% Swift 99.74% Ruby 0.16%
autolayout autolayout-constraints ios macos swift swift-framework swift4 swift5

constraid's People

Contributors

claude avatar dependabot[bot] avatar drewdeponte avatar gitter-badger avatar jasonjrr avatar muescha avatar ryanhedges avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

constraid's Issues

Add limitHeight method

signature should look roughly as follows:

func limitHeight(_ of: Constraid.View, to: CGFloat)

Add a CHANGELOG.md

We need a CHANGELOG.md so people can see the high level important changes per release rather than having to sift through Git commit logs.

Add support for layout guides

    open func flush(withTopLayoutGuideOf item: UIViewController, constant: CGFloat = 0.0,
                    multiplier: CGFloat = 1.0, priority: UILayoutPriority = UILayoutPriorityRequired) {

        self.translatesAutoresizingMaskIntoConstraints = false
        NSLayoutConstraint.activate([
            NSLayoutConstraint(item: self, attribute: .top, relatedBy: .equal,
                               toItem: item.topLayoutGuide, attribute: .bottom, multiplier: multiplier,
                               constant: constant, priority: priority)
            ])
    }

    open func flush(withBottomLayoutGuideOf item: UIViewController, constant: CGFloat = 0.0,
                    multiplier: CGFloat = 1.0, priority: UILayoutPriority = UILayoutPriorityRequired) {

        self.translatesAutoresizingMaskIntoConstraints = false
        NSLayoutConstraint.activate([
            NSLayoutConstraint(item: self, attribute: .bottom, relatedBy: .equal,
                               toItem: item.bottomLayoutGuide, attribute: .top, multiplier: multiplier,
                               constant: constant, priority: priority)
            ])
    }

Change API design to no longer use UIView extension

We need to do this because it is clear that it is coupling us to non-functional characteristics of UIView. In fact this bit us already when upgrading to Swift 4.0 as we were forced to rename center() to middle() when using the extension style API because UIView now has a center() property instead of method and it was conflicting with our center() methods.

Add setHeightAspectRatio

    open func setHeightAspectRatio(_ ratio: CGFloat, priority: UILayoutPriority = UILayoutPriorityRequired) {

        self.translatesAutoresizingMaskIntoConstraints = false
        NSLayoutConstraint.activate([
            NSLayoutConstraint(item: self, attribute: .height,
                               relatedBy: .equal, toItem: self, attribute: .width,
                               multiplier: ratio, constant: 0.0, priority: priority)
            ])
    }

Add @discardableResult attribute to the methods and a ConstraintCollection object

We should do this so that each of the methods can return a collection of constraints that can easily be stored, and also easily be activated or deactivated.

let constraints = viewA.center(in: viewB)
...
constraints.deactivate()
...
constraints.activate()

Adding the @discardableResult attribute to the methods will suppress the compiler warnings for the methods when the return value is not used.

Add a cupped method

This would add the constraints similar to a horse shoe.

The following are the example calls

a.cupped(byLeadingEdgeOf: b)
a.cupped(byTrailingEdgeOf: b)
a.cupped(byTopEdgeOf: b)
a.cupped(byBottomEdgeOf: b)
a.cupped(byLeadingMarginOf: b)
a.cupped(byTrailingMarginOf: b)
a.cupped(byTopMarginOf: b)
a.cupped(byBottomMarginOf: b)

Change constant to meaningful promoter name, possibly insetBy

I have been trying to better organize the issues, and therefore associated them with a new milestone for v2.0.0 of the project. With this one of the goals I would like to achieve is making the API discoverable and understandable ideally without having to reference documentation. With that I started looking at and thinking about one of the most confusing parts of the current API. You guessed it, the constant: parameter for all of the methods.

The flush(withMargin…) and flush(withEdge…) methods I believe makes sense to rename constant: to inset: because I believe it communicates that if given a positive value of inset: 5 it would inset the view from the related view by 5.

This led me to then start thinking about the center() family of methods and trying to come up with a more meaningful name for the constant: parameter in that context. In the case of center the way constant: works with NSLayoutConstraint is that you basically have a coordiante system with 0,0 at the center point. Then the provided constant if positive adjusts the view either down or to the right depending on if it is a centerY or centerX constraint.

This would mean if I called the following method fooView.center(within: barView, constant: 5) it would place the fooView 5 down and 5 to the right of the center point of barView. Inversely if we called fooView.center(within: barView, constant: -5) it would place the fooView 5 up and 5 to the left of the center point of barView.

So far I have the following names/ideas, but I would love input from others.

  • shiftRightBy: 5
  • offsetRightBy: 5
  • leadingOffsetBy: 5
  • trailingOffsetBy: 5
  • offsetToRightBy: 5
  • offsetBy: 5
  • offsetBy: 5, withOffsetDirection: .up

So far the majority of these could potentially work for the center horizontially and center vertically methods, however they don’t really fit for the generic center method, except for maybe the offsetBy and offsetBy: 5, withOffsetDirection: .up cases.

I welcome all thoughts and input on this matter.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.