Status Update
Comments
pa...@hinge.co <pa...@hinge.co> #2
Hi. Thanks for reporting this. Fixed in alpha-04
pa...@hinge.co <pa...@hinge.co> #3
Branch: androidx-main
commit e782987543a9f8ccd485e970ddc74564b24378db
Author: Vighnesh Raut <vighnesh.raut13@gmail.com>
Date: Mon Jan 02 15:27:40 2023
fix: tab row crashes when only 1 tab is added
Bug:
Test: Added unit test
Change-Id: I6381dbac304fc1d69d3708c6655f8b595668e93f
M tv/tv-material/src/androidTest/java/androidx/tv/material/TabRowTest.kt
M tv/tv-material/src/main/java/androidx/tv/material/TabRow.kt
kl...@google.com <kl...@google.com>
kl...@google.com <kl...@google.com> #4
si...@google.com <si...@google.com>
kl...@google.com <kl...@google.com> #5
The following release(s) address this bug.It is possible this bug has only been partially addressed:
androidx.tv:tv-material:1.0.0-alpha04
kl...@google.com <kl...@google.com> #6
It does not seem to be possible to override ClickableSpan
's getId()
method, which means that the only way to make this work is to actually use the same instance across a11y string conversions.
kl...@google.com <kl...@google.com> #7
We don't need to call enableAccessibleClickableSpanSupport
because AndroidComposeView
is already using the a11y delegate compat stuff. This will be fixed in
ap...@google.com <ap...@google.com> #8
Branch: androidx-main
commit 41183c41f686979fb051549196f7b06cc172022b
Author: Zach Klippenstein <klippenstein@google.com>
Date: Fri Mar 17 16:33:38 2023
Fix UrlAnnotation links not being opened by a11y services.
Relnote: "`UrlAnnotation`s in `AnnotatedString`s can now be opened via
accessibility services like TalkBack."
Test: AndroidAccessibilitySpannableStringTest.kt
Test: Manually with TalkBack
Fixes:
Change-Id: If4d82999d8c62aa3718e1e681eeeaac12a9b0f55
M compose/foundation/foundation/integration-tests/foundation-demos/src/main/java/androidx/compose/foundation/demos/text/ComposeTextAccessibility.kt
M compose/ui/ui-text/api/public_plus_experimental_current.txt
M compose/ui/ui-text/src/androidAndroidTest/kotlin/androidx/compose/ui/text/platform/AndroidAccessibilitySpannableStringTest.kt
M compose/ui/ui-text/src/androidMain/kotlin/androidx/compose/ui/text/platform/AndroidAccessibilitySpannableString.android.kt
A compose/ui/ui-text/src/androidMain/kotlin/androidx/compose/ui/text/platform/URLSpanCache.kt
D compose/ui/ui-text/src/androidMain/kotlin/androidx/compose/ui/text/platform/extensions/UrlAnnotationExtensions.android.kt
M compose/ui/ui/src/androidMain/kotlin/androidx/compose/ui/platform/AndroidComposeViewAccessibilityDelegateCompat.android.kt
na...@google.com <na...@google.com> #9
The following release(s) address this bug.It is possible this bug has only been partially addressed:
androidx.compose.foundation:foundation:1.5.0-alpha02
androidx.compose.ui:ui:1.5.0-alpha02
androidx.compose.ui:ui-text:1.5.0-alpha02
ju...@google.com <ju...@google.com> #10
The following release(s) address this bug.It is possible this bug has only been partially addressed:
androidx.compose.ui:ui-text-android:1.5.0-beta01
sv...@gmail.com <sv...@gmail.com> #11
Versions:
androidx.compose.ui:ui-text-android:1.5.1
androidx.compose.foundation:foundation:1.5.1
androidx.compose.ui:ui:1.5.1
androidx.compose.ui:ui-text:1.5.1
fu...@gmail.com <fu...@gmail.com> #12
fu...@gmail.com <fu...@gmail.com> #13
The issue is only fixed in URL redirection case but not custom action case, looks there will be
a LinkAnnotation
added in 1.7.0 for it.
In case anyone need solution now or unable to use newest compose version, might try these approaches:
Use customActions
instead of link
@OptIn(ExperimentalTextApi::class)
@Composable
fun TestInlineLink1() = Column(
modifier = Modifier.fillMaxWidth(),
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally,
) {
var result by remember { mutableStateOf("") }
fun action(tag: String) {
result = "Inline link [ $tag ] get clicked"
}
val text = buildAnnotatedString {
append("This is an example for ")
withAnnotation(tag = "link1", annotation = "link1") {
append("link1")
}
append(" and ")
withAnnotation(tag = "link2", annotation = "link2") {
append("link2")
}
}
ClickableText(
modifier = Modifier.semantics {
customActions = listOf(
CustomAccessibilityAction("link1") {
action("link1")
true
},
CustomAccessibilityAction("link2") {
action("link2")
true
},
)
},
text = text,
onClick = { offset ->
val tag = text.getStringAnnotations(offset, offset)
.singleOrNull()?.tag
tag?.let(::action)
}
)
Text(text = result)
}
Modify AccessibilityNodeInfo
@OptIn(ExperimentalTextApi::class)
@Composable
fun TestInlineLink2() = Column(
modifier = Modifier.fillMaxWidth(),
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally,
) {
var result by remember { mutableStateOf("") }
fun action(tag: String) {
result = "Inline link [ $tag ] get clicked"
}
val text = buildAnnotatedString {
append("This is an example for ")
withAnnotation(urlAnnotation = UrlAnnotation(url = "link1")) {
append("link1")
}
append(" and ")
withAnnotation(urlAnnotation = UrlAnnotation(url = "link2")) {
append("link2")
}
}
WrappingView {
ReplaceAccessibilityNodeInfoText(
text = text.toSpannableString(::action)
)
ClickableText(
text = text,
onClick = { offset ->
val tag = text.getUrlAnnotations(offset, offset)
.singleOrNull()?.item?.url
tag?.let(::action)
},
)
}
Text(text = result)
}
@Composable
private fun ReplaceAccessibilityNodeInfoText(
text: CharSequence,
) {
val view = LocalView.current
val defaultDelegate = ViewCompat.getAccessibilityDelegate(view)
val newDelegate = object : AccessibilityDelegateCompat() {
override fun onInitializeAccessibilityNodeInfo(
host: View,
info: AccessibilityNodeInfoCompat,
) {
defaultDelegate?.onInitializeAccessibilityNodeInfo(host, info)
info.text = text
}
}
ViewCompat.setAccessibilityDelegate(view, newDelegate)
}
/**
* use AndroidView to create an AndroidComposeView,
* aim to prevent modify accessibilityDelegate of outer view.
*/
@Composable
private fun WrappingView(
modifier: Modifier = Modifier,
content: @Composable () -> Unit,
) {
AndroidView(
modifier = modifier,
factory = { context ->
ComposeView(context).apply {
setContent(content)
}
}
)
}
@OptIn(ExperimentalTextApi::class)
private fun AnnotatedString.toSpannableString(
action: (String) -> Unit
) = buildSpannedString {
append(this@toSpannableString)
getUrlAnnotations(0, length).forEach { (item, start, end, _) ->
setSpan(
object : ClickableSpan() {
override fun onClick(widget: View) {
action(item.url)
}
},
start, end, SPAN_INCLUSIVE_EXCLUSIVE
)
}
}
Description
- Jetpack Compose component used: ClickableText with AnnotatedString including UrlAnnotation
- Android Studio Build: Android Studio Chipmunk | 2021.2.1 Patch 2
Build #AI-212.5712.43.2112.8815526, built on July 10, 2022
- Kotlin version: 1.7.20
- Devices/Android versions reproduced on: Android 30, 33 on Pixel 4As
- Keyboard (i.e. Gboard, Samsung, etc): Stock Google keyboard
If this is a bug in the library, we would appreciate if you could attach:
- Sample project to trigger the issue:
- A screenrecord or screenshots showing the issue (if UI related). This is included with the sample project but I attached it again here.
- Stack trace (if applicable) - N/A
There is a bug where the recently introduced UrlAnnotation is read correctly by Talkback, but the onClick is not called, so the link is not opened.
Steps to Reproduce:
1. Turn on Talkback in Accessibility settings
2. Run app
3. App will display a single line of text
4. Part of this text will be a URLAnnotation containing a link
5. Open the Talkback action menu per the prompt
6. Select "Links" in Talkback menu
7. Select the link to trigger the onClick method call, which opens the browser.
Expected:
1.Talkback correctly recognizes the link in the text
2. Talkback shows the link in the Talkback menu
3. When the link is selected in the Talkback menu, the onClick is called in ClickableText and the user is navigated to the browser.
Actual:
1. The onClick for the ClickableText is never called. Note that it is not the browser navigation that is broken. This can be confirmed using the logs in the sample app provided.