@@ -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