Refactor a custom alignment to its own modifier for readability. (#924)
This commit is contained in:
parent
90f91160e2
commit
025d8781a7
3 changed files with 40 additions and 16 deletions
|
|
@ -29,12 +29,12 @@ import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.graphics.Color
|
||||||
import androidx.compose.ui.layout.ContentScale
|
import androidx.compose.ui.layout.ContentScale
|
||||||
import androidx.compose.ui.platform.LocalContext
|
import androidx.compose.ui.platform.LocalContext
|
||||||
import androidx.compose.ui.unit.IntOffset
|
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import coil.compose.AsyncImagePainter
|
import coil.compose.AsyncImagePainter
|
||||||
import coil.compose.rememberAsyncImagePainter
|
import coil.compose.rememberAsyncImagePainter
|
||||||
import coil.request.ImageRequest
|
import coil.request.ImageRequest
|
||||||
import io.element.android.features.location.api.internal.StaticMapPlaceholder
|
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.features.location.api.internal.staticMapUrl
|
||||||
import io.element.android.libraries.designsystem.preview.DayNightPreviews
|
import io.element.android.libraries.designsystem.preview.DayNightPreviews
|
||||||
import io.element.android.libraries.designsystem.preview.ElementPreview
|
import io.element.android.libraries.designsystem.preview.ElementPreview
|
||||||
|
|
@ -106,13 +106,7 @@ fun StaticMapView(
|
||||||
resourceId = DesignSystemR.drawable.pin,
|
resourceId = DesignSystemR.drawable.pin,
|
||||||
contentDescription = null,
|
contentDescription = null,
|
||||||
tint = Color.Unspecified,
|
tint = Color.Unspecified,
|
||||||
modifier = Modifier.align { size, space, _ ->
|
modifier = Modifier.centerBottomEdge(this),
|
||||||
// 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,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
StaticMapPlaceholder(
|
StaticMapPlaceholder(
|
||||||
|
|
|
||||||
|
|
@ -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,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
@ -43,10 +43,10 @@ import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.graphics.Color
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
import androidx.compose.ui.tooling.preview.PreviewParameter
|
import androidx.compose.ui.tooling.preview.PreviewParameter
|
||||||
import androidx.compose.ui.unit.IntOffset
|
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import com.mapbox.mapboxsdk.camera.CameraPosition
|
import com.mapbox.mapboxsdk.camera.CameraPosition
|
||||||
import io.element.android.features.location.api.Location
|
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.api.internal.rememberTileStyleUrl
|
||||||
import io.element.android.features.location.impl.MapDefaults
|
import io.element.android.features.location.impl.MapDefaults
|
||||||
import io.element.android.libraries.designsystem.components.button.BackButton
|
import io.element.android.libraries.designsystem.components.button.BackButton
|
||||||
|
|
@ -201,13 +201,7 @@ fun SendLocationView(
|
||||||
resourceId = DesignSystemR.drawable.pin,
|
resourceId = DesignSystemR.drawable.pin,
|
||||||
contentDescription = null,
|
contentDescription = null,
|
||||||
tint = Color.Unspecified,
|
tint = Color.Unspecified,
|
||||||
modifier = Modifier.align { size, space, _ ->
|
modifier = Modifier.centerBottomEdge(this),
|
||||||
// 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,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
FloatingActionButton(
|
FloatingActionButton(
|
||||||
onClick = { state.eventSink(SendLocationEvents.SwitchToMyLocationMode) },
|
onClick = { state.eventSink(SendLocationEvents.SwitchToMyLocationMode) },
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue