Browse Source

Refactor a custom alignment to its own modifier for readability. (#924)

pull/929/head
Marco Romano 1 year ago committed by GitHub
parent
commit
f614895ec1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 10
      features/location/api/src/main/kotlin/io/element/android/features/location/api/StaticMapView.kt
  2. 36
      features/location/api/src/main/kotlin/io/element/android/features/location/api/internal/ModifierCenterBottomEdge.kt
  3. 10
      features/location/impl/src/main/kotlin/io/element/android/features/location/impl/send/SendLocationView.kt

10
features/location/api/src/main/kotlin/io/element/android/features/location/api/StaticMapView.kt

@ -29,12 +29,12 @@ import androidx.compose.ui.Modifier @@ -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( @@ -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(

36
features/location/api/src/main/kotlin/io/element/android/features/location/api/internal/ModifierCenterBottomEdge.kt

@ -0,0 +1,36 @@ @@ -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,
)
}
)
}

10
features/location/impl/src/main/kotlin/io/element/android/features/location/impl/send/SendLocationView.kt

@ -43,10 +43,10 @@ import androidx.compose.ui.Modifier @@ -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( @@ -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) },

Loading…
Cancel
Save