does anyone have a reference to the rules the CMP ...
# compose-ios
s
does anyone have a reference to the rules the CMP applies when converting semantic contentDescription to accessibility labels? Seen a instance where on iOS the content description removes the Text of a button and sets the contentDescription as the Buttons Label. I’d guess for my case I would want a way to send the accessibilityChild options from compose to swift so I can ignore this contentDescription for one particular item without goint down the expect actual root. Thanks.
a
Sorry, didn't get what you'd like to achieve.
s
Sure I’ll try to clarify, I would like to know how CMP determines accessibilityElements on iOS When CMP converts the semantic modifier “contentDescription” to iOS
a
https://github.com/JetBrains/compose-multiplatform-core/blob/d74c67a9bb094412d0c89[…]compose/ui/platform/accessibility/SemanticConfigurationUtils.kt If content description exists in the node (or it is a result of merging description from clild nodes), it will be assigned as accessibilityLabel. Otherwise some heuristic will be applied to match accessibility of Material(3) nodes with iOS views.
s
thanks, is there anything from semantic modifer that will map to the swiftUI accessibility api? so a modifer that will map to this one? https://developer.apple.com/documentation/swiftui/view/accessibilityelement(children:)
a
We're not mapping into SwiftUI. Both, Compose Accessibility for iOS and SwiftUI are mapped to some kind of tree structure based on the UIAccessibility. To mimic such behavior, you can use
semantics
or
clearAndSetSemantics
modifiers
s
I’m not familiar with UIAccessibility but I see I’ve made an assumption in error. But when you say you can use
semantics
, are you saying I can just lists out the accessibility api found in swiftui in the modifier?
Copy code
.semantic {
  accessibilityElement = { children = AccessibilityChildBehavior.ignore }
}
My end goal is to have children be ignored specifically if they have a contentDescription which is being used as a “non-accessibility” property for a nested element. Thanks again.
a
Please correct me if I understood wrong. This will remove all children semantics from the tree:
Copy code
Column(modifier = Modifier.clearAndSetSemantics {
                // Setup new semantics here
            }) {
                Text("Text 1", modifier = Modifier.semantics {
                    contentDescription = "Text 1" // Won't be accessible or propagated to parent
                })
                Text("Text 2", modifier = Modifier.semantics {
                    contentDescription = "Text 2" // Won't be accessible or propagated to parent
                })
            }
1
s
Your example is correct, and I understanding it now, when I finally realized it wasn’t using the swiftui accessibility api. I understood It would be a manual process i.e “// Setup new sematics here”
👍 1