mirror of https://github.com/SnapKit/SnapKit
Release v3.2.0 (#403)
* make 'layoutConstraints' public again (#382) * Fix wrong function call within contentCompressionResistanceHorizontalPriority (#387) * Missing property topMargin on ConstraintMakerExtendable (#393) This pull request adds the missing property "topMargin" to ConstraintMakerExtendable class. * Switched main target build settings' "skip install" default settings to YES. (#391) * Add an isActive API to Constraint * Priority enum (#345) * Adds ConstraintPriority enum to ConstraintMakerPrioritizable * Constraints priority is now more robust * Adds priority enum function * Fixes compile error * Adds failable initializer. Custom macOS medium priority. Adds back deleted methods * Updates depracation messages * Improve Priority API's * Add extra protocol conformances to ConstraintPriority * Tweak priority API's for offseting * Tweak priority API's some more and add tests * Prepare for release
This commit is contained in:
parent
9a82379f93
commit
9430a3dcd9
|
@ -59,7 +59,7 @@ platform :ios, '10.0'
|
||||||
use_frameworks!
|
use_frameworks!
|
||||||
|
|
||||||
target '<Your Target Name>' do
|
target '<Your Target Name>' do
|
||||||
pod 'SnapKit', '~> 3.1.2'
|
pod 'SnapKit', '~> 3.2.0'
|
||||||
end
|
end
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -83,7 +83,7 @@ $ brew install carthage
|
||||||
To integrate SnapKit into your Xcode project using Carthage, specify it in your `Cartfile`:
|
To integrate SnapKit into your Xcode project using Carthage, specify it in your `Cartfile`:
|
||||||
|
|
||||||
```ogdl
|
```ogdl
|
||||||
github "SnapKit/SnapKit" ~> 3.1.2
|
github "SnapKit/SnapKit" ~> 3.2.0
|
||||||
```
|
```
|
||||||
|
|
||||||
Run `carthage update` to build the framework and drag the built `SnapKit.framework` into your Xcode project.
|
Run `carthage update` to build the framework and drag the built `SnapKit.framework` into your Xcode project.
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
Pod::Spec.new do |s|
|
Pod::Spec.new do |s|
|
||||||
s.name = 'SnapKit'
|
s.name = 'SnapKit'
|
||||||
s.version = '3.1.2'
|
s.version = '3.2.0'
|
||||||
s.license = 'MIT'
|
s.license = 'MIT'
|
||||||
s.summary = 'Harness the power of auto layout with a simplified, chainable, and compile time safe syntax.'
|
s.summary = 'Harness the power of auto layout with a simplified, chainable, and compile time safe syntax.'
|
||||||
s.homepage = 'https://github.com/SnapKit/SnapKit'
|
s.homepage = 'https://github.com/SnapKit/SnapKit'
|
||||||
s.authors = { 'Robert Payne' => 'robertpayne@me.com' }
|
s.authors = { 'Robert Payne' => 'robertpayne@me.com' }
|
||||||
s.social_media_url = 'http://twitter.com/robertjpayne'
|
s.social_media_url = 'http://twitter.com/robertjpayne'
|
||||||
s.source = { :git => 'https://github.com/SnapKit/SnapKit.git', :tag => '3.1.2' }
|
s.source = { :git => 'https://github.com/SnapKit/SnapKit.git', :tag => '3.2.0' }
|
||||||
|
|
||||||
s.ios.deployment_target = '8.0'
|
s.ios.deployment_target = '8.0'
|
||||||
s.osx.deployment_target = '10.11'
|
s.osx.deployment_target = '10.11'
|
||||||
|
|
|
@ -33,6 +33,7 @@
|
||||||
EE235FC31C5785DC00C08960 /* ConstraintLayoutSupportDSL.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235FBF1C5785DC00C08960 /* ConstraintLayoutSupportDSL.swift */; };
|
EE235FC31C5785DC00C08960 /* ConstraintLayoutSupportDSL.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235FBF1C5785DC00C08960 /* ConstraintLayoutSupportDSL.swift */; };
|
||||||
EE235FC81C5785E200C08960 /* ConstraintView+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235FC61C5785E200C08960 /* ConstraintView+Extensions.swift */; };
|
EE235FC81C5785E200C08960 /* ConstraintView+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235FC61C5785E200C08960 /* ConstraintView+Extensions.swift */; };
|
||||||
EE4910991B19A40200A54F1F /* SnapKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = EEBCC9D819CC627D0083B827 /* SnapKit.framework */; };
|
EE4910991B19A40200A54F1F /* SnapKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = EEBCC9D819CC627D0083B827 /* SnapKit.framework */; };
|
||||||
|
EE6087751E4F133E0029CF84 /* ConstraintPriority.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE6087741E4F133E0029CF84 /* ConstraintPriority.swift */; };
|
||||||
EE6898CB1DA7B3A100D47F33 /* LayoutConstraintItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE6898CA1DA7B3A100D47F33 /* LayoutConstraintItem.swift */; };
|
EE6898CB1DA7B3A100D47F33 /* LayoutConstraintItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE6898CA1DA7B3A100D47F33 /* LayoutConstraintItem.swift */; };
|
||||||
EECDB3741AC0C9B6006BBC11 /* SnapKit.h in Headers */ = {isa = PBXBuildFile; fileRef = EECDB3661AC0C95C006BBC11 /* SnapKit.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
EECDB3741AC0C9B6006BBC11 /* SnapKit.h in Headers */ = {isa = PBXBuildFile; fileRef = EECDB3661AC0C95C006BBC11 /* SnapKit.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||||
EECDB3931AC0CB52006BBC11 /* Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = EECDB36A1AC0C95C006BBC11 /* Tests.swift */; };
|
EECDB3931AC0CB52006BBC11 /* Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = EECDB36A1AC0C95C006BBC11 /* Tests.swift */; };
|
||||||
|
@ -71,6 +72,7 @@
|
||||||
EE235FBE1C5785DC00C08960 /* ConstraintViewDSL.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ConstraintViewDSL.swift; sourceTree = "<group>"; };
|
EE235FBE1C5785DC00C08960 /* ConstraintViewDSL.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ConstraintViewDSL.swift; sourceTree = "<group>"; };
|
||||||
EE235FBF1C5785DC00C08960 /* ConstraintLayoutSupportDSL.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ConstraintLayoutSupportDSL.swift; sourceTree = "<group>"; };
|
EE235FBF1C5785DC00C08960 /* ConstraintLayoutSupportDSL.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ConstraintLayoutSupportDSL.swift; sourceTree = "<group>"; };
|
||||||
EE235FC61C5785E200C08960 /* ConstraintView+Extensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "ConstraintView+Extensions.swift"; sourceTree = "<group>"; };
|
EE235FC61C5785E200C08960 /* ConstraintView+Extensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "ConstraintView+Extensions.swift"; sourceTree = "<group>"; };
|
||||||
|
EE6087741E4F133E0029CF84 /* ConstraintPriority.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ConstraintPriority.swift; sourceTree = "<group>"; };
|
||||||
EE6898CA1DA7B3A100D47F33 /* LayoutConstraintItem.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LayoutConstraintItem.swift; sourceTree = "<group>"; };
|
EE6898CA1DA7B3A100D47F33 /* LayoutConstraintItem.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LayoutConstraintItem.swift; sourceTree = "<group>"; };
|
||||||
EE94F6081AC0F10A008767FF /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; };
|
EE94F6081AC0F10A008767FF /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; };
|
||||||
EE94F60A1AC0F10F008767FF /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/System/Library/Frameworks/AppKit.framework; sourceTree = DEVELOPER_DIR; };
|
EE94F60A1AC0F10F008767FF /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/System/Library/Frameworks/AppKit.framework; sourceTree = DEVELOPER_DIR; };
|
||||||
|
@ -187,6 +189,7 @@
|
||||||
EE235F6B1C5785C600C08960 /* ConstraintItem.swift */,
|
EE235F6B1C5785C600C08960 /* ConstraintItem.swift */,
|
||||||
EE235F6C1C5785C600C08960 /* LayoutConstraint.swift */,
|
EE235F6C1C5785C600C08960 /* LayoutConstraint.swift */,
|
||||||
EE6898CA1DA7B3A100D47F33 /* LayoutConstraintItem.swift */,
|
EE6898CA1DA7B3A100D47F33 /* LayoutConstraintItem.swift */,
|
||||||
|
EE6087741E4F133E0029CF84 /* ConstraintPriority.swift */,
|
||||||
);
|
);
|
||||||
name = Models;
|
name = Models;
|
||||||
sourceTree = "<group>";
|
sourceTree = "<group>";
|
||||||
|
@ -365,6 +368,7 @@
|
||||||
EE235FB51C5785D400C08960 /* ConstraintMakerEditable.swift in Sources */,
|
EE235FB51C5785D400C08960 /* ConstraintMakerEditable.swift in Sources */,
|
||||||
EEF68FBC1D78653000980C26 /* ConstraintLayoutGuide.swift in Sources */,
|
EEF68FBC1D78653000980C26 /* ConstraintLayoutGuide.swift in Sources */,
|
||||||
EE235FAC1C5785D400C08960 /* ConstraintMaker.swift in Sources */,
|
EE235FAC1C5785D400C08960 /* ConstraintMaker.swift in Sources */,
|
||||||
|
EE6087751E4F133E0029CF84 /* ConstraintPriority.swift in Sources */,
|
||||||
EE235F941C5785CE00C08960 /* ConstraintRelatableTarget.swift in Sources */,
|
EE235F941C5785CE00C08960 /* ConstraintRelatableTarget.swift in Sources */,
|
||||||
EEF68FA61D784A5300980C26 /* ConstraintDSL.swift in Sources */,
|
EEF68FA61D784A5300980C26 /* ConstraintDSL.swift in Sources */,
|
||||||
EE235FBB1C5785D400C08960 /* ConstraintMakerExtendable.swift in Sources */,
|
EE235FBB1C5785D400C08960 /* ConstraintMakerExtendable.swift in Sources */,
|
||||||
|
@ -506,6 +510,7 @@
|
||||||
PRODUCT_BUNDLE_IDENTIFIER = "io.snapkit.$(PRODUCT_NAME:rfc1034identifier)";
|
PRODUCT_BUNDLE_IDENTIFIER = "io.snapkit.$(PRODUCT_NAME:rfc1034identifier)";
|
||||||
PRODUCT_BUNDLE_PACKAGE_TYPE = FMWK;
|
PRODUCT_BUNDLE_PACKAGE_TYPE = FMWK;
|
||||||
PRODUCT_NAME = SnapKit;
|
PRODUCT_NAME = SnapKit;
|
||||||
|
SKIP_INSTALL = YES;
|
||||||
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
|
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
|
||||||
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
|
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
|
||||||
VERSIONING_SYSTEM = "apple-generic";
|
VERSIONING_SYSTEM = "apple-generic";
|
||||||
|
@ -525,6 +530,7 @@
|
||||||
PRODUCT_BUNDLE_IDENTIFIER = "io.snapkit.$(PRODUCT_NAME:rfc1034identifier)";
|
PRODUCT_BUNDLE_IDENTIFIER = "io.snapkit.$(PRODUCT_NAME:rfc1034identifier)";
|
||||||
PRODUCT_BUNDLE_PACKAGE_TYPE = FMWK;
|
PRODUCT_BUNDLE_PACKAGE_TYPE = FMWK;
|
||||||
PRODUCT_NAME = SnapKit;
|
PRODUCT_NAME = SnapKit;
|
||||||
|
SKIP_INSTALL = YES;
|
||||||
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
|
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
|
||||||
VERSIONING_SYSTEM = "apple-generic";
|
VERSIONING_SYSTEM = "apple-generic";
|
||||||
};
|
};
|
||||||
|
|
|
@ -28,10 +28,10 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
public final class Constraint {
|
public final class Constraint {
|
||||||
|
|
||||||
internal let sourceLocation: (String, UInt)
|
internal let sourceLocation: (String, UInt)
|
||||||
internal let label: String?
|
internal let label: String?
|
||||||
|
|
||||||
private let from: ConstraintItem
|
private let from: ConstraintItem
|
||||||
private let to: ConstraintItem
|
private let to: ConstraintItem
|
||||||
private let relation: ConstraintRelation
|
private let relation: ConstraintRelation
|
||||||
|
@ -46,10 +46,19 @@ public final class Constraint {
|
||||||
self.updateConstantAndPriorityIfNeeded()
|
self.updateConstantAndPriorityIfNeeded()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private var layoutConstraints: [LayoutConstraint]
|
public var layoutConstraints: [LayoutConstraint]
|
||||||
|
|
||||||
|
public var isActive: Bool {
|
||||||
|
for layoutConstraint in self.layoutConstraints {
|
||||||
|
if layoutConstraint.isActive {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
// MARK: Initialization
|
// MARK: Initialization
|
||||||
|
|
||||||
internal init(from: ConstraintItem,
|
internal init(from: ConstraintItem,
|
||||||
to: ConstraintItem,
|
to: ConstraintItem,
|
||||||
relation: ConstraintRelation,
|
relation: ConstraintRelation,
|
||||||
|
@ -67,17 +76,17 @@ public final class Constraint {
|
||||||
self.constant = constant
|
self.constant = constant
|
||||||
self.priority = priority
|
self.priority = priority
|
||||||
self.layoutConstraints = []
|
self.layoutConstraints = []
|
||||||
|
|
||||||
// get attributes
|
// get attributes
|
||||||
let layoutFromAttributes = self.from.attributes.layoutAttributes
|
let layoutFromAttributes = self.from.attributes.layoutAttributes
|
||||||
let layoutToAttributes = self.to.attributes.layoutAttributes
|
let layoutToAttributes = self.to.attributes.layoutAttributes
|
||||||
|
|
||||||
// get layout from
|
// get layout from
|
||||||
let layoutFrom = self.from.layoutConstraintItem!
|
let layoutFrom = self.from.layoutConstraintItem!
|
||||||
|
|
||||||
// get relation
|
// get relation
|
||||||
let layoutRelation = self.relation.layoutRelation
|
let layoutRelation = self.relation.layoutRelation
|
||||||
|
|
||||||
for layoutFromAttribute in layoutFromAttributes {
|
for layoutFromAttribute in layoutFromAttributes {
|
||||||
// get layout to attribute
|
// get layout to attribute
|
||||||
let layoutToAttribute: NSLayoutAttribute
|
let layoutToAttribute: NSLayoutAttribute
|
||||||
|
@ -130,18 +139,18 @@ public final class Constraint {
|
||||||
layoutToAttribute = layoutFromAttribute
|
layoutToAttribute = layoutFromAttribute
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// get layout constant
|
// get layout constant
|
||||||
let layoutConstant: CGFloat = self.constant.constraintConstantTargetValueFor(layoutAttribute: layoutToAttribute)
|
let layoutConstant: CGFloat = self.constant.constraintConstantTargetValueFor(layoutAttribute: layoutToAttribute)
|
||||||
|
|
||||||
// get layout to
|
// get layout to
|
||||||
var layoutTo: AnyObject? = self.to.target
|
var layoutTo: AnyObject? = self.to.target
|
||||||
|
|
||||||
// use superview if possible
|
// use superview if possible
|
||||||
if layoutTo == nil && layoutToAttribute != .width && layoutToAttribute != .height {
|
if layoutTo == nil && layoutToAttribute != .width && layoutToAttribute != .height {
|
||||||
layoutTo = layoutFrom.superview
|
layoutTo = layoutFrom.superview
|
||||||
}
|
}
|
||||||
|
|
||||||
// create layout constraint
|
// create layout constraint
|
||||||
let layoutConstraint = LayoutConstraint(
|
let layoutConstraint = LayoutConstraint(
|
||||||
item: layoutFrom,
|
item: layoutFrom,
|
||||||
|
@ -152,119 +161,113 @@ public final class Constraint {
|
||||||
multiplier: self.multiplier.constraintMultiplierTargetValue,
|
multiplier: self.multiplier.constraintMultiplierTargetValue,
|
||||||
constant: layoutConstant
|
constant: layoutConstant
|
||||||
)
|
)
|
||||||
|
|
||||||
// set label
|
// set label
|
||||||
layoutConstraint.label = self.label
|
layoutConstraint.label = self.label
|
||||||
|
|
||||||
// set priority
|
// set priority
|
||||||
layoutConstraint.priority = self.priority.constraintPriorityTargetValue
|
layoutConstraint.priority = self.priority.constraintPriorityTargetValue
|
||||||
|
|
||||||
// set constraint
|
// set constraint
|
||||||
layoutConstraint.constraint = self
|
layoutConstraint.constraint = self
|
||||||
|
|
||||||
// append
|
// append
|
||||||
self.layoutConstraints.append(layoutConstraint)
|
self.layoutConstraints.append(layoutConstraint)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: Public
|
// MARK: Public
|
||||||
|
|
||||||
@available(*, deprecated:3.0, message:"Use activate().")
|
@available(*, deprecated:3.0, message:"Use activate().")
|
||||||
public func install() {
|
public func install() {
|
||||||
self.activate()
|
self.activate()
|
||||||
}
|
}
|
||||||
|
|
||||||
@available(*, deprecated:3.0, message:"Use deactivate().")
|
@available(*, deprecated:3.0, message:"Use deactivate().")
|
||||||
public func uninstall() {
|
public func uninstall() {
|
||||||
self.deactivate()
|
self.deactivate()
|
||||||
}
|
}
|
||||||
|
|
||||||
public func activate() {
|
public func activate() {
|
||||||
self.activateIfNeeded()
|
self.activateIfNeeded()
|
||||||
}
|
}
|
||||||
|
|
||||||
public func deactivate() {
|
public func deactivate() {
|
||||||
self.deactivateIfNeeded()
|
self.deactivateIfNeeded()
|
||||||
}
|
}
|
||||||
|
|
||||||
@discardableResult
|
@discardableResult
|
||||||
public func update(offset: ConstraintOffsetTarget) -> Constraint {
|
public func update(offset: ConstraintOffsetTarget) -> Constraint {
|
||||||
self.constant = offset.constraintOffsetTargetValue
|
self.constant = offset.constraintOffsetTargetValue
|
||||||
return self
|
return self
|
||||||
}
|
}
|
||||||
|
|
||||||
@discardableResult
|
@discardableResult
|
||||||
public func update(inset: ConstraintInsetTarget) -> Constraint {
|
public func update(inset: ConstraintInsetTarget) -> Constraint {
|
||||||
self.constant = inset.constraintInsetTargetValue
|
self.constant = inset.constraintInsetTargetValue
|
||||||
return self
|
return self
|
||||||
}
|
}
|
||||||
|
|
||||||
@discardableResult
|
@discardableResult
|
||||||
public func update(priority: ConstraintPriorityTarget) -> Constraint {
|
public func update(priority: ConstraintPriorityTarget) -> Constraint {
|
||||||
self.priority = priority.constraintPriorityTargetValue
|
self.priority = priority.constraintPriorityTargetValue
|
||||||
return self
|
return self
|
||||||
}
|
}
|
||||||
|
|
||||||
@available(*, deprecated:3.0, message:"Use update(offset: ConstraintOffsetTarget) instead.")
|
@available(*, deprecated:3.0, message:"Use update(offset: ConstraintOffsetTarget) instead.")
|
||||||
public func updateOffset(amount: ConstraintOffsetTarget) -> Void { self.update(offset: amount) }
|
public func updateOffset(amount: ConstraintOffsetTarget) -> Void { self.update(offset: amount) }
|
||||||
|
|
||||||
@available(*, deprecated:3.0, message:"Use update(inset: ConstraintInsetTarget) instead.")
|
@available(*, deprecated:3.0, message:"Use update(inset: ConstraintInsetTarget) instead.")
|
||||||
public func updateInsets(amount: ConstraintInsetTarget) -> Void { self.update(inset: amount) }
|
public func updateInsets(amount: ConstraintInsetTarget) -> Void { self.update(inset: amount) }
|
||||||
|
|
||||||
@available(*, deprecated:3.0, message:"Use update(priority: ConstraintPriorityTarget) instead.")
|
@available(*, deprecated:3.0, message:"Use update(priority: ConstraintPriorityTarget) instead.")
|
||||||
public func updatePriority(amount: ConstraintPriorityTarget) -> Void { self.update(priority: amount) }
|
public func updatePriority(amount: ConstraintPriorityTarget) -> Void { self.update(priority: amount) }
|
||||||
|
|
||||||
@available(*, obsoleted:3.0, message:"Use update(priority: ConstraintPriorityTarget) instead.")
|
@available(*, obsoleted:3.0, message:"Use update(priority: ConstraintPriorityTarget) instead.")
|
||||||
public func updatePriorityRequired() -> Void {}
|
public func updatePriorityRequired() -> Void {}
|
||||||
|
|
||||||
@available(*, obsoleted:3.0, message:"Use update(priority: ConstraintPriorityTarget) instead.")
|
@available(*, obsoleted:3.0, message:"Use update(priority: ConstraintPriorityTarget) instead.")
|
||||||
public func updatePriorityHigh() -> Void { fatalError("Must be implemented by Concrete subclass.") }
|
public func updatePriorityHigh() -> Void { fatalError("Must be implemented by Concrete subclass.") }
|
||||||
|
|
||||||
@available(*, obsoleted:3.0, message:"Use update(priority: ConstraintPriorityTarget) instead.")
|
@available(*, obsoleted:3.0, message:"Use update(priority: ConstraintPriorityTarget) instead.")
|
||||||
public func updatePriorityMedium() -> Void { fatalError("Must be implemented by Concrete subclass.") }
|
public func updatePriorityMedium() -> Void { fatalError("Must be implemented by Concrete subclass.") }
|
||||||
|
|
||||||
@available(*, obsoleted:3.0, message:"Use update(priority: ConstraintPriorityTarget) instead.")
|
@available(*, obsoleted:3.0, message:"Use update(priority: ConstraintPriorityTarget) instead.")
|
||||||
public func updatePriorityLow() -> Void { fatalError("Must be implemented by Concrete subclass.") }
|
public func updatePriorityLow() -> Void { fatalError("Must be implemented by Concrete subclass.") }
|
||||||
|
|
||||||
// MARK: Internal
|
// MARK: Internal
|
||||||
|
|
||||||
internal func updateConstantAndPriorityIfNeeded() {
|
internal func updateConstantAndPriorityIfNeeded() {
|
||||||
for layoutConstraint in self.layoutConstraints {
|
for layoutConstraint in self.layoutConstraints {
|
||||||
let attribute = (layoutConstraint.secondAttribute == .notAnAttribute) ? layoutConstraint.firstAttribute : layoutConstraint.secondAttribute
|
let attribute = (layoutConstraint.secondAttribute == .notAnAttribute) ? layoutConstraint.firstAttribute : layoutConstraint.secondAttribute
|
||||||
layoutConstraint.constant = self.constant.constraintConstantTargetValueFor(layoutAttribute: attribute)
|
layoutConstraint.constant = self.constant.constraintConstantTargetValueFor(layoutAttribute: attribute)
|
||||||
|
|
||||||
#if os(iOS) || os(tvOS)
|
let requiredPriority = ConstraintPriority.required.value
|
||||||
let requiredPriority: UILayoutPriority = UILayoutPriorityRequired
|
|
||||||
#else
|
|
||||||
let requiredPriority: Float = 1000.0
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
if (layoutConstraint.priority < requiredPriority), (self.priority.constraintPriorityTargetValue != requiredPriority) {
|
if (layoutConstraint.priority < requiredPriority), (self.priority.constraintPriorityTargetValue != requiredPriority) {
|
||||||
layoutConstraint.priority = self.priority.constraintPriorityTargetValue
|
layoutConstraint.priority = self.priority.constraintPriorityTargetValue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal func activateIfNeeded(updatingExisting: Bool = false) {
|
internal func activateIfNeeded(updatingExisting: Bool = false) {
|
||||||
guard let item = self.from.layoutConstraintItem else {
|
guard let item = self.from.layoutConstraintItem else {
|
||||||
print("WARNING: SnapKit failed to get from item from constraint. Activate will be a no-op.")
|
print("WARNING: SnapKit failed to get from item from constraint. Activate will be a no-op.")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
let layoutConstraints = self.layoutConstraints
|
let layoutConstraints = self.layoutConstraints
|
||||||
|
|
||||||
if updatingExisting {
|
if updatingExisting {
|
||||||
var existingLayoutConstraints: [LayoutConstraint] = []
|
var existingLayoutConstraints: [LayoutConstraint] = []
|
||||||
for constraint in item.constraints {
|
for constraint in item.constraints {
|
||||||
existingLayoutConstraints += constraint.layoutConstraints
|
existingLayoutConstraints += constraint.layoutConstraints
|
||||||
}
|
}
|
||||||
|
|
||||||
for layoutConstraint in layoutConstraints {
|
for layoutConstraint in layoutConstraints {
|
||||||
let existingLayoutConstraint = existingLayoutConstraints.first { $0 == layoutConstraint }
|
let existingLayoutConstraint = existingLayoutConstraints.first { $0 == layoutConstraint }
|
||||||
guard let updateLayoutConstraint = existingLayoutConstraint else {
|
guard let updateLayoutConstraint = existingLayoutConstraint else {
|
||||||
fatalError("Updated constraint could not find existing matching constraint to update: \(layoutConstraint)")
|
fatalError("Updated constraint could not find existing matching constraint to update: \(layoutConstraint)")
|
||||||
}
|
}
|
||||||
|
|
||||||
let updateLayoutAttribute = (updateLayoutConstraint.secondAttribute == .notAnAttribute) ? updateLayoutConstraint.firstAttribute : updateLayoutConstraint.secondAttribute
|
let updateLayoutAttribute = (updateLayoutConstraint.secondAttribute == .notAnAttribute) ? updateLayoutConstraint.firstAttribute : updateLayoutConstraint.secondAttribute
|
||||||
updateLayoutConstraint.constant = self.constant.constraintConstantTargetValueFor(layoutAttribute: updateLayoutAttribute)
|
updateLayoutConstraint.constant = self.constant.constraintConstantTargetValueFor(layoutAttribute: updateLayoutAttribute)
|
||||||
}
|
}
|
||||||
|
@ -273,7 +276,7 @@ public final class Constraint {
|
||||||
item.add(constraints: [self])
|
item.add(constraints: [self])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal func deactivateIfNeeded() {
|
internal func deactivateIfNeeded() {
|
||||||
guard let item = self.from.layoutConstraintItem else {
|
guard let item = self.from.layoutConstraintItem else {
|
||||||
print("WARNING: SnapKit failed to get from item from constraint. Deactivate will be a no-op.")
|
print("WARNING: SnapKit failed to get from item from constraint. Deactivate will be a no-op.")
|
||||||
|
|
|
@ -109,6 +109,12 @@ public class ConstraintMakerExtendable: ConstraintMakerRelatable {
|
||||||
return self
|
return self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@available(iOS 8.0, *)
|
||||||
|
public var topMargin: ConstraintMakerExtendable {
|
||||||
|
self.description.attributes += .topMargin
|
||||||
|
return self
|
||||||
|
}
|
||||||
|
|
||||||
@available(iOS 8.0, *)
|
@available(iOS 8.0, *)
|
||||||
public var bottomMargin: ConstraintMakerExtendable {
|
public var bottomMargin: ConstraintMakerExtendable {
|
||||||
self.description.attributes += .bottomMargin
|
self.description.attributes += .bottomMargin
|
||||||
|
|
|
@ -30,38 +30,39 @@
|
||||||
|
|
||||||
public class ConstraintMakerPriortizable: ConstraintMakerFinalizable {
|
public class ConstraintMakerPriortizable: ConstraintMakerFinalizable {
|
||||||
|
|
||||||
|
@discardableResult
|
||||||
|
public func priority(_ amount: ConstraintPriority) -> ConstraintMakerFinalizable {
|
||||||
|
self.description.priority = amount.value
|
||||||
|
return self
|
||||||
|
}
|
||||||
|
|
||||||
@discardableResult
|
@discardableResult
|
||||||
public func priority(_ amount: ConstraintPriorityTarget) -> ConstraintMakerFinalizable {
|
public func priority(_ amount: ConstraintPriorityTarget) -> ConstraintMakerFinalizable {
|
||||||
self.description.priority = amount
|
self.description.priority = amount
|
||||||
return self
|
return self
|
||||||
}
|
}
|
||||||
|
|
||||||
@available(*, deprecated:3.0, message:"Use priority(_ amount: ConstraintPriorityTarget) instead.")
|
@available(*, deprecated:3.0, message:"Use priority(.required) instead.")
|
||||||
@discardableResult
|
@discardableResult
|
||||||
public func priorityRequired() -> ConstraintMakerFinalizable {
|
public func priorityRequired() -> ConstraintMakerFinalizable {
|
||||||
return self.priority(1000)
|
return self.priority(.required)
|
||||||
}
|
}
|
||||||
|
|
||||||
@available(*, deprecated:3.0, message:"Use priority(_ amount: ConstraintPriorityTarget) instead.")
|
@available(*, deprecated:3.0, message:"Use priority(.high) instead.")
|
||||||
@discardableResult
|
@discardableResult
|
||||||
public func priorityHigh() -> ConstraintMakerFinalizable {
|
public func priorityHigh() -> ConstraintMakerFinalizable {
|
||||||
return self.priority(750)
|
return self.priority(.high)
|
||||||
}
|
}
|
||||||
|
|
||||||
@available(*, deprecated:3.0, message:"Use priority(_ amount: ConstraintPriorityTarget) instead.")
|
@available(*, deprecated:3.0, message:"Use priority(.medium) instead.")
|
||||||
@discardableResult
|
@discardableResult
|
||||||
public func priorityMedium() -> ConstraintMakerFinalizable {
|
public func priorityMedium() -> ConstraintMakerFinalizable {
|
||||||
#if os(iOS) || os(tvOS)
|
return self.priority(.medium)
|
||||||
return self.priority(500)
|
|
||||||
#else
|
|
||||||
return self.priority(501)
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@available(*, deprecated:3.0, message:"Use priority(_ amount: ConstraintPriorityTarget) instead.")
|
@available(*, deprecated:3.0, message:"Use priority(.low) instead.")
|
||||||
@discardableResult
|
@discardableResult
|
||||||
public func priorityLow() -> ConstraintMakerFinalizable {
|
public func priorityLow() -> ConstraintMakerFinalizable {
|
||||||
return self.priority(250)
|
return self.priority(.low)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,68 @@
|
||||||
|
//
|
||||||
|
// SnapKit
|
||||||
|
//
|
||||||
|
// Copyright (c) 2011-Present SnapKit Team - https://github.com/SnapKit
|
||||||
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
|
// in the Software without restriction, including without limitation the rights
|
||||||
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
|
// furnished to do so, subject to the following conditions:
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be included in
|
||||||
|
// all copies or substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
// THE SOFTWARE.
|
||||||
|
|
||||||
|
#if os(iOS) || os(tvOS)
|
||||||
|
import UIKit
|
||||||
|
#else
|
||||||
|
import AppKit
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
public struct ConstraintPriority : ExpressibleByFloatLiteral, Equatable {
|
||||||
|
public typealias FloatLiteralType = Float
|
||||||
|
|
||||||
|
public let value: Float
|
||||||
|
|
||||||
|
public init(floatLiteral value: Float) {
|
||||||
|
self.value = value
|
||||||
|
}
|
||||||
|
|
||||||
|
public init(_ value: Float) {
|
||||||
|
self.value = value
|
||||||
|
}
|
||||||
|
|
||||||
|
public static var required: ConstraintPriority {
|
||||||
|
return 1000.0
|
||||||
|
}
|
||||||
|
|
||||||
|
public static var high: ConstraintPriority {
|
||||||
|
return 750.0
|
||||||
|
}
|
||||||
|
|
||||||
|
public static var medium: ConstraintPriority {
|
||||||
|
#if os(OSX)
|
||||||
|
return 501.0
|
||||||
|
#else
|
||||||
|
return 500.0
|
||||||
|
#endif
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static var low: ConstraintPriority {
|
||||||
|
return 250.0
|
||||||
|
}
|
||||||
|
|
||||||
|
public static func ==(lhs: ConstraintPriority, rhs: ConstraintPriority) -> Bool {
|
||||||
|
return lhs.value == rhs.value
|
||||||
|
}
|
||||||
|
}
|
|
@ -74,7 +74,7 @@ public struct ConstraintViewDSL: ConstraintAttributesDSL {
|
||||||
return self.view.contentCompressionResistancePriority(for: .horizontal)
|
return self.view.contentCompressionResistancePriority(for: .horizontal)
|
||||||
}
|
}
|
||||||
set {
|
set {
|
||||||
self.view.setContentHuggingPriority(newValue, for: .horizontal)
|
self.view.setContentCompressionResistancePriority(newValue, for: .horizontal)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -517,4 +517,27 @@ class SnapKitTests: XCTestCase {
|
||||||
self.container.snp.setLabel("Hello World")
|
self.container.snp.setLabel("Hello World")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testPriorityShortcuts() {
|
||||||
|
let view = View()
|
||||||
|
self.container.addSubview(view)
|
||||||
|
|
||||||
|
view.snp.remakeConstraints { make in
|
||||||
|
make.left.equalTo(1000.0).priority(.required)
|
||||||
|
}
|
||||||
|
XCTAssertEqual(self.container.snp_constraints.count, 1, "Should have 1 constraint")
|
||||||
|
XCTAssertEqual(self.container.snp_constraints.first?.priority, ConstraintPriority.required.value)
|
||||||
|
|
||||||
|
view.snp.remakeConstraints { make in
|
||||||
|
make.left.equalTo(1000.0).priority(.low)
|
||||||
|
}
|
||||||
|
XCTAssertEqual(self.container.snp_constraints.count, 1, "Should have 1 constraint")
|
||||||
|
XCTAssertEqual(self.container.snp_constraints.first?.priority, ConstraintPriority.low.value)
|
||||||
|
|
||||||
|
view.snp.remakeConstraints { make in
|
||||||
|
make.left.equalTo(1000.0).priority(ConstraintPriority.low.value + 1)
|
||||||
|
}
|
||||||
|
XCTAssertEqual(self.container.snp_constraints.count, 1, "Should have 1 constraint")
|
||||||
|
XCTAssertEqual(self.container.snp_constraints.first?.priority, ConstraintPriority.low.value + 1)
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue