mirror of https://github.com/SnapKit/SnapKit
Merge branch 'develop' of github.com:SnapKit/SnapKit into develop
This commit is contained in:
commit
77e7ca4084
|
@ -57,6 +57,8 @@ public class Constraint {
|
|||
public func updatePriorityHigh() -> Void { fatalError("Must be implemented by Concrete subclass.") }
|
||||
public func updatePriorityMedium() -> Void { fatalError("Must be implemented by Concrete subclass.") }
|
||||
public func updatePriorityLow() -> Void { fatalError("Must be implemented by Concrete subclass.") }
|
||||
|
||||
public var layoutConstraints: [LayoutConstraint] { fatalError("Must be implemented by Concrete subclass.") }
|
||||
|
||||
internal var makerFile: String = "Unknown"
|
||||
internal var makerLine: UInt = 0
|
||||
|
@ -197,6 +199,17 @@ internal class ConcreteConstraint: Constraint {
|
|||
|
||||
private var installInfo: ConcreteConstraintInstallInfo? = nil
|
||||
|
||||
override var layoutConstraints: [LayoutConstraint] {
|
||||
if installInfo == nil {
|
||||
install()
|
||||
}
|
||||
|
||||
guard let installInfo = installInfo else {
|
||||
return []
|
||||
}
|
||||
return installInfo.layoutConstraints.allObjects as! [LayoutConstraint]
|
||||
}
|
||||
|
||||
internal init(fromItem: ConstraintItem, toItem: ConstraintItem, relation: ConstraintRelation, constant: Any, multiplier: Float, priority: Float, label: String? = nil) {
|
||||
self.fromItem = fromItem
|
||||
self.toItem = toItem
|
||||
|
|
|
@ -291,4 +291,27 @@ class SnapKitTests: XCTestCase {
|
|||
XCTAssertEqual(constraints[0].constant, 10, "Should be 10")
|
||||
XCTAssertEqual(constraints[1].constant, -10, "Should be 10")
|
||||
}
|
||||
|
||||
func testNativeConstraints() {
|
||||
let view = View()
|
||||
|
||||
container.addSubview(view)
|
||||
|
||||
var topNativeConstraints: [LayoutConstraint]!
|
||||
var topNativeConstraint: LayoutConstraint?
|
||||
var sizeNativeConstraints: [LayoutConstraint]!
|
||||
view.snp_makeConstraints { (make) -> Void in
|
||||
let topConstraint = make.top.equalToSuperview().inset(10).constraint
|
||||
topNativeConstraints = topConstraint.layoutConstraints
|
||||
topNativeConstraint = topConstraint.layoutConstraints.first
|
||||
let sizeConstraints = make.size.equalTo(50).constraint
|
||||
sizeNativeConstraints = sizeConstraints.layoutConstraints
|
||||
}
|
||||
|
||||
XCTAssertEqual(topNativeConstraints.count, 1, "make.top should creates one native constraint")
|
||||
XCTAssertEqual(topNativeConstraint?.constant, 10, "topNativeConstraint.constant is set to 10")
|
||||
XCTAssertEqual(sizeNativeConstraints.count, 2, "make.tosize should create two native constraint")
|
||||
XCTAssertEqual(sizeNativeConstraints[0].constant, 50, "sizeNativeConstraints should set size[0] to 50")
|
||||
XCTAssertEqual(sizeNativeConstraints[1].constant, 50, "sizeNativeConstraints should set size[1] to 50")
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue