From c6be63ff0b9cb47642f3be0277e939521b058f62 Mon Sep 17 00:00:00 2001 From: Daniel Tes Date: Thu, 7 Apr 2022 15:17:31 -0300 Subject: [PATCH] fix: Accessibility trait config in applyAccessibility (#41) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: Accessibility trait config in applyAccessibility Signed-off-by: Daniel Tes Carrasque * fix license header Signed-off-by: Daniel Tes Carrasque Co-authored-by: Tiago Peres França --- .../Renderer/ViewConfiguratorTests.swift | 21 +++++++++++++++++++ .../Sources/Renderer/ViewConfigurator.swift | 6 +++--- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/Sources/Beagle/BeagleTests/Renderer/ViewConfiguratorTests.swift b/Sources/Beagle/BeagleTests/Renderer/ViewConfiguratorTests.swift index be34219..f06af39 100644 --- a/Sources/Beagle/BeagleTests/Renderer/ViewConfiguratorTests.swift +++ b/Sources/Beagle/BeagleTests/Renderer/ViewConfiguratorTests.swift @@ -66,4 +66,25 @@ class ViewConfiguratorTests: XCTestCase { XCTAssertNotEqual(view.layer.borderWidth, CGFloat(borderWidthValue)) XCTAssertNotEqual(view.layer.borderColor, UIColor(hex: borderColorHex)?.cgColor) } + + func testApplyAccessibility() { + // Given + let button = UIButton() + button.accessibilityTraits = .button + let buttonHeader = UIButton() + var accessibility = Accessibility(accessibilityLabel: "accessibilityLabel", accessible: true) + + // When + ViewConfigurator.applyAccessibility(accessibility, to: button) + accessibility.isHeader = true + ViewConfigurator.applyAccessibility(accessibility, to: buttonHeader) + + // Then + XCTAssertEqual(button.accessibilityLabel, accessibility.accessibilityLabel) + XCTAssertTrue(button.isAccessibilityElement) + XCTAssertEqual(button.accessibilityTraits, .button) + XCTAssertEqual(buttonHeader.accessibilityLabel, accessibility.accessibilityLabel) + XCTAssertTrue(buttonHeader.isAccessibilityElement) + XCTAssertEqual(buttonHeader.accessibilityTraits, .header) + } } diff --git a/Sources/Beagle/Sources/Renderer/ViewConfigurator.swift b/Sources/Beagle/Sources/Renderer/ViewConfigurator.swift index 4a4abf5..2faa4a3 100644 --- a/Sources/Beagle/Sources/Renderer/ViewConfigurator.swift +++ b/Sources/Beagle/Sources/Renderer/ViewConfigurator.swift @@ -1,5 +1,5 @@ /* - * Copyright 2020 ZUP IT SERVICOS EM TECNOLOGIA E INOVACAO SA + * Copyright 2020, 2022 ZUP IT SERVICOS EM TECNOLOGIA E INOVACAO SA * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -100,8 +100,8 @@ class ViewConfigurator: ViewConfiguratorProtocol { } object?.isAccessibilityElement = accessibility.accessible - if let isHeader = accessibility.isHeader { - object?.accessibilityTraits = isHeader ? .header : .none + if let isHeader = accessibility.isHeader, isHeader { + object?.accessibilityTraits = .header } } }