Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed rightToLeft languages's problem #108

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 17 additions & 34 deletions TinyConstraints/Classes/TinyConstraints+superview.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,24 +65,20 @@
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(.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(.left)) {
constraints.append(leftToSuperview(offset: insets.left, relation: relation, priority: priority, isActive: isActive, usingSafeArea: usingSafeArea))
}
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) {
Expand All @@ -98,11 +94,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, *)
Expand All @@ -111,11 +103,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, *)
Expand All @@ -125,13 +113,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
}
Expand Down