From 8d31b02642fc2fd1af5b4bce042c9e8812e5b8a9 Mon Sep 17 00:00:00 2001 From: mustiikhalil <26250654+mustiikhalil@users.noreply.github.com> Date: Wed, 4 May 2022 21:46:19 +0200 Subject: [PATCH] Adds accessibility identifier, and UIAccessibility trait set to be staticText (#15) Refactor code to use _accessibilityTraits instead of overriding accessor --- DemoApp/DemoApp.xcodeproj/project.pbxproj | 2 ++ DemoApp/LCLabelUITests/LCLabelHitTests.swift | 5 +++++ Sources/LCLabel/LCLabel.swift | 17 +++++++++++++++-- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/DemoApp/DemoApp.xcodeproj/project.pbxproj b/DemoApp/DemoApp.xcodeproj/project.pbxproj index 52117f8..b5d3b32 100644 --- a/DemoApp/DemoApp.xcodeproj/project.pbxproj +++ b/DemoApp/DemoApp.xcodeproj/project.pbxproj @@ -139,6 +139,8 @@ 3B21D4862785F3EF0009DE6A /* PBXTargetDependency */, ); name = LCLabelUITests; + packageProductDependencies = ( + ); productName = LCLabelUITests; productReference = 3B21D47F2785F3EF0009DE6A /* LCLabelUITests.xctest */; productType = "com.apple.product-type.bundle.ui-testing"; diff --git a/DemoApp/LCLabelUITests/LCLabelHitTests.swift b/DemoApp/LCLabelUITests/LCLabelHitTests.swift index e0085e5..e04e25d 100644 --- a/DemoApp/LCLabelUITests/LCLabelHitTests.swift +++ b/DemoApp/LCLabelUITests/LCLabelHitTests.swift @@ -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) diff --git a/Sources/LCLabel/LCLabel.swift b/Sources/LCLabel/LCLabel.swift index 6d1f67d..f1bcc4d 100644 --- a/Sources/LCLabel/LCLabel.swift +++ b/Sources/LCLabel/LCLabel.swift @@ -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? @@ -126,6 +136,7 @@ final public class LCLabel: UIView { renderedStorage = nil isHidden = true } + accessibilityIdentifier = newValue?.string setupRenderStorage() refreshView() } @@ -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) }