From 955a545f250e0194e4dc6641e5d1b49289816637 Mon Sep 17 00:00:00 2001 From: jhg3410 <80373033+jhg3410@users.noreply.github.com> Date: Sun, 26 Feb 2023 17:46:43 +0900 Subject: [PATCH] #10 - Custom actions --- .../com/example/jetnews/ui/home/PostCards.kt | 26 ++++++++++++++----- 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/AccessibilityCodelab/app/src/main/java/com/example/jetnews/ui/home/PostCards.kt b/AccessibilityCodelab/app/src/main/java/com/example/jetnews/ui/home/PostCards.kt index 64be9ae..6e351b8 100644 --- a/AccessibilityCodelab/app/src/main/java/com/example/jetnews/ui/home/PostCards.kt +++ b/AccessibilityCodelab/app/src/main/java/com/example/jetnews/ui/home/PostCards.kt @@ -29,8 +29,7 @@ import androidx.compose.ui.draw.clip import androidx.compose.ui.layout.ContentScale import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.stringResource -import androidx.compose.ui.semantics.onClick -import androidx.compose.ui.semantics.semantics +import androidx.compose.ui.semantics.* import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp @@ -43,10 +42,22 @@ import com.example.jetnews.ui.theme.JetnewsTheme @Composable fun PostCardHistory(post: Post, navigateToArticle: (String) -> Unit) { var openDialog by remember { mutableStateOf(false) } + val showFewerLabel = stringResource(R.string.cd_show_fewer) Row( - Modifier.clickable( - onClickLabel = stringResource(id = R.string.action_read_article) - ) { navigateToArticle(post.id) } + Modifier + .clickable( + onClickLabel = stringResource(id = R.string.action_read_article) + ) { + navigateToArticle(post.id) + } + .semantics { + customActions = listOf( + CustomAccessibilityAction( + label = showFewerLabel, + action = { openDialog = true; true } + ) + ) + } ) { Image( painter = painterResource(post.imageThumbId), @@ -77,7 +88,10 @@ fun PostCardHistory(post: Post, navigateToArticle: (String) -> Unit) { } } CompositionLocalProvider(LocalContentAlpha provides ContentAlpha.medium) { - IconButton(onClick = { openDialog = true }) { + IconButton( + modifier = Modifier.clearAndSetSemantics { }, + onClick = { openDialog = true } + ) { Icon( imageVector = Icons.Default.Close, contentDescription = stringResource(R.string.cd_show_fewer)