mirror of
https://github.com/Novaloop-AG/element-x-android.git
synced 2026-11-03 16:10:00 +00:00
Improve static map preview / screenshots.
This commit is contained in:
+6
-5
@@ -44,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.components.PinVariant
|
||||||
import io.element.android.libraries.designsystem.preview.ElementPreview
|
import io.element.android.libraries.designsystem.preview.ElementPreview
|
||||||
import io.element.android.libraries.designsystem.preview.PreviewsDayNight
|
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.
|
* Shows a static map image downloaded via a third party service's static maps API.
|
||||||
@@ -133,8 +134,8 @@ 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, state) = if (LocalInspectionMode.current) {
|
val (painter, state, contentScale) = if (LocalInspectionMode.current) {
|
||||||
val painter = painterResource(R.drawable.blurred_map)
|
val painter = painterResource(CommonDrawables.sample_map)
|
||||||
val state = AsyncImagePainter.State.Success(
|
val state = AsyncImagePainter.State.Success(
|
||||||
painter = painter,
|
painter = painter,
|
||||||
result = SuccessResult(
|
result = SuccessResult(
|
||||||
@@ -142,7 +143,7 @@ private fun BoxWithConstraintsScope.LoadableMapContent(
|
|||||||
request = ImageRequest.Builder(context).build()
|
request = ImageRequest.Builder(context).build()
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
painter to state
|
Triple(painter, state, ContentScale.Crop)
|
||||||
} else {
|
} else {
|
||||||
val painter = rememberAsyncImagePainter(
|
val painter = rememberAsyncImagePainter(
|
||||||
model = if (constraints.isZero) {
|
model = if (constraints.isZero) {
|
||||||
@@ -170,7 +171,7 @@ private fun BoxWithConstraintsScope.LoadableMapContent(
|
|||||||
)
|
)
|
||||||
|
|
||||||
val state by painter.state.collectAsState()
|
val state by painter.state.collectAsState()
|
||||||
painter to state
|
Triple(painter, state, ContentScale.Fit)
|
||||||
}
|
}
|
||||||
|
|
||||||
when (state) {
|
when (state) {
|
||||||
@@ -181,7 +182,7 @@ private fun BoxWithConstraintsScope.LoadableMapContent(
|
|||||||
modifier = Modifier.size(width = maxWidth, height = maxHeight),
|
modifier = Modifier.size(width = maxWidth, height = maxHeight),
|
||||||
// The returned image can be smaller than the requested size due to the static maps API having
|
// 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.
|
// 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))
|
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 |
Reference in New Issue
Block a user