Merge pull request #6954 from element-hq/fix/try-fixing-flaky-location-timeline-item-screenshots

Try fixing flaky screenshots for location timeline items
This commit is contained in:
Benoit Marty
2026-06-10 14:44:39 +02:00
committed by GitHub
13 changed files with 65 additions and 45 deletions
@@ -8,6 +8,7 @@
package io.element.android.features.location.api
import android.graphics.Bitmap
import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.Box
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.platform.LocalContext
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.platform.LocalInspectionMode
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import androidx.core.graphics.createBitmap
import coil3.Extras
import coil3.asImage
import coil3.compose.AsyncImagePainter
import coil3.compose.rememberAsyncImagePainter
import coil3.request.ImageRequest
import coil3.request.SuccessResult
import io.element.android.compound.theme.ElementTheme
import io.element.android.features.location.api.internal.StaticMapPlaceholder
import io.element.android.features.location.api.internal.StaticMapUrlBuilder
@@ -39,6 +44,7 @@ import io.element.android.libraries.designsystem.components.LocationPin
import io.element.android.libraries.designsystem.components.PinVariant
import io.element.android.libraries.designsystem.preview.ElementPreview
import io.element.android.libraries.designsystem.preview.PreviewsDayNight
import io.element.android.libraries.designsystem.utils.CommonDrawables
/**
* Shows a static map image downloaded via a third party service's static maps API.
@@ -128,32 +134,46 @@ private fun BoxWithConstraintsScope.LoadableMapContent(
var retryHash by remember { mutableIntStateOf(0) }
val builder = remember { StaticMapUrlBuilder() }
val painter = rememberAsyncImagePainter(
model = if (constraints.isZero) {
// Avoid building a URL if any of the size constraints is zero
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,
val (painter, state, contentScale) = if (LocalInspectionMode.current) {
val painter = painterResource(CommonDrawables.sample_map)
val state = AsyncImagePainter.State.Success(
painter = painter,
result = SuccessResult(
image = createBitmap(1, 1, Bitmap.Config.ALPHA_8).asImage(),
request = ImageRequest.Builder(context).build()
)
)
Triple(painter, state, ContentScale.Crop)
} else {
val painter = rememberAsyncImagePainter(
model = if (constraints.isZero) {
// Avoid building a URL if any of the size constraints is zero
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)
.apply {
extras.set(Extras.Key("retry_hash"), retryHash).build()
}
.build()
}
)
.size(width = constraints.maxWidth, height = constraints.maxHeight)
.apply {
extras.set(Extras.Key("retry_hash"), retryHash).build()
}
.build()
}
)
val state by painter.state.collectAsState()
Triple(painter, state, ContentScale.Fit)
}
val state by painter.state.collectAsState()
when (state) {
is AsyncImagePainter.State.Success -> {
Image(
@@ -162,7 +182,7 @@ private fun BoxWithConstraintsScope.LoadableMapContent(
modifier = Modifier.size(width = maxWidth, height = maxHeight),
// The returned image can be smaller than the requested size due to the static maps API having
// a max width and height of 2048 px. We apply ContentScale.Fit to handle this.
contentScale = ContentScale.Fit,
contentScale = contentScale,
)
LocationPin(variant = pinVariant, modifier = Modifier.centerBottomEdge(this))
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 318 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 595 KiB

@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:56a86695d2c25c94a8e79c27c8f525229cc348201073566909f83a681b37ac30
size 251329
oid sha256:69ffc87be8fc643d3cd553eb86140a9654ccac92d205b93e428d8631f2a770a3
size 408053
@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:0c2b2a7071bd1c21ff706525e2416169507fef364485c651c429baefa15d4c9f
size 104240
oid sha256:7b2af9381e91c470a87d5585fd211b1f1ffdc4d56876285f73765a5ccd5ce72c
size 147867
@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:3daba890afd2533e1746f1ffd0c535674a4a238e4591da2a6bcbe31716d26858
size 143676
oid sha256:2ae9812763faa89524be29c0b796479c51092e570d31667bfbb7209e901dca83
size 225821
@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:b9f2f0e8ba6829cb3d83dcc0c6d3ed5a91a0346771f84adb6731ba5fdac01f4d
size 122009
oid sha256:ab6262a03bbe7e4ff33ad1c0655652b58a78cbf6aa0a2e4a8f794f7b347cfff7
size 197616
@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:7f85b9e88dca466b567769291fb69afac535135c3a07f412d6b8203968460519
size 120940
oid sha256:1a8c03a738592d5ad555e1cbd07b5169edc45de18044dee9139dd15763d58468
size 197204
@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:463a2e544b2806f4082c813ec3ba8c6ce0ad0ebcd8ee32666806757a90c248f5
size 57131
oid sha256:d761883dee687ae4917949d64b5f6fe13daf1d54ce8ee05785967c4906078560
size 80994
@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:00da192b3b46897c9d50986ecd84e07332cd2b490ebc8f3893a9497e72f18af8
size 41478
oid sha256:848201daee4c16c24dd6d29f6244ac24d197832c43168bb5d76245ebdaf0d643
size 73421
@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:c015bae5b3ce8c4447c62a13fb74d855c23b0e41bf0b128a1834d30781c0d1f8
size 41110
oid sha256:aa9d77577784fe54259902d90d447ca253de22c2a9f8e62d767456a5d52179f5
size 73006
@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:f90a31ccde2880e01393be2bd36e9554d8087aa52bfe36e29b8514a32fea3dcd
size 752143
oid sha256:7c07f6bff1e3c3626ec2bb5ecbdb3f17931a8ba1ea01e93b6d14594b9ba11639
size 534417
@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:a853885aac641afe3fb28f3a1d9ebf6744862f153ea22bc2d511ff957b814a19
size 747294
oid sha256:122b56f230efcad08fef31e50709dfaf4315befcc119e65c08b71c52404d87c7
size 216117