@@ -594,43 +594,26 @@ class PinLayoutImpl: PinLayout {
594
594
//
595
595
@discardableResult
596
596
func size( _ size: CGSize ) -> PinLayout {
597
- if isSizeNotSet ( { return " size(CGSize(width: \( size. width) , height: \( size. height) )) " } ) {
598
- width ( size. width)
599
- height ( size. height)
600
- }
601
- return self
597
+ return setSize ( size, { return " size(CGSize(width: \( size. width) , height: \( size. height) )) " } )
602
598
}
603
599
604
600
@discardableResult
605
601
func size( _ sideLength: CGFloat ) -> PinLayout {
606
- if isSizeNotSet ( { return " size(sideLength: \( sideLength) ) " } ) {
607
- width ( sideLength)
608
- height ( sideLength)
609
- }
610
- return self
602
+ return setSize ( CGSize ( width: sideLength, height: sideLength) , { return " size(sideLength: \( sideLength) ) " } )
611
603
}
612
604
613
605
@discardableResult
614
606
func size( _ percent: Percent ) -> PinLayout {
615
607
func context( ) -> String { return " size( \( percent) ) " }
616
- if isSizeNotSet ( context) {
617
- guard let layoutSuperview = layoutSuperview ( context) else { return self }
618
- setWidth ( percent. of ( layoutSuperview. frame. width) , context)
619
- setHeight ( percent. of ( layoutSuperview. frame. height) , context)
620
- }
621
- return self
608
+ guard let layoutSuperview = layoutSuperview ( context) else { return self }
609
+ let size = CGSize ( width: percent. of ( layoutSuperview. frame. width) , height: percent. of ( layoutSuperview. frame. height) )
610
+ return setSize ( size, context)
622
611
}
623
612
624
613
@discardableResult
625
614
func size( of view: UIView ) -> PinLayout {
626
615
func context( ) -> String { return " size(of \( view) ) " }
627
- let viewSize = view. frame. size
628
-
629
- if isSizeNotSet ( context) {
630
- setWidth ( viewSize. width, context)
631
- setHeight ( viewSize. height, context)
632
- }
633
- return self
616
+ return setSize ( view. frame. size, context)
634
617
}
635
618
636
619
@discardableResult
@@ -867,7 +850,7 @@ extension PinLayoutImpl {
867
850
868
851
if let _left = _left, let _right = _right {
869
852
warnConflict ( context, [ " left " : _left, " right " : _right] )
870
- } else if let width = width {
853
+ } else if let width = width, width != value {
871
854
warnPropertyAlreadySet ( " width " , propertyValue: width, context)
872
855
} else {
873
856
width = value
@@ -883,27 +866,18 @@ extension PinLayoutImpl {
883
866
884
867
if let _top = _top, let _bottom = _bottom {
885
868
warnConflict ( context, [ " top " : _top, " bottom " : _bottom] )
886
- } else if let height = height {
869
+ } else if let height = height, height != value {
887
870
warnPropertyAlreadySet ( " height " , propertyValue: height, context)
888
871
} else {
889
872
height = value
890
873
}
891
874
return self
892
875
}
893
876
894
- fileprivate func isSizeNotSet( _ context: Context ) -> Bool {
895
- if let _top = _top, let _bottom = _bottom {
896
- warnConflict ( context, [ " top " : _top, " bottom " : _bottom] )
897
- return false
898
- } else if let height = height {
899
- warnConflict ( context, [ " height " : height] )
900
- return false
901
- } else if let width = width {
902
- warnConflict ( context, [ " width " : width] )
903
- return false
904
- } else {
905
- return true
906
- }
877
+ fileprivate func setSize( _ size: CGSize , _ context: Context ) -> PinLayout {
878
+ setWidth ( size. width, { return " \( context ( ) ) 's width " } )
879
+ setHeight ( size. height, { return " \( context ( ) ) 's height " } )
880
+ return self
907
881
}
908
882
909
883
fileprivate func computeCoordinates( _ point: CGPoint , _ layoutSuperview: UIView , _ referenceView: UIView , _ referenceSuperview: UIView ) -> CGPoint {
0 commit comments