Skip to content

Commit

Permalink
Adds accessibility identifier, and UIAccessibility trait set to be st…
Browse files Browse the repository at this point in the history
…aticText (#15)

Refactor code to use _accessibilityTraits instead of overriding accessor
  • Loading branch information
mustiikhalil committed May 4, 2022
1 parent 42742d0 commit 8d31b02
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
2 changes: 2 additions & 0 deletions DemoApp/DemoApp.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@
3B21D4862785F3EF0009DE6A /* PBXTargetDependency */,
);
name = LCLabelUITests;
packageProductDependencies = (
);
productName = LCLabelUITests;
productReference = 3B21D47F2785F3EF0009DE6A /* LCLabelUITests.xctest */;
productType = "com.apple.product-type.bundle.ui-testing";
Expand Down
5 changes: 5 additions & 0 deletions DemoApp/LCLabelUITests/LCLabelHitTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ final class LCLabelHitTests: XCTestCase {
app = XCUIApplication()
app.launchArguments = [""]
app.launch()

XCTAssertEqual(
app.staticTexts.matching(.staticText, identifier: "lcllabel+1").firstMatch.identifier,
"lcllabel+1")

let main = app.otherElements["main"]
XCTAssertTrue(main.exists)
XCTAssertTrue(main.staticTexts["translator"].exists)
Expand Down
17 changes: 15 additions & 2 deletions Sources/LCLabel/LCLabel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,16 @@ final public class LCLabel: UIView {
}

// MARK: - Variables

public override var accessibilityTraits: UIAccessibilityTraits {
get {
_accessibilityTraits
}
set {
_accessibilityTraits = newValue
}
}

/// A LCLabel delegate that responses to link interactions within
/// the view
public weak var delegate: LCLabelDelegate?
Expand Down Expand Up @@ -126,6 +136,7 @@ final public class LCLabel: UIView {
renderedStorage = nil
isHidden = true
}
accessibilityIdentifier = newValue?.string
setupRenderStorage()
refreshView()
}
Expand All @@ -143,14 +154,16 @@ final public class LCLabel: UIView {
}()

private var currentlySelectedLink: URL?
private var _accessibilityTraits: UIAccessibilityTraits

// MARK: - Life Cycle

public init() {
super.init(frame: .zero)
public convenience init() {
self.init(frame: .zero)
}

public override init(frame: CGRect) {
_accessibilityTraits = .staticText
super.init(frame: frame)
}

Expand Down

0 comments on commit 8d31b02

Please sign in to comment.