Skip to content
This repository has been archived by the owner on Feb 20, 2023. It is now read-only.

Commit

Permalink
fixes #23644: reload wallpapers on orientation change
Browse files Browse the repository at this point in the history
  • Loading branch information
MatthewTighe authored and mergify[bot] committed Feb 11, 2022
1 parent 1160177 commit 9643e96
Showing 1 changed file with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,16 @@ import androidx.compose.material.Text
import androidx.compose.material.TextButton
import androidx.compose.material.rememberScaffoldState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.asImageBitmap
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.platform.LocalConfiguration
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.Font
Expand Down Expand Up @@ -204,6 +210,10 @@ private fun WallpaperThumbnailItem(
aspectRatio: Float = 1.1f,
onSelect: (Wallpaper) -> Unit
) {
var bitmap by remember { mutableStateOf(loadWallpaperResource(wallpaper)) }
DisposableEffect(LocalConfiguration.current.orientation) {
onDispose { bitmap = loadWallpaperResource(wallpaper) }
}
val thumbnailShape = RoundedCornerShape(8.dp)
val border = if (isSelected) {
Modifier.border(
Expand All @@ -214,9 +224,9 @@ private fun WallpaperThumbnailItem(
Modifier
}

val bitmap = loadWallpaperResource(wallpaper)
// Completely avoid drawing the item if a bitmap cannot be loaded and is required
if (bitmap == null && wallpaper != defaultWallpaper) return

Surface(
elevation = 4.dp,
shape = thumbnailShape,
Expand All @@ -228,9 +238,9 @@ private fun WallpaperThumbnailItem(
.then(border)
.clickable { onSelect(wallpaper) }
) {
if (bitmap != null) {
bitmap?.let {
Image(
bitmap = bitmap.asImageBitmap(),
bitmap = it.asImageBitmap(),
contentScale = ContentScale.FillBounds,
contentDescription = stringResource(
R.string.wallpapers_item_name_content_description, wallpaper.name
Expand Down

0 comments on commit 9643e96

Please sign in to comment.