-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c6b18fb
commit d0387e9
Showing
20 changed files
with
422 additions
and
6 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
138 changes: 138 additions & 0 deletions
138
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,138 @@ | ||
// | ||
// Copyright 2020 Square 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 Paralayout | ||
import UIKit | ||
import Accessibility | ||
|
||
@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 { | ||
|
||
// Swift 5.4 ships with Xcode 12.5 and the iOS 14.5 SDK. | ||
#if swift(>=5.4) | ||
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] | ||
}() | ||
} | ||
|
||
#else | ||
final class CustomContentView: UIView { | ||
// This shouldnt ever get called because of the @available(iOS 14.0, *) | ||
init(includeLabel: Bool, includeHint: Bool) { | ||
super.init(frame: .zero) | ||
|
||
backgroundColor = .gray | ||
|
||
isAccessibilityElement = true | ||
|
||
accessibilityLabel = "Accessibility Custom Content not avilable in this SDK" | ||
accessibilityHint = "Please use iOS 14 or later for Custom Content" | ||
} | ||
|
||
@available(*, unavailable) | ||
required init?(coder: NSCoder) { | ||
fatalError("init(coder:) has not been implemented") | ||
} | ||
#endif | ||
} |
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
+135 Bytes
(100%)
...mages/_64/SnapshotTests.SwiftUISnapshotTests/[email protected]
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.8 KB
(110%)
...mages/_64/SnapshotTests.SwiftUISnapshotTests/[email protected]
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/[email protected]
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
+135 Bytes
(100%)
...shots__/SnapshotTestingTests/testSimpleSwiftUIConfiguration.375x812-13-7-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.8 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
+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.
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.