mirror of https://github.com/SnapKit/SnapKit
Fix incorrect behavior of inset with center and baseline anchors (#569)
* Fix insets adjusting center attributes incorrectly * Fix insets adjusting baseline attributes incorrectly
This commit is contained in:
parent
bc2b0b9332
commit
b3b64f61a7
|
@ -106,18 +106,22 @@ extension ConstraintConstantTarget {
|
||||||
if let value = self as? ConstraintInsets {
|
if let value = self as? ConstraintInsets {
|
||||||
#if os(iOS) || os(tvOS)
|
#if os(iOS) || os(tvOS)
|
||||||
switch layoutAttribute {
|
switch layoutAttribute {
|
||||||
case .left, .leftMargin, .centerX, .centerXWithinMargins:
|
case .left, .leftMargin:
|
||||||
return value.left
|
return value.left
|
||||||
case .top, .topMargin, .centerY, .centerYWithinMargins, .lastBaseline, .firstBaseline:
|
case .top, .topMargin, .firstBaseline:
|
||||||
return value.top
|
return value.top
|
||||||
case .right, .rightMargin:
|
case .right, .rightMargin:
|
||||||
return -value.right
|
return -value.right
|
||||||
case .bottom, .bottomMargin:
|
case .bottom, .bottomMargin, .lastBaseline:
|
||||||
return -value.bottom
|
return -value.bottom
|
||||||
case .leading, .leadingMargin:
|
case .leading, .leadingMargin:
|
||||||
return (ConstraintConfig.interfaceLayoutDirection == .leftToRight) ? value.left : value.right
|
return (ConstraintConfig.interfaceLayoutDirection == .leftToRight) ? value.left : value.right
|
||||||
case .trailing, .trailingMargin:
|
case .trailing, .trailingMargin:
|
||||||
return (ConstraintConfig.interfaceLayoutDirection == .leftToRight) ? -value.right : -value.left
|
return (ConstraintConfig.interfaceLayoutDirection == .leftToRight) ? -value.right : -value.left
|
||||||
|
case .centerX, .centerXWithinMargins:
|
||||||
|
return (value.left - value.right) / 2
|
||||||
|
case .centerY, .centerYWithinMargins:
|
||||||
|
return (value.top - value.bottom) / 2
|
||||||
case .width:
|
case .width:
|
||||||
return -(value.left + value.right)
|
return -(value.left + value.right)
|
||||||
case .height:
|
case .height:
|
||||||
|
@ -131,18 +135,22 @@ extension ConstraintConstantTarget {
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
switch layoutAttribute {
|
switch layoutAttribute {
|
||||||
case .left, .centerX:
|
case .left:
|
||||||
return value.left
|
return value.left
|
||||||
case .top, .centerY, .lastBaseline, .firstBaseline:
|
case .top, .firstBaseline:
|
||||||
return value.top
|
return value.top
|
||||||
case .right:
|
case .right:
|
||||||
return -value.right
|
return -value.right
|
||||||
case .bottom:
|
case .bottom, .lastBaseline:
|
||||||
return -value.bottom
|
return -value.bottom
|
||||||
case .leading:
|
case .leading:
|
||||||
return (ConstraintConfig.interfaceLayoutDirection == .leftToRight) ? value.left : value.right
|
return (ConstraintConfig.interfaceLayoutDirection == .leftToRight) ? value.left : value.right
|
||||||
case .trailing:
|
case .trailing:
|
||||||
return (ConstraintConfig.interfaceLayoutDirection == .leftToRight) ? -value.right : -value.left
|
return (ConstraintConfig.interfaceLayoutDirection == .leftToRight) ? -value.right : -value.left
|
||||||
|
case .centerX:
|
||||||
|
return (value.left - value.right) / 2
|
||||||
|
case .centerY:
|
||||||
|
return (value.top - value.bottom) / 2
|
||||||
case .width:
|
case .width:
|
||||||
return -(value.left + value.right)
|
return -(value.left + value.right)
|
||||||
case .height:
|
case .height:
|
||||||
|
|
Loading…
Reference in New Issue