Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Example/AccessibilitySnapshot.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
1104A8D12B595FF600B6715F /* TextFieldViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1104A8D02B595FF600B6715F /* TextFieldViewController.swift */; };
112909BC2B63E57B00B4EBEB /* TextViewViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 112909BB2B63E57B00B4EBEB /* TextViewViewController.swift */; };
1635CE4E251EAC6700907101 /* SnapshotTestingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1635CE4D251EAC6700907101 /* SnapshotTestingTests.swift */; };
346FEE602ED63C220077CD7D /* AccessibilityFeatureShowcaseView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 346FEE5F2ED63C220077CD7D /* AccessibilityFeatureShowcaseView.swift */; };
349DD3262ED0D843009E6D09 /* AccessibilityFeatureShowcaseTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 349DD3252ED0D843009E6D09 /* AccessibilityFeatureShowcaseTests.swift */; };
3D04B6D6211558B0006218A4 /* AccessibilityViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3D04B6D5211558B0006218A4 /* AccessibilityViewController.swift */; };
3D04B6D921155942006218A4 /* LabelAccessibilityPropertiesViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3D04B6D821155942006218A4 /* LabelAccessibilityPropertiesViewController.swift */; };
3D04B6DB21155D92006218A4 /* ButtonAccessibilityTraitsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3D04B6DA21155D92006218A4 /* ButtonAccessibilityTraitsViewController.swift */; };
Expand Down Expand Up @@ -93,6 +95,8 @@
1104A8D02B595FF600B6715F /* TextFieldViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextFieldViewController.swift; sourceTree = "<group>"; };
112909BB2B63E57B00B4EBEB /* TextViewViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextViewViewController.swift; sourceTree = "<group>"; };
1635CE4D251EAC6700907101 /* SnapshotTestingTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SnapshotTestingTests.swift; sourceTree = "<group>"; };
346FEE5F2ED63C220077CD7D /* AccessibilityFeatureShowcaseView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccessibilityFeatureShowcaseView.swift; sourceTree = "<group>"; };
349DD3252ED0D843009E6D09 /* AccessibilityFeatureShowcaseTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccessibilityFeatureShowcaseTests.swift; sourceTree = "<group>"; };
358D84DCD315110A89BD052E /* Pods-UnitTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-UnitTests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-UnitTests/Pods-UnitTests.debug.xcconfig"; sourceTree = "<group>"; };
3A3192D7B9B16BD10FB517A2 /* Pods_SnapshotTests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_SnapshotTests.framework; sourceTree = BUILT_PRODUCTS_DIR; };
3B8EB28BD6E6A6332C5D3115 /* LICENSE */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; name = LICENSE; path = ../LICENSE; sourceTree = "<group>"; };
Expand Down Expand Up @@ -218,6 +222,7 @@
3DF46501220D7F9B0048D446 /* ElementOrderViewController.swift */,
AC59D46F2D83326F0096B803 /* ElementFrameComparisonController.swift */,
3D0AC55B222DD70A00B6F1C1 /* UserInterfaceDirectionViewController.swift */,
346FEE5F2ED63C220077CD7D /* AccessibilityFeatureShowcaseView.swift */,
3DEBF24D221018610065424F /* DefaultControlsViewController.swift */,
3DBEAA5A2222953E00FAE61D /* SwitchControlViewController.swift */,
3DC488362212A7D4006D1E15 /* ModalAccessibilityViewController.swift */,
Expand Down Expand Up @@ -340,6 +345,7 @@
607FACEB1AFB9204008FA782 /* AccessibilityPropertiesTests.swift */,
D2F76EEC2945C879000A453F /* HitTargetTests.swift */,
3D39BFAF2239BC42009C3EF4 /* ActivationPointTests.swift */,
349DD3252ED0D843009E6D09 /* AccessibilityFeatureShowcaseTests.swift */,
3DEBF24F22101EE40065424F /* DefaultControlsTests.swift */,
3DF46503220D8C500048D446 /* ElementOrderTests.swift */,
AC59D4712D8333020096B803 /* ElementFrameComparisonTests.swift */,
Expand Down Expand Up @@ -647,6 +653,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
346FEE602ED63C220077CD7D /* AccessibilityFeatureShowcaseView.swift in Sources */,
607FACD81AFB9204008FA782 /* RootViewController.swift in Sources */,
3F8E5DB92535B25000276B32 /* SwiftUIView.swift in Sources */,
3DBEAA5F2223D0DA00FAE61D /* AccessibilityPathViewController.swift in Sources */,
Expand Down Expand Up @@ -687,6 +694,7 @@
buildActionMask = 2147483647;
files = (
3D13DB522221124000066519 /* ObjectiveCTests.m in Sources */,
349DD3262ED0D843009E6D09 /* AccessibilityFeatureShowcaseTests.swift in Sources */,
3DC2C67C21F46020003184E4 /* HighlightTests.swift in Sources */,
3DF464FC220D4F430048D446 /* SnapshotTestCase.swift in Sources */,
3D3F2E162263E94D00F7608E /* InvertColorsTests.swift in Sources */,
Expand Down
127 changes: 127 additions & 0 deletions Example/AccessibilitySnapshot/AccessibilityFeatureShowcaseView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
//
// 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 SwiftUI
import UIKit

@available(iOS 16.0, *)
struct AccessibilityFeatureShowcaseView: View {

var body: some View {
VStack(alignment: .leading, spacing: 24) {

// Just a label
Text("Basic label")

// Label and value
HStack(spacing: 4) {
Text("Basic label with value")
.bold()
Text("Here is the value")
}
.accessibilityElement(children: .ignore)
.accessibilityLabel(Text("Basic label with value"))
.accessibilityValue(Text("Here is the value"))

// Custom hint
Text("Something with a hint")
.accessibilityHint(Text("Here's the hint."))

// Custom input labels
Text("Custom input labels")
.accessibilityRespondsToUserInteraction()
.accessibilityInputLabels([Text("Custom Label 1"), Text("Another custom label")])

// Header trait
Text("A label marked as a header")
.font(.headline)
.accessibilityAddTraits(.isHeader)

// Button trait
Button("Something with the button trait", action: { })

// Link trait
Text("Something with the link trait")
.accessibilityAddTraits(.isLink)

Slider(value: .constant(0.5), in: 0...1.5)
.accessibilityLabel(Text("A slider that has the adjustable trait"))

CustomActionFeatureCard()

RotorTraitFeatureCard()
}
.navigationTitle(Text("Accessibility Snapshot Feature Showcase"))
.padding()
}
}

@available(iOS 16.0, *)
private struct CustomActionFeatureCard: View {
var body: some View {
VStack {
Text("Three buttons combined. The latter two become accessibility custom actions")
HStack {
Button("Primary button") { }
.buttonStyle(.borderedProminent)
Button("Reply") { }
Button("Archive") { }
}
}
.buttonStyle(.bordered)
.accessibilityElement(children: .combine)
}
}

@available(iOS 16.0, *)
private struct RotorTraitFeatureCard: View {

private let flaggedEntries = [
"Melissa — Needs approval",
"Jordan — Missing receipt",
"Priya — Waiting on brand review",
]

let title = "A custom rotor"

var body: some View {
VStack(alignment: .leading, spacing: 4) {
Text(title.uppercased())
.font(.caption)
.fontWeight(.bold)
.foregroundColor(.secondary)

ForEach(flaggedEntries, id: \.self) { entry in
Text(entry)
}
}
.accessibilityElement(children: .combine)
.accessibilityLabel(Text(title))
.accessibilityRotor(Text(title), entries: {
ForEach(flaggedEntries, id: \.self) { entry in
AccessibilityRotorEntry(entry, id: entry)
}
})
}
}

#Preview {
if #available(iOS 16.0, *) {
AccessibilityFeatureShowcaseView()
} else {
Text("Not available")
}
}
52 changes: 52 additions & 0 deletions Example/SnapshotTests/AccessibilityFeatureShowcaseTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
//
// 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 AccessibilitySnapshot
import FBSnapshotTestCase
import UIKit

@testable import AccessibilitySnapshotDemo

class FeatureShowcaseSnapshotTestCase: SnapshotTestCase {

override func setUpWithError() throws {
try super.setUpWithError()

guard #available(iOS 16.0, *) else {
throw XCTSkip("Feature showcase requires iOS 16 or newer.")
}
}

}

@available(iOS 16.0, *)
final class FeatureShowcaseSnapshotTests: FeatureShowcaseSnapshotTestCase {

func testFeatureShowcaseView() {
let configuration = AccessibilitySnapshotConfiguration(
viewRenderingMode: .drawHierarchyInRect,
includesInputLabels: .whenOverridden,
includesCustomRotors: .always
)

SnapshotVerifyAccessibility(
AccessibilityFeatureShowcaseView(),
size: UIScreen.main.bounds.size,
snapshotConfiguration: configuration
)
}

}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading