[英]HorizontalPager is ignoring itemSpacing and overriding content in Jetpack Compose
[英]Jetpack Compose: ignoring descendants' content description
假设我有一个带有行的列。 每行都是一个逻辑单元,我希望 Talkback 逐行浏览列,而不选择行的后代。 使用mergeDescendants = true
很容易实现
现在,我为 Row 定制了一个 contentDescription,它提供了更自然的描述。 如何忽略要阅读的后代文本,以防止信息翻倍?
tl;dr:当使用mergeDescendants
时; 如何让 Talkback 替换而不是合并后代的 contentDescriptions?
@Composable
fun Greeting() {
// Goal: Each row is a single entity for talkback, that has a content desccription describing the entire tow
// descendants should not be focused when navigating by swipe w/ talkback
// "Greeting for Android X" should be read, descendants should not be read automatically.
Column(modifier = Modifier.padding(20.dp)) {// Screen padding
Box(
// "greeting for Android 1 ... Hello Android! ... How do you do?" :-(
// descendants can not be selected individually :-)
Modifier.semantics(mergeDescendants = true) {
contentDescription = "greeting for Android 1"
}
) {
Row {
Text(text = "Hello Android!", modifier = Modifier.padding(32.dp))
Text(text = "How do you do?", modifier = Modifier.padding(32.dp))
}
}
Box(
// "greeting for Android 2" :-)
// descendants will be traversed next :-(
Modifier.semantics {
contentDescription = "greeting for Android 2"
}
) {
Row {
Text(text = "Hello Android!", modifier = Modifier.padding(32.dp))
Text(text = "How do you do?", modifier = Modifier.padding(32.dp))
}
}
Box(
// "greeting for Android 3" :-)
// descendants can not be selected individually :-)
// When using tap to speak rather than swipe, it is hard to select the row:
// Only when tapping empty space will the row be selected.
// When tapping either text element,nothing happens. :-(
// Expected: the row is selected and "greeting for android 3" is read when
// I tap anywhere inside it's bounds
Modifier.semantics {
contentDescription = "greeting for Android 3"
}
) {
Row(Modifier.clearAndSetSemantics {}) {
Text(text = "Hello Android!", modifier = Modifier.padding(32.dp))
Text(text = "How do you do?", modifier = Modifier.padding(32.dp))
}
}
}
}
我假设在您在顶级Box
上方提供的代码中代表您的“行”。 尝试首先合并 Box 子项的语义属性,然后通过对 Box 应用以下修饰符来清除所有这些属性并设置您的自定义内容描述:
Modifier
.semantics(mergeDescendants = true) {}
.clearAndSetSemantics { contentDescription = "greeting for Android 1" }
此外,您还可以在每个 Box 的子项上显式调用以下内容,以确保忽略它们的语义属性:
Modifier.clearAndSetSemantics {}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.