From 4fbc52542df97392593c1591cd975e7cced47cb7 Mon Sep 17 00:00:00 2001 From: dankito Date: Tue, 24 Sep 2024 08:11:22 +0200 Subject: [PATCH] Fixed that on iOS system and navigation bar covered parts of the FullscreenViews --- .../net/codinux/banking/ui/Platform.android.kt | 5 +++++ .../kotlin/net/codinux/banking/ui/Platform.kt | 5 +++++ .../banking/ui/screens/FullscreenViewBase.kt | 16 ++++++++++++++-- .../net/codinux/banking/ui/Platform.desktop.kt | 6 ++++++ .../net/codinux/banking/ui/Platform.ios.kt | 14 ++++++++++++++ .../kotlin/net/codinux/banking/ui/Platform.js.kt | 6 ++++++ 6 files changed, 50 insertions(+), 2 deletions(-) diff --git a/composeApp/src/androidMain/kotlin/net/codinux/banking/ui/Platform.android.kt b/composeApp/src/androidMain/kotlin/net/codinux/banking/ui/Platform.android.kt index 9d5b182..e8458f3 100644 --- a/composeApp/src/androidMain/kotlin/net/codinux/banking/ui/Platform.android.kt +++ b/composeApp/src/androidMain/kotlin/net/codinux/banking/ui/Platform.android.kt @@ -1,6 +1,7 @@ package net.codinux.banking.ui import android.os.Build +import androidx.compose.foundation.layout.PaddingValues import androidx.compose.runtime.Composable import androidx.compose.runtime.remember import androidx.compose.ui.input.key.KeyEvent @@ -16,6 +17,10 @@ actual fun KeyEvent.isBackButtonPressedEvent(): Boolean = this.nativeKeyEvent.keyCode == android.view.KeyEvent.KEYCODE_BACK +@Composable +actual fun systemPaddings(): PaddingValues = PaddingValues(0.dp) + + @Composable actual fun rememberScreenSizeInfo(): ScreenSizeInfo { val config = LocalConfiguration.current diff --git a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/Platform.kt b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/Platform.kt index 8b46316..35bbf85 100644 --- a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/Platform.kt +++ b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/Platform.kt @@ -1,5 +1,6 @@ package net.codinux.banking.ui +import androidx.compose.foundation.layout.PaddingValues import androidx.compose.runtime.Composable import androidx.compose.ui.input.key.KeyEvent import androidx.compose.ui.unit.Dp @@ -13,6 +14,10 @@ expect val Dispatchers.IOorDefault: CoroutineDispatcher expect fun KeyEvent.isBackButtonPressedEvent(): Boolean +@Composable +expect fun systemPaddings(): PaddingValues + + @Composable expect fun rememberScreenSizeInfo(): ScreenSizeInfo diff --git a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/screens/FullscreenViewBase.kt b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/screens/FullscreenViewBase.kt index ede9e38..2890069 100644 --- a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/screens/FullscreenViewBase.kt +++ b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/screens/FullscreenViewBase.kt @@ -13,10 +13,22 @@ import androidx.compose.ui.unit.dp import androidx.compose.ui.window.Dialog import androidx.compose.ui.window.DialogProperties import androidx.compose.ui.zIndex +import net.codinux.banking.ui.PlatformType import net.codinux.banking.ui.composables.text.HeaderText import net.codinux.banking.ui.config.Colors import net.codinux.banking.ui.config.DI import net.codinux.banking.ui.config.Style +import net.codinux.banking.ui.systemPaddings + +@Composable +private fun Modifier.applyPlatformSpecificPadding(): Modifier { + val systemPaddings = systemPaddings() + + return this.padding( + top = systemPaddings.calculateTopPadding(), + bottom = systemPaddings.calculateBottomPadding() + ) +} @Composable fun FullscreenViewBase( @@ -34,12 +46,12 @@ fun FullscreenViewBase( onClosed, properties = DialogProperties(usePlatformDefaultWidth = false) ) { - Column(Modifier.fillMaxSize().zIndex(1000f).background(Color.White).padding(8.dp)) { + Column(Modifier.fillMaxSize().zIndex(1000f).background(Color.White).applyPlatformSpecificPadding().padding(8.dp)) { Row(Modifier.fillMaxWidth()) { HeaderText(title, Modifier.padding(top = 8.dp, bottom = 16.dp).weight(1f), textColor = Style.ListItemHeaderTextColor) - if (DI.platform.isDesktop) { + if (DI.platform.type != PlatformType.Android) { // for iOS it's also relevant due to the missing back gesture / back button TextButton(onClosed, colors = ButtonDefaults.buttonColors(contentColor = Colors.Zinc700, backgroundColor = Color.Transparent)) { Icon(Icons.Filled.Close, contentDescription = "Close dialog", Modifier.size(32.dp)) } diff --git a/composeApp/src/desktopMain/kotlin/net/codinux/banking/ui/Platform.desktop.kt b/composeApp/src/desktopMain/kotlin/net/codinux/banking/ui/Platform.desktop.kt index 96c9c9a..1487f34 100644 --- a/composeApp/src/desktopMain/kotlin/net/codinux/banking/ui/Platform.desktop.kt +++ b/composeApp/src/desktopMain/kotlin/net/codinux/banking/ui/Platform.desktop.kt @@ -1,11 +1,13 @@ package net.codinux.banking.ui +import androidx.compose.foundation.layout.PaddingValues import androidx.compose.runtime.Composable import androidx.compose.runtime.remember import androidx.compose.ui.ExperimentalComposeUiApi import androidx.compose.ui.input.key.KeyEvent import androidx.compose.ui.platform.LocalDensity import androidx.compose.ui.platform.LocalWindowInfo +import androidx.compose.ui.unit.dp import kotlinx.coroutines.CoroutineDispatcher import kotlinx.coroutines.Dispatchers @@ -15,6 +17,10 @@ actual val Dispatchers.IOorDefault: CoroutineDispatcher actual fun KeyEvent.isBackButtonPressedEvent(): Boolean = false +@Composable +actual fun systemPaddings(): PaddingValues = PaddingValues(0.dp) + + @OptIn(ExperimentalComposeUiApi::class) @Composable actual fun rememberScreenSizeInfo(): ScreenSizeInfo { diff --git a/composeApp/src/iosMain/kotlin/net/codinux/banking/ui/Platform.ios.kt b/composeApp/src/iosMain/kotlin/net/codinux/banking/ui/Platform.ios.kt index f3d1616..5f1f872 100644 --- a/composeApp/src/iosMain/kotlin/net/codinux/banking/ui/Platform.ios.kt +++ b/composeApp/src/iosMain/kotlin/net/codinux/banking/ui/Platform.ios.kt @@ -1,5 +1,6 @@ package net.codinux.banking.ui +import androidx.compose.foundation.layout.PaddingValues import androidx.compose.runtime.Composable import androidx.compose.runtime.remember import androidx.compose.ui.input.key.KeyEvent @@ -11,6 +12,7 @@ import kotlinx.coroutines.CoroutineDispatcher import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.IO import platform.CoreGraphics.CGRect +import platform.UIKit.UIApplication import platform.UIKit.UIDevice import platform.UIKit.UIScreen @@ -20,6 +22,18 @@ actual val Dispatchers.IOorDefault: CoroutineDispatcher actual fun KeyEvent.isBackButtonPressedEvent(): Boolean = false // TODO +@Composable +@OptIn(ExperimentalForeignApi::class) +actual fun systemPaddings(): PaddingValues { + val window = UIApplication.sharedApplication.keyWindow ?: return PaddingValues(0.dp) + val (top, bottom) = window.safeAreaInsets.useContents { + this.top.toFloat() to this.bottom.toFloat() + } + + return PaddingValues(top = top.dp, bottom = bottom.dp) +} + + @OptIn(ExperimentalForeignApi::class) @Composable actual fun rememberScreenSizeInfo(): ScreenSizeInfo { diff --git a/composeApp/src/jsMain/kotlin/net/codinux/banking/ui/Platform.js.kt b/composeApp/src/jsMain/kotlin/net/codinux/banking/ui/Platform.js.kt index e7f1446..1d344c1 100644 --- a/composeApp/src/jsMain/kotlin/net/codinux/banking/ui/Platform.js.kt +++ b/composeApp/src/jsMain/kotlin/net/codinux/banking/ui/Platform.js.kt @@ -1,11 +1,13 @@ package net.codinux.banking.ui +import androidx.compose.foundation.layout.PaddingValues import androidx.compose.runtime.Composable import androidx.compose.runtime.remember import androidx.compose.ui.ExperimentalComposeUiApi import androidx.compose.ui.input.key.KeyEvent import androidx.compose.ui.platform.LocalDensity import androidx.compose.ui.platform.LocalWindowInfo +import androidx.compose.ui.unit.dp import kotlinx.coroutines.CoroutineDispatcher import kotlinx.coroutines.Dispatchers @@ -15,6 +17,10 @@ actual val Dispatchers.IOorDefault: CoroutineDispatcher actual fun KeyEvent.isBackButtonPressedEvent(): Boolean = false +@Composable +actual fun systemPaddings(): PaddingValues = PaddingValues(0.dp) + + @OptIn(ExperimentalComposeUiApi::class) @Composable actual fun rememberScreenSizeInfo(): ScreenSizeInfo {