Skip to content

Commit 8d31b02

Browse files
authored
Adds accessibility identifier, and UIAccessibility trait set to be staticText (#15)
Refactor code to use _accessibilityTraits instead of overriding accessor
1 parent 42742d0 commit 8d31b02

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

DemoApp/DemoApp.xcodeproj/project.pbxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@
139139
3B21D4862785F3EF0009DE6A /* PBXTargetDependency */,
140140
);
141141
name = LCLabelUITests;
142+
packageProductDependencies = (
143+
);
142144
productName = LCLabelUITests;
143145
productReference = 3B21D47F2785F3EF0009DE6A /* LCLabelUITests.xctest */;
144146
productType = "com.apple.product-type.bundle.ui-testing";

DemoApp/LCLabelUITests/LCLabelHitTests.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ final class LCLabelHitTests: XCTestCase {
1818
app = XCUIApplication()
1919
app.launchArguments = [""]
2020
app.launch()
21+
22+
XCTAssertEqual(
23+
app.staticTexts.matching(.staticText, identifier: "lcllabel+1").firstMatch.identifier,
24+
"lcllabel+1")
25+
2126
let main = app.otherElements["main"]
2227
XCTAssertTrue(main.exists)
2328
XCTAssertTrue(main.staticTexts["translator"].exists)

Sources/LCLabel/LCLabel.swift

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,16 @@ final public class LCLabel: UIView {
5050
}
5151

5252
// MARK: - Variables
53+
54+
public override var accessibilityTraits: UIAccessibilityTraits {
55+
get {
56+
_accessibilityTraits
57+
}
58+
set {
59+
_accessibilityTraits = newValue
60+
}
61+
}
62+
5363
/// A LCLabel delegate that responses to link interactions within
5464
/// the view
5565
public weak var delegate: LCLabelDelegate?
@@ -126,6 +136,7 @@ final public class LCLabel: UIView {
126136
renderedStorage = nil
127137
isHidden = true
128138
}
139+
accessibilityIdentifier = newValue?.string
129140
setupRenderStorage()
130141
refreshView()
131142
}
@@ -143,14 +154,16 @@ final public class LCLabel: UIView {
143154
}()
144155

145156
private var currentlySelectedLink: URL?
157+
private var _accessibilityTraits: UIAccessibilityTraits
146158

147159
// MARK: - Life Cycle
148160

149-
public init() {
150-
super.init(frame: .zero)
161+
public convenience init() {
162+
self.init(frame: .zero)
151163
}
152164

153165
public override init(frame: CGRect) {
166+
_accessibilityTraits = .staticText
154167
super.init(frame: frame)
155168
}
156169

0 commit comments

Comments
 (0)