DetailDialogsShell (finally!) platform independent and moved to shared
This commit is contained in:
@@ -12,3 +12,10 @@ actual fun platformScreenHeightDp(): Dp {
|
|||||||
return conf.screenHeightDp.dp
|
return conf.screenHeightDp.dp
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
actual fun platformScreenWidthDp(): Dp {
|
||||||
|
val conf = LocalConfiguration.current
|
||||||
|
// screenHeightDp is in dp units already
|
||||||
|
return conf.screenWidthDp.dp
|
||||||
|
}
|
||||||
|
|||||||
@@ -3,7 +3,12 @@ package app.klottr.platform
|
|||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.ui.unit.Dp
|
import androidx.compose.ui.unit.Dp
|
||||||
|
|
||||||
|
|
||||||
|
//TODO: OH: Verkar som vi inte borde bero på dessa, utan använda compose api:et LocalWindowInfo.containerSize istället
|
||||||
|
// som redan är platformsoberoende
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Platform-agnostic screen height in dp for sizing dialogs proportionally.
|
* Platform-agnostic screen height in dp for sizing dialogs proportionally.
|
||||||
*/
|
*/
|
||||||
@Composable expect fun platformScreenHeightDp(): Dp
|
@Composable expect fun platformScreenHeightDp(): Dp
|
||||||
|
@Composable expect fun platformScreenWidthDp(): Dp
|
||||||
|
|||||||
@@ -17,8 +17,6 @@ import androidx.compose.runtime.mutableStateOf
|
|||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
import androidx.compose.runtime.setValue // Gör 'by remember { ... }' skrivbart
|
import androidx.compose.runtime.setValue // Gör 'by remember { ... }' skrivbart
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.platform.LocalConfiguration
|
|
||||||
import androidx.compose.ui.platform.LocalContext
|
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.compose.ui.window.DialogProperties
|
import androidx.compose.ui.window.DialogProperties
|
||||||
import app.klottr.net.DigitaltMuseumItem
|
import app.klottr.net.DigitaltMuseumItem
|
||||||
@@ -26,10 +24,12 @@ import app.klottr.net.FornsokItem
|
|||||||
import app.klottr.net.Wikipedia
|
import app.klottr.net.Wikipedia
|
||||||
import app.klottr.location.LocationServiceProvider
|
import app.klottr.location.LocationServiceProvider
|
||||||
import app.klottr.platform.AppNavigator
|
import app.klottr.platform.AppNavigator
|
||||||
|
import app.klottr.platform.platformScreenWidthDp
|
||||||
import app.klottr.util.SettingsStore
|
import app.klottr.util.SettingsStore
|
||||||
import app.klottr.util.formatCoords
|
import app.klottr.util.formatCoords
|
||||||
import app.klottr.util.formatDistance
|
import app.klottr.util.formatDistance
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.IO
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
import kotlin.math.roundToInt
|
import kotlin.math.roundToInt
|
||||||
|
|
||||||
@@ -42,8 +42,7 @@ fun WikiArticleDialog(
|
|||||||
lon: Double?,
|
lon: Double?,
|
||||||
onClose: () -> Unit
|
onClose: () -> Unit
|
||||||
) {
|
) {
|
||||||
val configuration = LocalConfiguration.current
|
val dialogWidth = (platformScreenWidthDp() * 0.98f)
|
||||||
val dialogWidth = (configuration.screenWidthDp.dp * 0.98f)
|
|
||||||
|
|
||||||
var loading by remember { mutableStateOf(true) }
|
var loading by remember { mutableStateOf(true) }
|
||||||
var title by remember { mutableStateOf("") }
|
var title by remember { mutableStateOf("") }
|
||||||
@@ -136,9 +135,7 @@ fun FornsokDialog(
|
|||||||
item: FornsokItem,
|
item: FornsokItem,
|
||||||
onClose: () -> Unit
|
onClose: () -> Unit
|
||||||
) {
|
) {
|
||||||
val context = LocalContext.current
|
val dialogWidth = (platformScreenWidthDp() * 0.98f)
|
||||||
val configuration = LocalConfiguration.current
|
|
||||||
val dialogWidth = (configuration.screenWidthDp.dp * 0.98f)
|
|
||||||
|
|
||||||
// Vi använder fälten från FornsokItem; om desc/uri saknas visar vi "saknas"-text.
|
// Vi använder fälten från FornsokItem; om desc/uri saknas visar vi "saknas"-text.
|
||||||
val title = remember(item.id) { item.title.ifBlank { "Fornlämning" } }
|
val title = remember(item.id) { item.title.ifBlank { "Fornlämning" } }
|
||||||
@@ -219,9 +216,8 @@ fun DmDialog(
|
|||||||
item: DigitaltMuseumItem,
|
item: DigitaltMuseumItem,
|
||||||
onClose: () -> Unit
|
onClose: () -> Unit
|
||||||
) {
|
) {
|
||||||
val context = LocalContext.current
|
val dialogWidth = (platformScreenWidthDp() * 0.98f)
|
||||||
val configuration = LocalConfiguration.current
|
|
||||||
val dialogWidth = (configuration.screenWidthDp.dp * 0.98f)
|
|
||||||
var detailText by remember { mutableStateOf<String?>(null) }
|
var detailText by remember { mutableStateOf<String?>(null) }
|
||||||
|
|
||||||
var loading by remember { mutableStateOf(false) }
|
var loading by remember { mutableStateOf(false) }
|
||||||
@@ -4,9 +4,11 @@ import androidx.compose.runtime.Composable
|
|||||||
import androidx.compose.ui.platform.LocalDensity
|
import androidx.compose.ui.platform.LocalDensity
|
||||||
import androidx.compose.ui.unit.Dp
|
import androidx.compose.ui.unit.Dp
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
|
import kotlinx.cinterop.ExperimentalForeignApi
|
||||||
import platform.UIKit.UIScreen
|
import platform.UIKit.UIScreen
|
||||||
import platform.CoreGraphics.CGRectGetHeight
|
import platform.CoreGraphics.CGRectGetHeight
|
||||||
|
|
||||||
|
@OptIn(ExperimentalForeignApi::class)
|
||||||
@Composable
|
@Composable
|
||||||
actual fun platformScreenHeightDp(): Dp {
|
actual fun platformScreenHeightDp(): Dp {
|
||||||
// UIKit gives points; convert to Compose dp via LocalDensity for safety.
|
// UIKit gives points; convert to Compose dp via LocalDensity for safety.
|
||||||
@@ -16,3 +18,12 @@ actual fun platformScreenHeightDp(): Dp {
|
|||||||
return with(density) { heightPoints.toFloat().dp }
|
return with(density) { heightPoints.toFloat().dp }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@OptIn(ExperimentalForeignApi::class)
|
||||||
|
@Composable
|
||||||
|
actual fun platformScreenWidthDp(): 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