Skip to content

Commit b931c90

Browse files
committed
Accessibility changes
1 parent 310dbae commit b931c90

File tree

6 files changed

+46
-23
lines changed

6 files changed

+46
-23
lines changed

Example/SampleApp/AccessibilityExamples/ActionExample.swift

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -51,33 +51,39 @@ public struct ActionExample: View {
5151

5252
public var body: some View {
5353
VStack(alignment: .leading) {
54-
Text("Element with default action")
55-
56-
AccessibilityElementView(color: defaultActionColor, text: Text("Default"))
57-
.accessibilityLabel(Text("Element with default action"))
58-
.accessibilityAddTraits(.isButton)
59-
.accessibilityAction {
60-
print("Default action fired!")
61-
self.defaultActionFired = true
62-
}
54+
VStack(alignment: .leading) {
55+
Text("Element with default action").accessibilityHidden(true)
56+
AccessibilityElementView(color: defaultActionColor, text: Text("Default"))
57+
}
58+
.accessibilityLabel(Text("Element with default action"))
59+
.accessibilityAddTraits(.isButton)
60+
.accessibilityAction {
61+
print("Default action fired!")
62+
self.defaultActionFired = true
63+
}
64+
.accessibilityElement(children: .combine)
6365

6466
LargeSpacer()
6567

66-
Text("Element with custom actions")
67-
68-
AccessibilityElementView(color: customActionColor, text: Text("Custom"))
69-
.accessibilityLabel(Text("Element with custom actions"))
70-
.accessibilityAction(named: Text("Custom Action 1"), customAction1)
71-
.accessibilityAction(named: Text("Custom Action 2"), customAction2)
68+
VStack(alignment: .leading) {
69+
Text("Element with custom actions").accessibilityHidden(true)
70+
AccessibilityElementView(color: customActionColor, text: Text("Custom"))
71+
}
72+
.accessibilityLabel(Text("Element with custom actions"))
73+
.accessibilityAction(named: Text("Custom Action 1"), customAction1)
74+
.accessibilityAction(named: Text("Custom Action 2"), customAction2)
75+
.accessibilityElement(children: .combine)
7276

7377
LargeSpacer()
7478

75-
Text("Custom adjustment action element")
76-
77-
AccessibilityElementView(color: .green, text: Text("Adjustable: \(incrementIndex)"))
78-
.accessibilityLabel(Text("Custom increment element"))
79-
.accessibilityValue(Text(verbatim: "\(incrementIndex)"))
80-
.accessibilityAdjustableAction(adjustAction)
79+
VStack(alignment: .leading) {
80+
Text("Custom adjustment action element").accessibilityHidden(true)
81+
AccessibilityElementView(color: .green, text: Text("Adjustable: \(incrementIndex)"))
82+
}
83+
.accessibilityLabel(Text("Custom adjustment action element"))
84+
.accessibilityValue(Text(verbatim: "\(incrementIndex)"))
85+
.accessibilityAdjustableAction(adjustAction)
86+
.accessibilityElement(children: .combine)
8187
}
8288
}
8389

Example/SampleApp/AccessibilityExamples/ContainerExample.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,17 @@ public struct ContainerExample: View {
1616
// Create a stack with multiple toggles and a label inside.
1717
VStack(alignment: .leading) {
1818
Text("Grouping Container")
19+
.accessibilityAddTraits(.isHeader)
20+
.accessibilitySortPriority(0)
21+
1922
Toggle(isOn: $onState) { Text("Toggle 1") }
23+
.accessibilitySortPriority(2)
2024
Toggle(isOn: $onState) { Text("Toggle 2") }
25+
.accessibilitySortPriority(1)
2126
Toggle(isOn: $onState) { Text("Toggle 3") }
27+
.accessibilitySortPriority(3)
2228
Toggle(isOn: $onState) { Text("Toggle 4") }
29+
.accessibilitySortPriority(4)
2330
}
2431
.padding()
2532
.background(Color.white)

Example/SampleApp/AccessibilityExamples/ImageExample.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,15 @@ public struct ImageExample: View {
3636
public var body: some View {
3737
VStack(alignment: .leading) {
3838
Text("Unlabeled Image")
39+
.accessibilityHidden(true)
3940

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

4344
LargeSpacer()
4445

4546
Text("Labeled Images")
47+
.accessibilityHidden(true)
4648

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

6365
Text("Decorative Image")
66+
.accessibilityHidden(true)
6467

6568
// This image is explicitly marked decorative, so it does not
6669
// create an accessibility element.

Example/SampleApp/AccessibilityExamples/RepresentableExample.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,26 @@ public struct RepresentableExample: View {
1212
public var body: some View {
1313
VStack(alignment: .leading) {
1414
Text("Element with representable view")
15+
.accessibilityLabel("representable view")
1516

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

2325
LargeSpacer()
2426

2527
Text("Element with representable view controller")
28+
.accessibilityLabel("representable view controller")
2629

2730
RepresentableViewController()
2831
.frame(width: 128, height: 48)
2932
.accessibilityLabel(Text("representable view controller accessibility label"))
3033
.accessibilityValue(Text("representable view controller accessibility value"))
34+
.accessibilityHint(Text("representable view accessibility hint"))
3135
}
3236
}
3337

Example/SampleApp/AccessibilityExamples/StandardControlExample.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public struct StandardControlExample: View {
1616
Button(action: {}) {
1717
Text("Button with hint & identifier")
1818
}
19+
.accessibilityRemoveTraits(.isButton)
1920
.accessibilityHint(Text("Accessibility hint for first button"))
2021
.accessibilityIdentifier("First Button")
2122

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

2931
LargeSpacer()
3032

Example/SampleApp/AccessibilityExamples/TextExample.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public struct TextExample: View {
1717

1818
Text("Relabeled Text")
1919
.accessibilityLabel(Text("Accessibility Label"))
20+
.accessibilityAddTraits(.isStaticText)
2021

2122
LargeSpacer()
2223

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

35-
Text("Simple Multiple Line Text\nThis is on another line")
36+
Text("Simple Multiple Line Text\nThis is on second line\nThis is on third line")
3637
.lineLimit(nil)
3738

3839
LargeSpacer()

0 commit comments

Comments
 (0)