Skip to content

Commit 3b1c67c

Browse files
committed
Cleanup: NSTextAlignment.
1 parent 67ca063 commit 3b1c67c

File tree

1 file changed

+9
-16
lines changed

1 file changed

+9
-16
lines changed

Sources/DiffableTextViewsXiOS/Helpers/&NSTextAlignment.swift

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,29 +24,22 @@ extension NSTextAlignment {
2424

2525
@inlinable init(_ alignment: TextAlignment, for layout: UIUserInterfaceLayoutDirection) {
2626
switch alignment {
27-
case .leading: self = .leading(for: layout)
28-
case .trailing: self = .trailing(for: layout)
29-
case .center: self = .center
27+
case .leading: self = .adaptive(layout, lr: .left, rl: .right)
28+
case .trailing: self = .adaptive(layout, lr: .right, rl: .left)
29+
case .center: self = .center
3030
}
3131
}
3232

3333
//=------------------------------------------------------------------------=
34-
// MARK: Initializers - Static
34+
// MARK: Initializers - Helpers
3535
//=------------------------------------------------------------------------=
3636

37-
@inlinable static func leading(for layout: UIUserInterfaceLayoutDirection) -> Self {
37+
@inlinable static func adaptive(_ layout: UIUserInterfaceLayoutDirection,
38+
lr: @autoclosure () -> Self, rl: @autoclosure () -> Self) -> Self {
3839
switch layout {
39-
case .leftToRight: return .left
40-
case .rightToLeft: return .right
41-
@unknown default: return .left
42-
}
43-
}
44-
45-
@inlinable static func trailing(for layout: UIUserInterfaceLayoutDirection) -> Self {
46-
switch layout {
47-
case .leftToRight: return .right
48-
case .rightToLeft: return .left
49-
@unknown default: return .right
40+
case .rightToLeft: return rl()
41+
case .leftToRight: return lr()
42+
@unknown default: return lr()
5043
}
5144
}
5245
}

0 commit comments

Comments
 (0)