uptech / constraid Goto Github PK
View Code? Open in Web Editor NEWYour friendly NSLayoutConstraint Aid
License: MIT License
Your friendly NSLayoutConstraint Aid
License: MIT License
We want to do this so that the API is consistent now that we have started to really settle on the names of things.
matchWidth(of item:)
matchHeight(of item:)
expand(fromHeightOf:)
expand(fromWidthOf:)
square()
signature should look roughly as follows:
func limitHeight(_ of: Constraid.View, to: CGFloat)
The Baseline Standing Spacing Constraints are supposed to be useful to seperate two labels from eachother vertically as when the Dynamic Font style sizes change it adjust the baseline spacing appropriately.
Vertical Spacing Constraints on the other hand don't do this. But, either way we should look into how we want to hande this type of constraint.
Signature should look roughly as follows:
func expandHeight(_ of: Constraid.View, from: CGFloat)
We need to do this so that we can get feedback on pull requests and if they build cleanly or if they have problems.
We need to fix all the bugs like #39 not just that one.
For example
setHeight(toWidthOf:)
setHeight(toHeightOf:)
signature should look something like the following:
func limitWidth(_ of: Constraid.View, to: CGFloat)
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.
Or maybe it is ok to make the user call activate(). Although, the majority use case is for them to be activated. It is only in animation cases or showing/hiding things where you want to create non active constraints to begin.
Here is a quick link I found on it that might be valuable.
https://www.hackingwithswift.com/new-syntax-swift-2-availability-checking
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)
])
}
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.
We want to do this despite it being a breaking change because we are trying to standardize on the interface and be more consistent as it promotes discoverability.
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)
])
}
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.
The signature should look as follows:
func expandWidth(_ of: Constraid.View, from: CGFloat)
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)
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.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.