JetPack组成:忽略后代'内容描述

发布于 2025-01-29 19:16:39 字数 2485 浏览 4 评论 0原文

假设我有一个带有行的列。每一行都是逻辑单元,我想对话以逐行导航,而无需选择该行的后代。 现在,使用MERGEDESCENDANTS = true现在可以很容易地实现这一点

,我有一个针对该行的量身定制的内容描述,可以提供更自然的描述。我如何忽略后代的文本要阅读,以防止将信息加倍?

tl; dr:使用合并Escendants;如何使对讲替换而不是合并后代的内容描述?

@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))
            }
        }
    }
}

Let's say I have a Column with Rows. Each Row is a logical unit and I want Talkback to navigate through the Column Row by Row, without selecting and descendants of the row. That's easily achievable with mergeDescendants = true

Now, I have a tailored contentDescription for the Row, that provides a more natural description. How do I ignore the descendant's text to be read, to prevent doubling the information?

tl;dr: When using mergeDescendants; how do I make Talkback replace rather than merge the descendants' 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))
            }
        }
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

池木 2025-02-05 19:16:39

我假设在您上方呈现的代码中,box表示您的“行”。首先尝试合并Box的孩子的语义属性,然后通过将以下修饰符应用于Box来清除所有内容并设置自定义内容说明:

Modifier
  .semantics(mergeDescendants = true) {}
  .clearAndSetSemantics { contentDescription = "greeting for Android 1" }

此外,您还可以在每个Box的孩子上明确调用以下以下内容,以确保其语义属性忽略:

Modifier.clearAndSetSemantics {}

I assume that in the code you presented above the top level Box represents your "rows". Try firstly merging semantic properties of Box's children and then clearing all of them and setting your custom content description by applying the following modifier to Box:

Modifier
  .semantics(mergeDescendants = true) {}
  .clearAndSetSemantics { contentDescription = "greeting for Android 1" }

Additionally, you could also explicitly call the following on each Box's children to ensure their semantic properties are ignored:

Modifier.clearAndSetSemantics {}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文