Skip to content

Commit

Permalink
Add right to left support
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrei Rychkov committed Dec 26, 2016
1 parent 6181a75 commit 1f6d0c0
Showing 1 changed file with 76 additions and 0 deletions.
76 changes: 76 additions & 0 deletions Source/Neon.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,18 @@
#endif


// MARK: Right to left support
//
///
fileprivate var isRightToLeft: Bool {
#if os(iOS)
return UIApplication.shared.userInterfaceLayoutDirection == .rightToLeft
#else
return NSApplication.shared().userInterfaceLayoutDirection == .rightToLeft
#endif
}


// MARK: AutoHeight
//
///
Expand Down Expand Up @@ -41,6 +53,22 @@ public enum Corner {
case topRight
case bottomLeft
case bottomRight

public static var topLeading: Corner {
return isRightToLeft ? .topRight : .topLeft
}

public static var topTrailing: Corner {
return isRightToLeft ? .topLeft : .topRight
}

public static var bottomLeading: Corner {
return isRightToLeft ? .bottomRight : .bottomLeft
}

public static var bottomTrailing: Corner {
return isRightToLeft ? .bottomLeft : .bottomRight
}
}


Expand All @@ -62,6 +90,14 @@ public enum Edge {
case left
case bottom
case right

public static var leading: Edge {
return isRightToLeft ? .right : .left
}

public static var trailing: Edge {
return isRightToLeft ? .left : .right
}
}


Expand Down Expand Up @@ -121,6 +157,46 @@ public enum Align {
case aboveMatchingLeft
case aboveMatchingRight
case aboveCentered

public static var toTheLeadingMatchingTop: Align {
return isRightToLeft ? .toTheRightMatchingTop : .toTheLeftMatchingTop
}

public static var toTheTrailingMatchingTop: Align {
return isRightToLeft ? .toTheLeftMatchingTop : .toTheRightMatchingTop
}

public static var toTheLeadingMatchingBottom: Align {
return isRightToLeft ? .toTheRightMatchingBottom : .toTheLeftMatchingBottom
}

public static var toTheTrailingMatchingBottom: Align {
return isRightToLeft ? .toTheLeftMatchingBottom : .toTheRightMatchingBottom
}

public static var toTheLeadingCentered: Align {
return isRightToLeft ? .toTheRightCentered : .toTheLeftCentered
}

public static var toTheTrailingCentered: Align {
return isRightToLeft ? .toTheLeftCentered : .toTheRightCentered
}

public static var underMatchingLeading: Align {
return isRightToLeft ? .underMatchingRight : .underMatchingLeft
}

public static var underMatchingTrailing: Align {
return isRightToLeft ? .underMatchingLeft : .underMatchingRight
}

public static var aboveMatchingLeading: Align {
return isRightToLeft ? .aboveMatchingRight : .aboveMatchingLeft
}

public static var aboveMatchingTrailing: Align {
return isRightToLeft ? .aboveMatchingLeft : .aboveMatchingRight
}
}


Expand Down

0 comments on commit 1f6d0c0

Please sign in to comment.