Skip to content

Commit

Permalink
#10 - Custom actions
Browse files Browse the repository at this point in the history
  • Loading branch information
jhg3410 committed Feb 26, 2023
1 parent 1f41c72 commit 955a545
Showing 1 changed file with 20 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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),
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 955a545

Please sign in to comment.