-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #173 from cashapp/alex/AXCustomContent
Support Accessibility Custom Content
- Loading branch information
Showing
26 changed files
with
453 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
116 changes: 116 additions & 0 deletions
116
Example/AccessibilitySnapshot/AccessibilityCustomContentViewController.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
// | ||
// Copyright 2024 Block Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
import Accessibility | ||
import Paralayout | ||
import UIKit | ||
|
||
@available(iOS 14.0, *) | ||
final class AccessibilityCustomContentViewController: AccessibilityViewController { | ||
|
||
// MARK: - UIViewController | ||
|
||
override func loadView() { | ||
view = View( | ||
views: [ | ||
.init(includeLabel: true, includeHint: true), | ||
.init(includeLabel: true, includeHint: false), | ||
.init(includeLabel: false, includeHint: true), | ||
.init(includeLabel: false, includeHint: false), | ||
] | ||
) | ||
} | ||
|
||
} | ||
|
||
// MARK: - | ||
@available(iOS 14.0, *) | ||
private extension AccessibilityCustomContentViewController { | ||
|
||
final class View: UIView { | ||
|
||
// MARK: - Life Cycle | ||
|
||
init(views: [CustomContentView], frame: CGRect = .zero) { | ||
self.views = views | ||
|
||
super.init(frame: frame) | ||
|
||
views.forEach(addSubview) | ||
} | ||
|
||
@available(*, unavailable) | ||
required init?(coder: NSCoder) { | ||
fatalError("init(coder:) has not been implemented") | ||
} | ||
|
||
// MARK: - Private Properties | ||
|
||
private let views: [CustomContentView] | ||
|
||
// MARK: - UIView | ||
|
||
override func layoutSubviews() { | ||
views.forEach { $0.bounds.size = .init(width: bounds.width / 2, height: 50) } | ||
|
||
let statusBarHeight = window?.windowScene?.statusBarManager?.statusBarFrame.height ?? 0 | ||
|
||
var distributionSpecifiers: [ViewDistributionSpecifying] = [ statusBarHeight.fixed, 1.flexible ] | ||
for subview in views { | ||
distributionSpecifiers.append(subview) | ||
distributionSpecifiers.append(1.flexible) | ||
} | ||
applyVerticalSubviewDistribution(distributionSpecifiers) | ||
} | ||
|
||
} | ||
|
||
} | ||
|
||
// MARK: - | ||
@available(iOS 14.0, *) | ||
private extension AccessibilityCustomContentViewController { | ||
|
||
final class CustomContentView: UIView, AXCustomContentProvider { | ||
// MARK: - Life Cycle | ||
|
||
init(includeLabel: Bool, includeHint: Bool) { | ||
super.init(frame: .zero) | ||
|
||
backgroundColor = .gray | ||
|
||
isAccessibilityElement = true | ||
|
||
accessibilityLabel = includeLabel ? "Label" : nil | ||
accessibilityHint = includeHint ? "Hint" : nil | ||
} | ||
|
||
@available(*, unavailable) | ||
required init?(coder: NSCoder) { | ||
fatalError("init(coder:) has not been implemented") | ||
} | ||
|
||
// MARK: - UIAccessibility | ||
var accessibilityCustomContent: [AXCustomContent]! = { | ||
let customContent = AXCustomContent(label: "Custom Content Label", value: "Custom Content Value") | ||
|
||
let highImportance = AXCustomContent(label: "High Importance Label", value: "High Importance Value") | ||
highImportance.importance = .high | ||
|
||
return [customContent, highImportance] | ||
}() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file added
BIN
+242 KB
...AccessibilitySnapshotTests/testCustomContentAndReturnError__14_5_390x844@3x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+243 KB
...AccessibilitySnapshotTests/testCustomContentAndReturnError__16_4_393x852@3x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+243 KB
...AccessibilitySnapshotTests/testCustomContentAndReturnError__17_2_393x852@3x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+24.3 KB
(130%)
...shotTests.SwiftUISnapshotTests/testSimpleViewAtSizeThatFits_14_5_390x844@3x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+60.3 KB
(170%)
...shotTests.SwiftUISnapshotTests/testSimpleViewAtSizeThatFits_16_4_393x852@3x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+39.2 KB
(140%)
...shotTests.SwiftUISnapshotTests/testSimpleViewAtSizeThatFits_17_2_393x852@3x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+17.6 KB
(110%)
...mages/_64/SnapshotTests.SwiftUISnapshotTests/testSimpleView_14_5_390x844@3x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+47.3 KB
(130%)
...mages/_64/SnapshotTests.SwiftUISnapshotTests/testSimpleView_16_4_393x852@3x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+26.6 KB
(120%)
...mages/_64/SnapshotTests.SwiftUISnapshotTests/testSimpleView_17_2_393x852@3x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+17.6 KB
(110%)
...shots__/SnapshotTestingTests/testSimpleSwiftUIConfiguration.390x844-14-5-3x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+47.3 KB
(130%)
...shots__/SnapshotTestingTests/testSimpleSwiftUIConfiguration.393x852-16-4-3x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+26.6 KB
(120%)
...shots__/SnapshotTestingTests/testSimpleSwiftUIConfiguration.393x852-17-2-3x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+17.6 KB
(110%)
...otTestingTests/testSimpleSwiftUIWithScrollViewConfiguration.390x844-14-5-3x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+47.3 KB
(130%)
...otTestingTests/testSimpleSwiftUIWithScrollViewConfiguration.393x852-16-4-3x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+26.6 KB
(120%)
...otTestingTests/testSimpleSwiftUIWithScrollViewConfiguration.393x852-17-2-3x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.