-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathView-Accessibility-Wrappers.swift
275 lines (230 loc) · 12.2 KB
/
View-Accessibility-Wrappers.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
//
// View-Accessibility-Wrappers.swift
// View-Accessibility-Wrappers
//
// Created by Philipp on 10.09.21.
//
import SwiftUI
#if TARGET_IOS_MAJOR_13
@available(iOS, introduced: 13, obsoleted: 14.0,
message: "Backport not necessary as of iOS 14")
extension ModifiedContent where Modifier == AccessibilityAttachmentModifier {
/// Adds an accessibility action to the view. Actions allow assistive technologies,
/// such as the VoiceOver, to interact with the view by invoking the action.
@inlinable public func accessibilityAction(named nameKey: LocalizedStringKey, _ handler: @escaping () -> Void)
-> ModifiedContent<Content, Modifier> {
self.accessibilityAction(named: Text(nameKey), handler)
}
/// Adds an accessibility action to the view. Actions allow assistive technologies,
/// such as the VoiceOver, to interact with the view by invoking the action.
@inlinable public func accessibilityAction<S>(named name: S, _ handler: @escaping () -> Void)
-> ModifiedContent<Content, Modifier> where S: StringProtocol {
self.accessibilityAction(named: Text(name), handler)
}
/// Specifies whether to hide this view from system accessibility features.
@inlinable public func accessibilityHidden(_ hidden: Bool) -> ModifiedContent<Content, Modifier> {
self.accessibility(hidden: hidden)
}
/// Adds a label to the view that describes its contents.
@inlinable public func accessibilityLabel(_ label: Text) -> ModifiedContent<Content, Modifier> {
self.accessibility(label: label)
}
/// Communicates to the user what happens after performing the view's
/// action.
@inlinable public func accessibilityHint(_ hint: Text) -> ModifiedContent<Content, Modifier> {
accessibility(hint: hint)
}
/// Sets alternate input labels with which users identify a view.
@inlinable public func accessibilityInputLabels(_ inputLabels: [Text]) -> ModifiedContent<Content, Modifier> {
accessibility(inputLabels: inputLabels)
}
/// Uses the string you specify to identify the view.
@inlinable public func accessibilityIdentifier(_ identifier: String) -> ModifiedContent<Content, Modifier> {
accessibility(identifier: identifier)
}
/// Specifies the point where activations occur in the view.
@inlinable public func accessibilityActivationPoint(_ activationPoint: CGPoint)
-> ModifiedContent<Content, Modifier> {
accessibility(activationPoint: activationPoint)
}
/// Specifies the unit point where activations occur in the view.
@inlinable public func accessibilityActivationPoint(_ activationPoint: UnitPoint)
-> ModifiedContent<Content, Modifier> {
accessibility(activationPoint: activationPoint)
}
/// Adds a label to the view that describes its contents.
@inlinable public func accessibilityLabel(_ labelKey: LocalizedStringKey) -> ModifiedContent<Content, Modifier> {
accessibility(label: Text(labelKey))
}
/// Adds a label to the view that describes its contents.
@inlinable public func accessibilityLabel<S>(_ label: S) -> ModifiedContent<Content, Modifier>
where S: StringProtocol {
accessibility(label: Text(label))
}
/// Communicates to the user what happens after performing the view's action.
@inlinable public func accessibilityHint(_ hintKey: LocalizedStringKey) -> ModifiedContent<Content, Modifier> {
accessibility(hint: Text(hintKey))
}
/// Communicates to the user what happens after performing the view's action.
@inlinable public func accessibilityHint<S>(_ hint: S) -> ModifiedContent<Content, Modifier>
where S: StringProtocol {
accessibility(hint: Text(hint))
}
/// Sets alternate input labels with which users identify a view.
@inlinable public func accessibilityInputLabels(_ inputLabelKeys: [LocalizedStringKey])
-> ModifiedContent<Content, Modifier> {
accessibility(inputLabels: inputLabelKeys.map({Text($0)}))
}
/// Sets alternate input labels with which users identify a view.
@inlinable public func accessibilityInputLabels<S>(_ inputLabels: [S]) -> ModifiedContent<Content, Modifier>
where S: StringProtocol {
accessibility(inputLabels: inputLabels.map(Text.init))
}
/// Sets the sort priority order for this view's accessibility
/// element, relative to other elements at the same level.
@inlinable public func accessibilitySortPriority(_ sortPriority: Double) -> ModifiedContent<Content, Modifier> {
accessibility(sortPriority: sortPriority)
}
/// Adds the given traits to the view.
@inlinable public func accessibilityAddTraits(_ traits: AccessibilityTraits) -> ModifiedContent<Content, Modifier> {
accessibility(addTraits: traits)
}
/// Removes the given traits from this view.
@inlinable public func accessibilityRemoveTraits(_ traits: AccessibilityTraits)
-> ModifiedContent<Content, Modifier> {
accessibility(removeTraits: traits)
}
/// Adds a textual description of the value that the view contains.
@inlinable public func accessibilityValue(_ valueDescription: Text) -> ModifiedContent<Content, Modifier> {
accessibility(value: valueDescription)
}
/// Adds a textual description of the value that the view contains.
@inlinable public func accessibilityValue(_ valueKey: LocalizedStringKey) -> ModifiedContent<Content, Modifier> {
accessibility(value: Text(valueKey))
}
/// Adds a textual description of the value that the view contains.
///
/// Use this method to describe the value represented by a view, but only if that's different than the
/// view's label. For example, for a slider that you label as "Volume" using accessibilityLabel(),
/// you can provide the current volume setting, like "60%", using accessibilityValue().
@inlinable public func accessibilityValue<S>(_ value: S) -> ModifiedContent<Content, Modifier>
where S: StringProtocol {
accessibility(value: Text(value))
}
}
@available(iOS, introduced: 13, obsoleted: 14.0,
message: "Backport not necessary as of iOS 14")
extension View {
/// Adds an accessibility action to the view. Actions allow assistive technologies,
/// such as the VoiceOver, to interact with the view by invoking the action.
@inlinable public func accessibilityAction(named nameKey: LocalizedStringKey, _ handler: @escaping () -> Void)
-> ModifiedContent<Self, AccessibilityAttachmentModifier> {
self.accessibilityAction(named: Text(nameKey), handler)
}
/// Adds an accessibility action to the view. Actions allow assistive technologies,
/// such as the VoiceOver, to interact with the view by invoking the action.
@inlinable public func accessibilityAction<S>(named name: S, _ handler: @escaping () -> Void)
-> ModifiedContent<Self, AccessibilityAttachmentModifier> where S: StringProtocol {
self.accessibilityAction(named: Text(name), handler)
}
/// Specifies whether to hide this view from system accessibility features.
@inlinable public func accessibilityHidden(_ hidden: Bool)
-> ModifiedContent<Self, AccessibilityAttachmentModifier> {
self.accessibility(hidden: hidden)
}
/// Adds a label to the view that describes its contents.
@inlinable public func accessibilityLabel(_ label: Text) -> ModifiedContent<Self, AccessibilityAttachmentModifier> {
self.accessibility(label: label)
}
/// Communicates to the user what happens after performing the view's
/// action.
@inlinable public func accessibilityHint(_ hint: Text) -> ModifiedContent<Self, AccessibilityAttachmentModifier> {
accessibility(hint: hint)
}
/// Sets alternate input labels with which users identify a view.
@inlinable public func accessibilityInputLabels(_ inputLabels: [Text])
-> ModifiedContent<Self, AccessibilityAttachmentModifier> {
accessibility(inputLabels: inputLabels)
}
/// Uses the string you specify to identify the view.
@inlinable public func accessibilityIdentifier(_ identifier: String)
-> ModifiedContent<Self, AccessibilityAttachmentModifier> {
accessibility(identifier: identifier)
}
/// Specifies the point where activations occur in the view.
@inlinable public func accessibilityActivationPoint(_ activationPoint: CGPoint)
-> ModifiedContent<Self, AccessibilityAttachmentModifier> {
accessibility(activationPoint: activationPoint)
}
/// Specifies the unit point where activations occur in the view.
@inlinable public func accessibilityActivationPoint(_ activationPoint: UnitPoint)
-> ModifiedContent<Self, AccessibilityAttachmentModifier> {
accessibility(activationPoint: activationPoint)
}
/// Adds a label to the view that describes its contents.
@inlinable public func accessibilityLabel(_ labelKey: LocalizedStringKey)
-> ModifiedContent<Self, AccessibilityAttachmentModifier> {
accessibility(label: Text(labelKey))
}
/// Adds a label to the view that describes its contents.
@inlinable public func accessibilityLabel<S>(_ label: S) -> ModifiedContent<Self, AccessibilityAttachmentModifier>
where S: StringProtocol {
accessibility(label: Text(label))
}
/// Communicates to the user what happens after performing the view's action.
@inlinable public func accessibilityHint(_ hintKey: LocalizedStringKey)
-> ModifiedContent<Self, AccessibilityAttachmentModifier> {
accessibility(hint: Text(hintKey))
}
/// Communicates to the user what happens after performing the view's action.
@inlinable public func accessibilityHint<S>(_ hint: S) -> ModifiedContent<Self, AccessibilityAttachmentModifier>
where S: StringProtocol {
accessibility(hint: Text(hint))
}
/// Sets alternate input labels with which users identify a view.
@inlinable public func accessibilityInputLabels(_ inputLabelKeys: [LocalizedStringKey])
-> ModifiedContent<Self, AccessibilityAttachmentModifier> {
accessibility(inputLabels: inputLabelKeys.map({Text($0)}))
}
/// Sets alternate input labels with which users identify a view.
@inlinable public func accessibilityInputLabels<S>(_ inputLabels: [S])
-> ModifiedContent<Self, AccessibilityAttachmentModifier> where S: StringProtocol {
accessibility(inputLabels: inputLabels.map(Text.init))
}
/// Sets the sort priority order for this view's accessibility
/// element, relative to other elements at the same level.
@inlinable public func accessibilitySortPriority(_ sortPriority: Double)
-> ModifiedContent<Self, AccessibilityAttachmentModifier> {
accessibility(sortPriority: sortPriority)
}
/// Adds the given traits to the view.
@inlinable public func accessibilityAddTraits(_ traits: AccessibilityTraits)
-> ModifiedContent<Self, AccessibilityAttachmentModifier> {
accessibility(addTraits: traits)
}
/// Removes the given traits from this view.
@inlinable public func accessibilityRemoveTraits(_ traits: AccessibilityTraits)
-> ModifiedContent<Self, AccessibilityAttachmentModifier> {
accessibility(removeTraits: traits)
}
/// Adds a textual description of the value that the view contains.
@inlinable public func accessibilityValue(_ valueDescription: Text)
-> ModifiedContent<Self, AccessibilityAttachmentModifier> {
accessibility(value: valueDescription)
}
/// Adds a textual description of the value that the view contains.
@inlinable public func accessibilityValue(_ valueKey: LocalizedStringKey)
-> ModifiedContent<Self, AccessibilityAttachmentModifier> {
accessibility(value: Text(valueKey))
}
/// Adds a textual description of the value that the view contains.
///
/// Use this method to describe the value represented by a view, but only if that's different than the
/// view's label. For example, for a slider that you label as "Volume" using accessibilityLabel(),
/// you can provide the current volume setting, like "60%", using accessibilityValue().
@inlinable public func accessibilityValue<S>(_ value: S) -> ModifiedContent<Self, AccessibilityAttachmentModifier>
where S: StringProtocol {
accessibility(value: Text(value))
}
}
#endif