I think a little bit about that.
As a basis idea we can take AutoLayout approach:
.leading means .left on left-to-right languages and means .right on right-to-left languages;
.trailing means .right on left-to-right languages and means .left on right-to-left languages.
We can implement this by simple adding factory functions to our enums(Edge, Corner, Align), for example for Edge:
public enum Edge {
case top
case left
case bottom
case right
static func leading() -> Edge {
return isRightToLeft() ? .right : .left
}
static func trailing() -> Edge {
return isRightToLeft() ? .left : .right
}
}
Then if client code wants to respect language direction, it should use .leading() and .trailing() functions instead .left and .right:
func isRightToLeft() -> Bool {
// return UIApplication.shared.userInterfaceLayoutDirection == .rightToLeft
return true
}
func bar(edge: Edge) {
switch edge {
case .left:
print("left")
case .right:
print("right")
case .top:
print("top")
case .bottom:
print("bottom")
}
}
bar(edge: .leading()) // prints 'right'
@mamaral what you think about this approach? Any suggestions?
I think a little bit about that.
As a basis idea we can take AutoLayout approach:
.leadingmeans.lefton left-to-right languages and means.righton right-to-left languages;.trailingmeans.righton left-to-right languages and means.lefton right-to-left languages.We can implement this by simple adding factory functions to our enums(Edge, Corner, Align), for example for
Edge:Then if client code wants to respect language direction, it should use .leading() and .trailing() functions instead .left and .right:
@mamaral what you think about this approach? Any suggestions?