Skip to content

Commit 71436b8

Browse files
committed
Cleanup: NSTextAlignment.
1 parent 830e492 commit 71436b8

File tree

2 files changed

+35
-5
lines changed

2 files changed

+35
-5
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//=----------------------------------------------------------------------------=
2+
// This source file is part of the DiffableTextViews open source project.
3+
//
4+
// Copyright (c) 2022 Oscar Byström Ericsson
5+
// Licensed under Apache License, Version 2.0
6+
//
7+
// See http://www.apache.org/licenses/LICENSE-2.0 for license information.
8+
//=----------------------------------------------------------------------------=
9+
10+
#if canImport(UIKit)
11+
12+
import SwiftUI
13+
import UIKit
14+
15+
//*============================================================================*
16+
// MARK: * NSTextAlignment
17+
//*============================================================================*
18+
19+
extension NSTextAlignment {
20+
21+
//=------------------------------------------------------------------------=
22+
// MARK: Initializers
23+
//=------------------------------------------------------------------------=
24+
25+
@inlinable init(_ alignment: TextAlignment, for layout: UIUserInterfaceLayoutDirection) {
26+
switch alignment {
27+
case .leading: self = (layout == .leftToRight) ? .left : .right
28+
case .trailing: self = (layout == .leftToRight) ? .right : .left
29+
case .center: self = .center
30+
}
31+
}
32+
}
33+
34+
#endif

Sources/DiffableTextViewsXiOS/Models/Alignment.swift renamed to Sources/DiffableTextViewsXiOS/Helpers/&UITextField.swift

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,7 @@ extension UITextField {
2727
}
2828

2929
@inlinable func setTextAlignment(_ newValue: TextAlignment) {
30-
switch newValue {
31-
case .leading: textAlignment = (userInterfaceLayoutDirection == .leftToRight) ? .left : .right
32-
case .trailing: textAlignment = (userInterfaceLayoutDirection == .leftToRight) ? .right : .left
33-
case .center: textAlignment = .center
34-
}
30+
self.textAlignment = NSTextAlignment(newValue, for: userInterfaceLayoutDirection)
3531
}
3632
}
3733

0 commit comments

Comments
 (0)