diff --git a/features/location/api/src/main/kotlin/io/element/android/features/location/api/StaticMapView.kt b/features/location/api/src/main/kotlin/io/element/android/features/location/api/StaticMapView.kt index 14390d0f4f..03aa21b4c8 100644 --- a/features/location/api/src/main/kotlin/io/element/android/features/location/api/StaticMapView.kt +++ b/features/location/api/src/main/kotlin/io/element/android/features/location/api/StaticMapView.kt @@ -29,12 +29,12 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.layout.ContentScale import androidx.compose.ui.platform.LocalContext -import androidx.compose.ui.unit.IntOffset import androidx.compose.ui.unit.dp import coil.compose.AsyncImagePainter import coil.compose.rememberAsyncImagePainter import coil.request.ImageRequest import io.element.android.features.location.api.internal.StaticMapPlaceholder +import io.element.android.features.location.api.internal.centerBottomEdge import io.element.android.features.location.api.internal.staticMapUrl import io.element.android.libraries.designsystem.preview.DayNightPreviews import io.element.android.libraries.designsystem.preview.ElementPreview @@ -106,13 +106,7 @@ fun StaticMapView( resourceId = DesignSystemR.drawable.pin, contentDescription = null, tint = Color.Unspecified, - modifier = Modifier.align { size, space, _ -> - // Center bottom edge of pin (i.e. its arrow) to center of screen - IntOffset( - x = (space.width - size.width) / 2, - y = (space.height / 2) - size.height, - ) - } + modifier = Modifier.centerBottomEdge(this), ) } else { StaticMapPlaceholder( diff --git a/features/location/api/src/main/kotlin/io/element/android/features/location/api/internal/ModifierCenterBottomEdge.kt b/features/location/api/src/main/kotlin/io/element/android/features/location/api/internal/ModifierCenterBottomEdge.kt new file mode 100644 index 0000000000..7ad299adae --- /dev/null +++ b/features/location/api/src/main/kotlin/io/element/android/features/location/api/internal/ModifierCenterBottomEdge.kt @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2023 New Vector Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.element.android.features.location.api.internal + +import androidx.compose.foundation.layout.BoxScope +import androidx.compose.ui.Modifier +import androidx.compose.ui.unit.IntOffset + +/** + * Horizontally aligns the content to the center of the space. + * Vertically aligns the bottom edge of the content to the center of the space. + */ +fun Modifier.centerBottomEdge(scope: BoxScope): Modifier = with(scope) { + then( + Modifier.align { size, space, _ -> + IntOffset( + x = (space.width - size.width) / 2, + y = (space.height / 2) - size.height, + ) + } + ) +} diff --git a/features/location/impl/src/main/kotlin/io/element/android/features/location/impl/send/SendLocationView.kt b/features/location/impl/src/main/kotlin/io/element/android/features/location/impl/send/SendLocationView.kt index 1a30c996a8..d0e9dfd5aa 100644 --- a/features/location/impl/src/main/kotlin/io/element/android/features/location/impl/send/SendLocationView.kt +++ b/features/location/impl/src/main/kotlin/io/element/android/features/location/impl/send/SendLocationView.kt @@ -43,10 +43,10 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.res.stringResource import androidx.compose.ui.tooling.preview.PreviewParameter -import androidx.compose.ui.unit.IntOffset import androidx.compose.ui.unit.dp import com.mapbox.mapboxsdk.camera.CameraPosition import io.element.android.features.location.api.Location +import io.element.android.features.location.api.internal.centerBottomEdge import io.element.android.features.location.api.internal.rememberTileStyleUrl import io.element.android.features.location.impl.MapDefaults import io.element.android.libraries.designsystem.components.button.BackButton @@ -201,13 +201,7 @@ fun SendLocationView( resourceId = DesignSystemR.drawable.pin, contentDescription = null, tint = Color.Unspecified, - modifier = Modifier.align { size, space, _ -> - // Center bottom edge of pin (i.e. its arrow) to center of screen - IntOffset( - x = (space.width - size.width) / 2, - y = (space.height / 2) - size.height, - ) - } + modifier = Modifier.centerBottomEdge(this), ) FloatingActionButton( onClick = { state.eventSink(SendLocationEvents.SwitchToMyLocationMode) },