Skip to content

Commit 3cad2bd

Browse files
committed
LicensesContainer.kt: Accessibility improvements
* Use custom actions for TalkBack * Clear semantics for custom actions
1 parent ca0a93e commit 3cad2bd

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

ui/common/src/main/kotlin/com/edricchan/studybuddy/ui/common/licenses/LicensesContainer.kt

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ import androidx.compose.ui.Alignment
6161
import androidx.compose.ui.Modifier
6262
import androidx.compose.ui.platform.LocalUriHandler
6363
import androidx.compose.ui.res.stringResource
64+
import androidx.compose.ui.semantics.CustomAccessibilityAction
65+
import androidx.compose.ui.semantics.clearAndSetSemantics
66+
import androidx.compose.ui.semantics.customActions
67+
import androidx.compose.ui.semantics.semantics
6468
import androidx.compose.ui.tooling.preview.Preview
6569
import androidx.compose.ui.tooling.preview.PreviewParameter
6670
import androidx.compose.ui.tooling.preview.datasource.LoremIpsum
@@ -106,7 +110,35 @@ fun LibraryItem(
106110
val labelViewWebsite = stringResource(R.string.licenses_action_view_website_url)
107111

108112
Surface(
109-
modifier = modifier,
113+
modifier = modifier.semantics {
114+
customActions = listOfNotNull(
115+
CustomAccessibilityAction(
116+
label = labelViewLicense,
117+
action = {
118+
onClick()
119+
true
120+
}
121+
),
122+
lib.scm?.url?.takeIf { it.isNotBlank() }?.let {
123+
CustomAccessibilityAction(
124+
label = labelViewScm,
125+
action = {
126+
onLinkClick(it)
127+
true
128+
}
129+
)
130+
},
131+
lib.website?.takeIf { it.isNotBlank() }?.let {
132+
CustomAccessibilityAction(
133+
label = labelViewWebsite,
134+
action = {
135+
onLinkClick(it)
136+
true
137+
}
138+
)
139+
}
140+
)
141+
},
110142
onClick = onClick,
111143
shape = MaterialTheme.shapes.large,
112144
color = MaterialTheme.colorScheme.surfaceContainer
@@ -164,7 +196,8 @@ fun LibraryItem(
164196
ButtonGroup(
165197
modifier = Modifier
166198
.fillMaxWidth()
167-
.padding(top = 14.dp),
199+
.padding(top = 14.dp)
200+
.clearAndSetSemantics {},
168201
overflowIndicator = {
169202
ButtonGroupDefaults.OverflowIndicator(
170203
menuState = it

ui/common/src/main/res/values/license_strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<resources>
3+
<string name="licenses_action_view_license_text_url">View License Text</string>
34
<string name="licenses_action_view_scm_url">View Source</string>
45
<string name="licenses_action_view_website_url">View Website</string>
56

0 commit comments

Comments
 (0)