mirror of https://github.com/SnapKit/SnapKit
Fix bug where pinning composite to composite would fail
This commit is contained in:
parent
9b1a0519ee
commit
cdedbcdea7
|
@ -82,7 +82,7 @@ public class Constraint {
|
|||
// get layout to attribute
|
||||
let layoutToAttribute: NSLayoutAttribute
|
||||
#if os(iOS) || os(tvOS)
|
||||
if layoutToAttributes.count > 1 {
|
||||
if layoutToAttributes.count > 0 {
|
||||
if self.from.attributes == .edges && self.to.attributes == .margins {
|
||||
switch layoutFromAttribute {
|
||||
case .left:
|
||||
|
@ -109,11 +109,11 @@ public class Constraint {
|
|||
default:
|
||||
fatalError()
|
||||
}
|
||||
} else if self.from.attributes == self.to.attributes {
|
||||
layoutToAttribute = layoutFromAttribute
|
||||
} else {
|
||||
layoutToAttribute = layoutToAttributes[0]
|
||||
}
|
||||
} else if layoutToAttributes.count == 1 {
|
||||
layoutToAttribute = layoutToAttributes[0]
|
||||
} else {
|
||||
layoutToAttribute = layoutFromAttribute
|
||||
}
|
||||
|
|
|
@ -441,6 +441,28 @@ class SnapKitTests: XCTestCase {
|
|||
|
||||
}
|
||||
|
||||
func testEdgesToEdges() {
|
||||
var fromAttributes = Set<NSLayoutAttribute>()
|
||||
var toAttributes = Set<NSLayoutAttribute>()
|
||||
|
||||
let view = View()
|
||||
self.container.addSubview(view)
|
||||
|
||||
view.snp.remakeConstraints { (make) -> Void in
|
||||
make.edges.equalTo(self.container.snp.edges)
|
||||
}
|
||||
|
||||
XCTAssertEqual(self.container.snp_constraints.count, 4, "Should have 4 constraints")
|
||||
|
||||
for constraint in (container.snp_constraints as! [NSLayoutConstraint]) {
|
||||
fromAttributes.insert(constraint.firstAttribute)
|
||||
toAttributes.insert(constraint.secondAttribute)
|
||||
}
|
||||
|
||||
XCTAssert(fromAttributes == [.top, .left, .bottom, .right])
|
||||
XCTAssert(toAttributes == [.top, .left, .bottom, .right])
|
||||
}
|
||||
|
||||
func testLayoutGuideConstraints() {
|
||||
let vc = UIViewController()
|
||||
vc.view = UIView(frame: CGRect(x: 0, y: 0, width: 300, height: 300))
|
||||
|
|
Loading…
Reference in New Issue