Fix crash in NearbyDialog due to missing screen height
This commit is contained in:
@@ -0,0 +1,14 @@
|
|||||||
|
package app.klottr.platform
|
||||||
|
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.ui.platform.LocalConfiguration
|
||||||
|
import androidx.compose.ui.unit.Dp
|
||||||
|
import androidx.compose.ui.unit.dp
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
actual fun platformScreenHeightDp(): Dp {
|
||||||
|
val conf = LocalConfiguration.current
|
||||||
|
// screenHeightDp is in dp units already
|
||||||
|
return conf.screenHeightDp.dp
|
||||||
|
}
|
||||||
|
|
||||||
@@ -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
|
||||||
@@ -5,6 +5,7 @@ import androidx.compose.foundation.background
|
|||||||
import androidx.compose.foundation.gestures.detectTransformGestures
|
import androidx.compose.foundation.gestures.detectTransformGestures
|
||||||
import androidx.compose.foundation.layout.Arrangement
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
import androidx.compose.foundation.layout.Box
|
import androidx.compose.foundation.layout.Box
|
||||||
|
import androidx.compose.foundation.layout.requiredHeightIn
|
||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
import androidx.compose.foundation.layout.Row
|
import androidx.compose.foundation.layout.Row
|
||||||
import androidx.compose.foundation.layout.Spacer
|
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.padding
|
||||||
import androidx.compose.foundation.layout.size
|
import androidx.compose.foundation.layout.size
|
||||||
import androidx.compose.foundation.layout.widthIn
|
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.foundation.shape.RoundedCornerShape
|
||||||
import androidx.compose.material3.AlertDialog
|
import androidx.compose.material3.AlertDialog
|
||||||
import androidx.compose.material3.Button
|
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.unit.dp
|
||||||
import androidx.compose.ui.window.Dialog
|
import androidx.compose.ui.window.Dialog
|
||||||
import androidx.compose.ui.window.DialogProperties
|
import androidx.compose.ui.window.DialogProperties
|
||||||
|
import app.klottr.platform.platformScreenHeightDp
|
||||||
import app.klottr.nearby.FoundOpenAction
|
import app.klottr.nearby.FoundOpenAction
|
||||||
import app.klottr.nearby.NearbyEntryShared
|
import app.klottr.nearby.NearbyEntryShared
|
||||||
import app.klottr.net.DigitaltMuseumItem
|
import app.klottr.net.DigitaltMuseumItem
|
||||||
@@ -78,18 +78,24 @@ fun NearbyDialog(
|
|||||||
title = { Text("Närliggande") },
|
title = { Text("Närliggande") },
|
||||||
text = {
|
text = {
|
||||||
val hasLocation = (lat != null && lon != null)
|
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 ->
|
val container = @Composable { inner: @Composable () -> Unit ->
|
||||||
if (maxHeight != null) {
|
// Bound the height BEFORE measuring child content; do NOT add verticalScroll here.
|
||||||
Box(Modifier.widthIn(min = 280.dp).height(maxHeight)) {
|
Box(
|
||||||
Column(Modifier.fillMaxSize().verticalScroll(scroll)) { inner() }
|
Modifier
|
||||||
}
|
.widthIn(min = 280.dp)
|
||||||
} else {
|
.requiredHeightIn(max = cap)
|
||||||
Column(Modifier.widthIn(min = 280.dp).verticalScroll(scroll)) { inner() }
|
) {
|
||||||
|
// 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 {
|
container {
|
||||||
NearbyContent(
|
NearbyContent(
|
||||||
loading = loading,
|
loading = loading,
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
package app.klottr.platform
|
||||||
|
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.ui.platform.LocalDensity
|
||||||
|
import androidx.compose.ui.unit.Dp
|
||||||
|
import androidx.compose.ui.unit.dp
|
||||||
|
import platform.UIKit.UIScreen
|
||||||
|
import platform.CoreGraphics.CGRectGetHeight
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
actual fun platformScreenHeightDp(): Dp {
|
||||||
|
// UIKit gives points; convert to Compose dp via LocalDensity for safety.
|
||||||
|
val heightPoints: Double = CGRectGetHeight(UIScreen.mainScreen.bounds)
|
||||||
|
val density = LocalDensity.current
|
||||||
|
// Compose dp ~= iOS points; still convert explicitly.
|
||||||
|
return with(density) { heightPoints.toFloat().dp }
|
||||||
|
}
|
||||||
|
|
||||||
Reference in New Issue
Block a user