Fix crash in NearbyDialog due to missing screen height

This commit is contained in:
Olof Hedman
2025-09-23 14:49:01 +02:00
parent d9eef1338a
commit 5d8d620811
4 changed files with 58 additions and 11 deletions

View File

@@ -0,0 +1,9 @@
package app.klottr.platform
import androidx.compose.runtime.Composable
import androidx.compose.ui.unit.Dp
/**
* Platform-agnostic screen height in dp for sizing dialogs proportionally.
*/
@Composable expect fun platformScreenHeightDp(): Dp

View File

@@ -5,6 +5,7 @@ import androidx.compose.foundation.background
import androidx.compose.foundation.gestures.detectTransformGestures
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.requiredHeightIn
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
@@ -14,8 +15,6 @@ import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.widthIn
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.Button
@@ -43,6 +42,7 @@ import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.Dialog
import androidx.compose.ui.window.DialogProperties
import app.klottr.platform.platformScreenHeightDp
import app.klottr.nearby.FoundOpenAction
import app.klottr.nearby.NearbyEntryShared
import app.klottr.net.DigitaltMuseumItem
@@ -78,18 +78,24 @@ fun NearbyDialog(
title = { Text("Närliggande") },
text = {
val hasLocation = (lat != null && lon != null)
val scroll = rememberScrollState()
// Cap to caller-provided height or ~75% of the real screen height (platform-agnostic).
val percentageCap = (platformScreenHeightDp() * 0.75f)
val cap = (maxHeight ?: percentageCap).coerceAtLeast(320.dp)
val container = @Composable { inner: @Composable () -> Unit ->
if (maxHeight != null) {
Box(Modifier.widthIn(min = 280.dp).height(maxHeight)) {
Column(Modifier.fillMaxSize().verticalScroll(scroll)) { inner() }
}
} else {
Column(Modifier.widthIn(min = 280.dp).verticalScroll(scroll)) { inner() }
// Bound the height BEFORE measuring child content; do NOT add verticalScroll here.
Box(
Modifier
.widthIn(min = 280.dp)
.requiredHeightIn(max = cap)
) {
// Let inner content (NearbyList) own scrolling; fill available space.
Column(Modifier.fillMaxSize()) { inner() }
}
}
//TODO: MaxHeight should be calculated as it was in the original
NearbyDialogContent(maxHeight = 580.dp) {
NearbyDialogContent(maxHeight = cap) {
container {
NearbyContent(
loading = loading,