Skip to content
This repository has been archived by the owner on Jun 1, 2024. It is now read-only.

Commit

Permalink
fix: Accessibility trait config in applyAccessibility (#41)
Browse files Browse the repository at this point in the history
* fix: Accessibility trait config in applyAccessibility

Signed-off-by: Daniel Tes Carrasque <daniel@zup.com.br>

* fix license header

Signed-off-by: Daniel Tes Carrasque <daniel@zup.com.br>

Co-authored-by: Tiago Peres França <tiagoperesfr@gmail.com>
  • Loading branch information
dantes-git and Tiagoperes authored Apr 7, 2022
1 parent 3638861 commit c6be63f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
21 changes: 21 additions & 0 deletions Sources/Beagle/BeagleTests/Renderer/ViewConfiguratorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
6 changes: 3 additions & 3 deletions Sources/Beagle/Sources/Renderer/ViewConfigurator.swift
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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
}
}
}

0 comments on commit c6be63f

Please sign in to comment.