[fenix] For https://github.com/mozilla-mobile/fenix/issues/27129 - Fix accessibility for default wallpaper thumbnail

pull/600/head
Alexandru2909 2 years ago committed by mergify[bot]
parent c326970961
commit 63841d70c4

@ -40,6 +40,8 @@ import androidx.compose.ui.graphics.asImageBitmap
import androidx.compose.ui.layout.ContentScale import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.platform.LocalConfiguration import androidx.compose.ui.platform.LocalConfiguration
import androidx.compose.ui.res.stringResource import androidx.compose.ui.res.stringResource
import androidx.compose.ui.semantics.contentDescription
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.text.style.TextDecoration import androidx.compose.ui.text.style.TextDecoration
import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
@ -257,6 +259,21 @@ private fun WallpaperThumbnailItem(
// Completely avoid drawing the item if a bitmap cannot be loaded and is required // Completely avoid drawing the item if a bitmap cannot be loaded and is required
if (bitmap == null && wallpaper != defaultWallpaper) return if (bitmap == null && wallpaper != defaultWallpaper) return
val description = stringResource(
R.string.wallpapers_item_name_content_description,
wallpaper.name,
)
// For the default wallpaper to be accessible, we should set the content description for
// the Surface instead of the thumbnail image
val contentDescriptionModifier = if (bitmap == null) {
Modifier.semantics {
contentDescription = description
}
} else {
Modifier
}
Surface( Surface(
elevation = 4.dp, elevation = 4.dp,
shape = thumbnailShape, shape = thumbnailShape,
@ -265,16 +282,14 @@ private fun WallpaperThumbnailItem(
.fillMaxWidth() .fillMaxWidth()
.aspectRatio(aspectRatio) .aspectRatio(aspectRatio)
.then(border) .then(border)
.clickable { onSelect(wallpaper) }, .clickable { onSelect(wallpaper) }
.then(contentDescriptionModifier),
) { ) {
bitmap?.let { bitmap?.let {
Image( Image(
bitmap = it.asImageBitmap(), bitmap = it.asImageBitmap(),
contentScale = ContentScale.FillBounds, contentScale = ContentScale.FillBounds,
contentDescription = stringResource( contentDescription = description,
R.string.wallpapers_item_name_content_description,
wallpaper.name,
),
modifier = Modifier.fillMaxSize(), modifier = Modifier.fillMaxSize(),
alpha = if (isLoading) loadingOpacity else 1.0f, alpha = if (isLoading) loadingOpacity else 1.0f,
) )

Loading…
Cancel
Save