Преглед на файлове

Fix bug where pinning composite to composite would fail

Robert Payne преди 9 години
родител
ревизия
cdedbcdea7
променени са 2 файла, в които са добавени 25 реда и са изтрити 3 реда
  1. 3 3
      Source/Constraint.swift
  2. 22 0
      Tests/Tests.swift

+ 3 - 3
Source/Constraint.swift

@@ -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
                 }

+ 22 - 0
Tests/Tests.swift

@@ -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))