Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: JinCodeGitHub/compose-samples
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: main
Choose a base ref
...
head repository: JinCodeGitHub/compose-samples
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: jv/jn_a11y
Choose a head ref
  • 2 commits
  • 3 files changed
  • 1 contributor

Commits on Dec 10, 2020

  1. Copy the full SHA
    0db0ba3 View commit details
  2. Copy the full SHA
    caf2983 View commit details
Original file line number Diff line number Diff line change
@@ -49,6 +49,7 @@ import androidx.compose.ui.graphics.ColorFilter
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.layout.FirstBaseline
import androidx.compose.ui.platform.AmbientDensity
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.text.ParagraphStyle
import androidx.compose.ui.text.SpanStyle
@@ -114,7 +115,7 @@ private fun PostHeaderImage(post: Post) {
@Composable
private fun PostMetadata(metadata: Metadata) {
val typography = MaterialTheme.typography
Row {
Row(modifier = Modifier.semantics(mergeDescendants = true) {}) {
Image(
imageVector = Icons.Filled.AccountCircle,
modifier = Modifier.preferredSize(40.dp),
Original file line number Diff line number Diff line change
@@ -38,6 +38,11 @@ import androidx.compose.runtime.Providers
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.res.imageResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.semantics.CustomAccessibilityAction
import androidx.compose.ui.semantics.customActions
import androidx.compose.ui.semantics.hidden
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.example.jetnews.R
@@ -90,9 +95,17 @@ fun PostCardSimple(
isFavorite: Boolean,
onToggleFavorite: () -> Unit
) {
val bookmarkActionLabel =
stringResource(if (isFavorite) R.string.action_add_bookmark else R.string.action_remove_bookmark)
Row(
modifier = Modifier.clickable(onClick = { navigateTo(Screen.Article(post.id)) })
.padding(16.dp)
.semantics(mergeDescendants = true) {
customActions = listOf(CustomAccessibilityAction(
label = bookmarkActionLabel,
action = { onToggleFavorite(); true }
))
}
) {
PostImage(post, Modifier.padding(end = 16.dp))
Column(modifier = Modifier.weight(1f)) {
@@ -101,7 +114,8 @@ fun PostCardSimple(
}
BookmarkButton(
isBookmarked = isFavorite,
onClick = onToggleFavorite
onClick = onToggleFavorite,
modifier = Modifier.semantics { hidden() }
)
}
}
2 changes: 2 additions & 0 deletions JetNews/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -16,4 +16,6 @@
<string name="app_name">Jetnews</string>
<string name="load_error">Can\'t update latest news</string>
<string name="retry">Retry</string>
<string name="action_add_bookmark">Add to bookmarks</string>
<string name="action_remove_bookmark">Remove from bookmarks</string>
</resources>