AccessibilityCombine
public struct AccessibilityCombine : Element
Use AccessibilityCombine to automatically combine child accessibility elements:
struct CustomRow: Element {
var content: ElementContent {
Row {
Image(image: profileImage)
Column {
Label(text: userName)
Label(text: userStatus)
}
Button("Follow") { followUser() }
}
.accessibilityCombine()
// Automatically combines: "Profile image, John Doe, Online, Follow"
// Button functionality preserved as custom action
}
}
Custom Filtering and Sorting
struct SmartCombinedElement: Element {
var content: ElementContent {
Column {
Label(text: "Header").accessibilityTraits(add: [.header])
Label(text: "Content")
Button("Action") { /* action */ }
}
.accessibilityCombine(
customFilter: { element in
// Only include elements with accessibility content
return element.hasAccessibilityRepresentation
},
customSorting: { element1, element2 in
// Headers come first
let element1IsHeader = element1.accessibilityTraits.contains(.header)
let element2IsHeader = element2.accessibilityTraits.contains(.header)
return element1IsHeader && !element2IsHeader
}
)
}
}
-
The wrapped element
Declaration
Swift
public var wrappedElement: Element -
A filter closure that will be applied to the discovered child elements, allowing for conditional inclusion. Return
trueif the element should be included in the derived accessibility representation.Declaration
Swift
public var customFilter: AccessibilityComposition.Filter? -
A sorting closure that will be applied to the discovered child elements, allowing for custom sort order. If no custom sorting is provided, elements will be using by their accessibility frame with a
Leading -> Trailing, Top -> Bottomheuristic.Declaration
Swift
public var customSorting: AccessibilityComposition.Sorting? -
After generating the combined accessibility representation, if this flag is
true, the element will not be accessible unless it has a non-nil and non-emptyaccessibilityLabel,accessibilityValue, oraccessibilityHint.Declaration
Swift
public var blockWhenNotAccessible: Bool -
Declaration
Swift
public init( wrapping element: @escaping () -> Element, customFilter: AccessibilityComposition.Filter? = nil, customSorting: AccessibilityComposition.Sorting? = nil, blockWhenNotAccessible: Bool = true ) -
Declaration
Swift
public var content: ElementContent { get } -
Declaration
Swift
public func backingViewDescription(with context: ViewDescriptionContext) -> ViewDescription?
View on GitHub
AccessibilityCombine Structure Reference