Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DO NOT MERGE] Visual Regression Testing with Percy Example #7

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
48 changes: 27 additions & 21 deletions Example/SampleApp/AccessibilityExamples/ActionExample.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,33 +51,39 @@ public struct ActionExample: View {

public var body: some View {
VStack(alignment: .leading) {
Text("Element with default action")

AccessibilityElementView(color: defaultActionColor, text: Text("Default"))
.accessibilityLabel(Text("Element with default action"))
.accessibilityAddTraits(.isButton)
.accessibilityAction {
print("Default action fired!")
self.defaultActionFired = true
}
VStack(alignment: .leading) {
Text("Element with default action").accessibilityHidden(true)
AccessibilityElementView(color: defaultActionColor, text: Text("Default"))
}
.accessibilityLabel(Text("Element with default action"))
.accessibilityAddTraits(.isButton)
.accessibilityAction {
print("Default action fired!")
self.defaultActionFired = true
}
.accessibilityElement(children: .combine)

LargeSpacer()

Text("Element with custom actions")

AccessibilityElementView(color: customActionColor, text: Text("Custom"))
.accessibilityLabel(Text("Element with custom actions"))
.accessibilityAction(named: Text("Custom Action 1"), customAction1)
.accessibilityAction(named: Text("Custom Action 2"), customAction2)
VStack(alignment: .leading) {
Text("Element with custom actions").accessibilityHidden(true)
AccessibilityElementView(color: customActionColor, text: Text("Custom"))
}
.accessibilityLabel(Text("Element with custom actions"))
.accessibilityAction(named: Text("Custom Action 1"), customAction1)
.accessibilityAction(named: Text("Custom Action 2"), customAction2)
.accessibilityElement(children: .combine)

LargeSpacer()

Text("Custom adjustment action element")

AccessibilityElementView(color: .green, text: Text("Adjustable: \(incrementIndex)"))
.accessibilityLabel(Text("Custom increment element"))
.accessibilityValue(Text(verbatim: "\(incrementIndex)"))
.accessibilityAdjustableAction(adjustAction)
VStack(alignment: .leading) {
Text("Custom adjustment action element").accessibilityHidden(true)
AccessibilityElementView(color: .green, text: Text("Adjustable: \(incrementIndex)"))
}
.accessibilityLabel(Text("Custom adjustment action element"))
.accessibilityValue(Text(verbatim: "\(incrementIndex)"))
.accessibilityAdjustableAction(adjustAction)
.accessibilityElement(children: .combine)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,17 @@ public struct ContainerExample: View {
// Create a stack with multiple toggles and a label inside.
VStack(alignment: .leading) {
Text("Grouping Container")
.accessibilityAddTraits(.isHeader)
.accessibilitySortPriority(0)

Toggle(isOn: $onState) { Text("Toggle 1") }
.accessibilitySortPriority(2)
Toggle(isOn: $onState) { Text("Toggle 2") }
.accessibilitySortPriority(1)
Toggle(isOn: $onState) { Text("Toggle 3") }
.accessibilitySortPriority(3)
Toggle(isOn: $onState) { Text("Toggle 4") }
.accessibilitySortPriority(4)
}
.padding()
.background(Color.white)
Expand Down
3 changes: 3 additions & 0 deletions Example/SampleApp/AccessibilityExamples/ImageExample.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,15 @@ public struct ImageExample: View {
public var body: some View {
VStack(alignment: .leading) {
Text("Unlabeled Image")
.accessibilityHidden(true)

// This image creates an accessibility element, but has no label.
ExampleImageView(Image("dot_green"))

LargeSpacer()

Text("Labeled Images")
.accessibilityHidden(true)

HStack {
// This image uses an explicit accessibility label via the API.
Expand All @@ -61,6 +63,7 @@ public struct ImageExample: View {
LargeSpacer()

Text("Decorative Image")
.accessibilityHidden(true)

// This image is explicitly marked decorative, so it does not
// create an accessibility element.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,26 @@ public struct RepresentableExample: View {
public var body: some View {
VStack(alignment: .leading) {
Text("Element with representable view")
.accessibilityLabel("representable view")

// You can use SwiftUI's Accessibility API to customize to accessibility of
// AppKit or UIKit represented elements
RepresentableView()
.frame(width: 128, height: 48)
.accessibilityLabel(Text("representable view accessibility label"))
.accessibilityValue(Text("representable view accessibility value"))
.accessibilityHint(Text("representable view accessibility hint"))

LargeSpacer()

Text("Element with representable view controller")
.accessibilityLabel("representable view controller")

RepresentableViewController()
.frame(width: 128, height: 48)
.accessibilityLabel(Text("representable view controller accessibility label"))
.accessibilityValue(Text("representable view controller accessibility value"))
.accessibilityHint(Text("representable view accessibility hint"))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public struct StandardControlExample: View {
Button(action: {}) {
Text("Button with hint & identifier")
}
.accessibilityRemoveTraits(.isButton)
.accessibilityHint(Text("Accessibility hint for first button"))
.accessibilityIdentifier("First Button")

Expand All @@ -25,6 +26,7 @@ public struct StandardControlExample: View {
Text("Toggle with hint")
}
.accessibilityHint(Text("Accessibility hint for toggle"))
.disabled(true)

LargeSpacer()

Expand Down
5 changes: 3 additions & 2 deletions Example/SampleApp/AccessibilityExamples/TextExample.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public struct TextExample: View {

Text("Relabeled Text")
.accessibilityLabel(Text("Accessibility Label"))
.accessibilityAddTraits(.isStaticText)

LargeSpacer()

Expand All @@ -30,9 +31,9 @@ public struct TextExample: View {
Text("Stacked Multiple Line Text Line 1")
Text("This is on another line")
}
.accessibilityElement(children: .combine)
.accessibilityElement(children: .contain)

Text("Simple Multiple Line Text\nThis is on another line")
Text("Simple Multiple Line Text\nThis is on second line\nThis is on third line")
.lineLimit(nil)

LargeSpacer()
Expand Down