From ba266ae7a923aaa8e8a7006575afd2422afba75e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Volkan=20So=CC=88nmez?= Date: Wed, 17 May 2023 00:05:19 +0300 Subject: [PATCH 1/2] Fixed rightToLeft --- .../Classes/TinyConstraints+superview.swift | 43 ++++--------------- 1 file changed, 9 insertions(+), 34 deletions(-) diff --git a/TinyConstraints/Classes/TinyConstraints+superview.swift b/TinyConstraints/Classes/TinyConstraints+superview.swift index 4241689..f626ff3 100644 --- a/TinyConstraints/Classes/TinyConstraints+superview.swift +++ b/TinyConstraints/Classes/TinyConstraints+superview.swift @@ -65,24 +65,12 @@ constraints.append(topToSuperview(offset: insets.top, relation: relation, priority: priority, isActive: isActive, usingSafeArea: usingSafeArea)) } - if effectiveUserInterfaceLayoutDirection == .leftToRight { - - if !(excludedEdge.contains(.leading) || excludedEdge.contains(.left)) { - constraints.append(leftToSuperview(offset: insets.left, relation: relation, priority: priority, isActive: isActive, usingSafeArea: usingSafeArea)) - } - - if !(excludedEdge.contains(.trailing) || excludedEdge.contains(.right)) { - constraints.append(rightToSuperview(offset: -insets.right, relation: relation, priority: priority, isActive: isActive, usingSafeArea: usingSafeArea)) - } - } else { - - if !(excludedEdge.contains(.leading) || excludedEdge.contains(.right)) { - constraints.append(rightToSuperview(offset: -insets.right, relation: relation, priority: priority, isActive: isActive, usingSafeArea: usingSafeArea)) - } + if !(excludedEdge.contains(.leading) || excludedEdge.contains(.left)) { + constraints.append(leadingToSuperview(offset: insets.left, relation: relation, priority: priority, isActive: isActive, usingSafeArea: usingSafeArea)) + } - if !(excludedEdge.contains(.trailing) || excludedEdge.contains(.left)) { - constraints.append(leftToSuperview(offset: insets.left, relation: relation, priority: priority, isActive: isActive, usingSafeArea: usingSafeArea)) - } + if !(excludedEdge.contains(.trailing) || excludedEdge.contains(.right)) { + constraints.append(trailingToSuperview(offset: insets.right, relation: relation, priority: priority, isActive: isActive, usingSafeArea: usingSafeArea)) } if !excludedEdge.contains(.bottom) { @@ -98,11 +86,7 @@ func leadingToSuperview( _ anchor: NSLayoutXAxisAnchor? = nil, offset: CGFloat = 0, relation: ConstraintRelation = .equal, priority: LayoutPriority = .required, isActive: Bool = true, usingSafeArea: Bool = false) -> Constraint { let constrainable = safeConstrainable(for: superview, usingSafeArea: usingSafeArea) - if effectiveUserInterfaceLayoutDirection == .rightToLeft { - return leading(to: constrainable, anchor, offset: -offset, relation: relation, priority: priority, isActive: isActive) - } else { - return leading(to: constrainable, anchor, offset: offset, relation: relation, priority: priority, isActive: isActive) - } + return leading(to: constrainable, anchor, offset: offset, relation: relation, priority: priority, isActive: isActive) } @available(tvOS 10.0, *) @@ -111,11 +95,7 @@ func trailingToSuperview( _ anchor: NSLayoutXAxisAnchor? = nil, offset: CGFloat = 0, relation: ConstraintRelation = .equal, priority: LayoutPriority = .required, isActive: Bool = true, usingSafeArea: Bool = false) -> Constraint { let constrainable = safeConstrainable(for: superview, usingSafeArea: usingSafeArea) - if effectiveUserInterfaceLayoutDirection == .rightToLeft { - return trailing(to: constrainable, anchor, offset: offset, relation: relation, priority: priority, isActive: isActive) - } else { - return trailing(to: constrainable, anchor, offset: -offset, relation: relation, priority: priority, isActive: isActive) - } + return trailing(to: constrainable, anchor, offset: -offset, relation: relation, priority: priority, isActive: isActive) } @available(tvOS 10.0, *) @@ -125,13 +105,8 @@ var constraints = Constraints() - if effectiveUserInterfaceLayoutDirection == .leftToRight { - constraints.append(leftToSuperview(offset: insets.left, relation: relation, priority: priority, isActive: isActive, usingSafeArea: usingSafeArea)) - constraints.append(rightToSuperview(offset: -insets.right, relation: relation, priority: priority, isActive: isActive, usingSafeArea: usingSafeArea)) - } else { - constraints.append(rightToSuperview(offset: -insets.right, relation: relation, priority: priority, isActive: isActive, usingSafeArea: usingSafeArea)) - constraints.append(leftToSuperview(offset: insets.left, relation: relation, priority: priority, isActive: isActive, usingSafeArea: usingSafeArea)) - } + constraints.append(leadingToSuperview(offset: insets.left, relation: relation, priority: priority, isActive: isActive, usingSafeArea: usingSafeArea)) + constraints.append(trailingToSuperview(offset: insets.right, relation: relation, priority: priority, isActive: isActive, usingSafeArea: usingSafeArea)) return constraints } From 812f48f519e45c7a39ebdfcb6951be542a0e15cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Volkan=20So=CC=88nmez?= Date: Tue, 7 Nov 2023 19:54:40 +0300 Subject: [PATCH 2/2] Left & Right error fixed --- .../Classes/TinyConstraints+superview.swift | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/TinyConstraints/Classes/TinyConstraints+superview.swift b/TinyConstraints/Classes/TinyConstraints+superview.swift index f626ff3..f6c9193 100644 --- a/TinyConstraints/Classes/TinyConstraints+superview.swift +++ b/TinyConstraints/Classes/TinyConstraints+superview.swift @@ -65,14 +65,22 @@ constraints.append(topToSuperview(offset: insets.top, relation: relation, priority: priority, isActive: isActive, usingSafeArea: usingSafeArea)) } - if !(excludedEdge.contains(.leading) || excludedEdge.contains(.left)) { + if !excludedEdge.contains(.left) { + constraints.append(leftToSuperview(offset: insets.left, relation: relation, priority: priority, isActive: isActive, usingSafeArea: usingSafeArea)) + } + + if !excludedEdge.contains(.leading) { constraints.append(leadingToSuperview(offset: insets.left, relation: relation, priority: priority, isActive: isActive, usingSafeArea: usingSafeArea)) } - if !(excludedEdge.contains(.trailing) || excludedEdge.contains(.right)) { + if !excludedEdge.contains(.trailing) { constraints.append(trailingToSuperview(offset: insets.right, relation: relation, priority: priority, isActive: isActive, usingSafeArea: usingSafeArea)) } + if !excludedEdge.contains(.right) { + constraints.append(rightToSuperview(offset: insets.right, relation: relation, priority: priority, isActive: isActive, usingSafeArea: usingSafeArea)) + } + if !excludedEdge.contains(.bottom) { constraints.append(bottomToSuperview(offset: -insets.bottom, relation: relation, priority: priority, isActive: isActive, usingSafeArea: usingSafeArea)) }