Fix map tiles in rtl layout

Fix #1333
This commit is contained in:
MM20 2025-04-02 23:26:49 +02:00
parent a85530de42
commit 4d78c3c24d
No known key found for this signature in database
GPG Key ID: 0B61A8F2DEAFA389

View File

@ -29,13 +29,14 @@ import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width import androidx.compose.foundation.layout.width
import androidx.compose.foundation.shape.CircleShape import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material.Text
import androidx.compose.material.icons.Icons import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.rounded.Navigation import androidx.compose.material.icons.rounded.Navigation
import androidx.compose.material.icons.rounded.Place import androidx.compose.material.icons.rounded.Place
import androidx.compose.material3.Icon import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.getValue import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableIntStateOf import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.remember import androidx.compose.runtime.remember
@ -51,9 +52,11 @@ import androidx.compose.ui.graphics.ColorMatrix
import androidx.compose.ui.graphics.FilterQuality import androidx.compose.ui.graphics.FilterQuality
import androidx.compose.ui.layout.onSizeChanged import androidx.compose.ui.layout.onSizeChanged
import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalLayoutDirection
import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.IntOffset import androidx.compose.ui.unit.IntOffset
import androidx.compose.ui.unit.IntSize import androidx.compose.ui.unit.IntSize
import androidx.compose.ui.unit.LayoutDirection
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.times import androidx.compose.ui.unit.times
import coil.ImageLoader import coil.ImageLoader
@ -134,6 +137,9 @@ fun MapTiles(
} else null } else null
} }
CompositionLocalProvider(
LocalLayoutDirection provides LayoutDirection.Ltr
) {
BoxWithConstraints( BoxWithConstraints(
modifier = modifier, modifier = modifier,
contentAlignment = Alignment.Center, contentAlignment = Alignment.Center,
@ -170,7 +176,8 @@ fun MapTiles(
} }
) { (start, stop, zoom) -> ) { (start, stop, zoom) ->
var tileWidth by remember { mutableIntStateOf(0) } var tileWidth by remember { mutableIntStateOf(0) }
Column(modifier = Modifier Column(
modifier = Modifier
.fillMaxWidth() .fillMaxWidth()
// Needed to force all tiles to be the _exact_ same size. With weight(1f) we get rounding errors and gaps. // Needed to force all tiles to be the _exact_ same size. With weight(1f) we get rounding errors and gaps.
.onSizeChanged { tileWidth = it.width / (stop.x - start.x + 1) } .onSizeChanged { tileWidth = it.width / (stop.x - start.x + 1) }
@ -224,7 +231,11 @@ fun MapTiles(
) )
if (userLocation != null) { if (userLocation != null) {
val userIndicatorOffset by animateOffsetAsState( val userIndicatorOffset by animateOffsetAsState(
targetValue = getTileCoordinates(userLocation.lat, userLocation.lon, zoom).let { targetValue = getTileCoordinates(
userLocation.lat,
userLocation.lon,
zoom
).let {
Offset( Offset(
(it.x - start.x) * tileSize.value - 8f, (it.x - start.x) * tileSize.value - 8f,
(it.y - start.y) * tileSize.value - 8f (it.y - start.y) * tileSize.value - 8f
@ -275,13 +286,18 @@ fun MapTiles(
color = MaterialTheme.colorScheme.onSurface, color = MaterialTheme.colorScheme.onSurface,
modifier = Modifier modifier = Modifier
.align(Alignment.BottomEnd) .align(Alignment.BottomEnd)
.background(MaterialTheme.colorScheme.surfaceContainerHigh.copy(alpha = .5f)) .background(
MaterialTheme.colorScheme.surfaceContainerHigh.copy(
alpha = .5f
)
)
.padding(top = 2.dp, bottom = 2.dp, start = 4.dp, end = 4.dp) .padding(top = 2.dp, bottom = 2.dp, start = 4.dp, end = 4.dp)
) )
} }
} }
} }
} }
}
} }
/** /**