Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
)
}
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -198,13 +198,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) },
Expand Down