mirror of
https://github.com/Novaloop-AG/element-x-android.git
synced 2026-11-03 06:55:41 +00:00
Try fixing flaky screenshots for location timeline items
Replace the `rememberAsyncImagePainter` call when in preview mode with fake values
This commit is contained in:
+43
-24
@@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
package io.element.android.features.location.api
|
package io.element.android.features.location.api
|
||||||
|
|
||||||
|
import android.graphics.Bitmap
|
||||||
import androidx.compose.foundation.Image
|
import androidx.compose.foundation.Image
|
||||||
import androidx.compose.foundation.layout.Box
|
import androidx.compose.foundation.layout.Box
|
||||||
import androidx.compose.foundation.layout.BoxWithConstraints
|
import androidx.compose.foundation.layout.BoxWithConstraints
|
||||||
@@ -24,13 +25,17 @@ import androidx.compose.ui.Modifier
|
|||||||
import androidx.compose.ui.layout.ContentScale
|
import androidx.compose.ui.layout.ContentScale
|
||||||
import androidx.compose.ui.platform.LocalContext
|
import androidx.compose.ui.platform.LocalContext
|
||||||
import androidx.compose.ui.platform.LocalDensity
|
import androidx.compose.ui.platform.LocalDensity
|
||||||
|
import androidx.compose.ui.platform.LocalInspectionMode
|
||||||
import androidx.compose.ui.res.painterResource
|
import androidx.compose.ui.res.painterResource
|
||||||
import androidx.compose.ui.unit.Dp
|
import androidx.compose.ui.unit.Dp
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
|
import androidx.core.graphics.createBitmap
|
||||||
import coil3.Extras
|
import coil3.Extras
|
||||||
|
import coil3.asImage
|
||||||
import coil3.compose.AsyncImagePainter
|
import coil3.compose.AsyncImagePainter
|
||||||
import coil3.compose.rememberAsyncImagePainter
|
import coil3.compose.rememberAsyncImagePainter
|
||||||
import coil3.request.ImageRequest
|
import coil3.request.ImageRequest
|
||||||
|
import coil3.request.SuccessResult
|
||||||
import io.element.android.compound.theme.ElementTheme
|
import io.element.android.compound.theme.ElementTheme
|
||||||
import io.element.android.features.location.api.internal.StaticMapPlaceholder
|
import io.element.android.features.location.api.internal.StaticMapPlaceholder
|
||||||
import io.element.android.features.location.api.internal.StaticMapUrlBuilder
|
import io.element.android.features.location.api.internal.StaticMapUrlBuilder
|
||||||
@@ -128,32 +133,46 @@ private fun BoxWithConstraintsScope.LoadableMapContent(
|
|||||||
var retryHash by remember { mutableIntStateOf(0) }
|
var retryHash by remember { mutableIntStateOf(0) }
|
||||||
val builder = remember { StaticMapUrlBuilder() }
|
val builder = remember { StaticMapUrlBuilder() }
|
||||||
|
|
||||||
val painter = rememberAsyncImagePainter(
|
val (painter, state) = if (LocalInspectionMode.current) {
|
||||||
model = if (constraints.isZero) {
|
val painter = painterResource(R.drawable.blurred_map)
|
||||||
// Avoid building a URL if any of the size constraints is zero
|
val state = AsyncImagePainter.State.Success(
|
||||||
null
|
painter = painter,
|
||||||
} else {
|
result = SuccessResult(
|
||||||
ImageRequest.Builder(context)
|
image = createBitmap(1, 1, Bitmap.Config.ALPHA_8).asImage(),
|
||||||
.data(
|
request = ImageRequest.Builder(context).build()
|
||||||
builder.build(
|
)
|
||||||
lat = location.lat,
|
)
|
||||||
lon = location.lon,
|
painter to state
|
||||||
zoom = zoom,
|
} else {
|
||||||
darkMode = darkMode,
|
val painter = rememberAsyncImagePainter(
|
||||||
width = constraints.maxWidth,
|
model = if (constraints.isZero) {
|
||||||
height = constraints.maxHeight,
|
// Avoid building a URL if any of the size constraints is zero
|
||||||
density = LocalDensity.current.density,
|
null
|
||||||
|
} else {
|
||||||
|
ImageRequest.Builder(context)
|
||||||
|
.data(
|
||||||
|
builder.build(
|
||||||
|
lat = location.lat,
|
||||||
|
lon = location.lon,
|
||||||
|
zoom = zoom,
|
||||||
|
darkMode = darkMode,
|
||||||
|
width = constraints.maxWidth,
|
||||||
|
height = constraints.maxHeight,
|
||||||
|
density = LocalDensity.current.density,
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
.size(width = constraints.maxWidth, height = constraints.maxHeight)
|
||||||
.size(width = constraints.maxWidth, height = constraints.maxHeight)
|
.apply {
|
||||||
.apply {
|
extras.set(Extras.Key("retry_hash"), retryHash).build()
|
||||||
extras.set(Extras.Key("retry_hash"), retryHash).build()
|
}
|
||||||
}
|
.build()
|
||||||
.build()
|
}
|
||||||
}
|
)
|
||||||
)
|
|
||||||
|
val state by painter.state.collectAsState()
|
||||||
|
painter to state
|
||||||
|
}
|
||||||
|
|
||||||
val state by painter.state.collectAsState()
|
|
||||||
when (state) {
|
when (state) {
|
||||||
is AsyncImagePainter.State.Success -> {
|
is AsyncImagePainter.State.Success -> {
|
||||||
Image(
|
Image(
|
||||||
|
|||||||
Reference in New Issue
Block a user