Fixed that on iOS system and navigation bar covered parts of the FullscreenViews

This commit is contained in:
dankito 2024-09-24 08:11:22 +02:00
parent 0a0b93f9c8
commit 4fbc52542d
6 changed files with 50 additions and 2 deletions

View File

@ -1,6 +1,7 @@
package net.codinux.banking.ui package net.codinux.banking.ui
import android.os.Build import android.os.Build
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember import androidx.compose.runtime.remember
import androidx.compose.ui.input.key.KeyEvent import androidx.compose.ui.input.key.KeyEvent
@ -16,6 +17,10 @@ actual fun KeyEvent.isBackButtonPressedEvent(): Boolean =
this.nativeKeyEvent.keyCode == android.view.KeyEvent.KEYCODE_BACK this.nativeKeyEvent.keyCode == android.view.KeyEvent.KEYCODE_BACK
@Composable
actual fun systemPaddings(): PaddingValues = PaddingValues(0.dp)
@Composable @Composable
actual fun rememberScreenSizeInfo(): ScreenSizeInfo { actual fun rememberScreenSizeInfo(): ScreenSizeInfo {
val config = LocalConfiguration.current val config = LocalConfiguration.current

View File

@ -1,5 +1,6 @@
package net.codinux.banking.ui package net.codinux.banking.ui
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.ui.input.key.KeyEvent import androidx.compose.ui.input.key.KeyEvent
import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.Dp
@ -13,6 +14,10 @@ expect val Dispatchers.IOorDefault: CoroutineDispatcher
expect fun KeyEvent.isBackButtonPressedEvent(): Boolean expect fun KeyEvent.isBackButtonPressedEvent(): Boolean
@Composable
expect fun systemPaddings(): PaddingValues
@Composable @Composable
expect fun rememberScreenSizeInfo(): ScreenSizeInfo expect fun rememberScreenSizeInfo(): ScreenSizeInfo

View File

@ -13,10 +13,22 @@ 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 androidx.compose.ui.zIndex import androidx.compose.ui.zIndex
import net.codinux.banking.ui.PlatformType
import net.codinux.banking.ui.composables.text.HeaderText import net.codinux.banking.ui.composables.text.HeaderText
import net.codinux.banking.ui.config.Colors import net.codinux.banking.ui.config.Colors
import net.codinux.banking.ui.config.DI import net.codinux.banking.ui.config.DI
import net.codinux.banking.ui.config.Style 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 @Composable
fun FullscreenViewBase( fun FullscreenViewBase(
@ -34,12 +46,12 @@ fun FullscreenViewBase(
onClosed, onClosed,
properties = DialogProperties(usePlatformDefaultWidth = false) 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()) { Row(Modifier.fillMaxWidth()) {
HeaderText(title, Modifier.padding(top = 8.dp, bottom = 16.dp).weight(1f), textColor = Style.ListItemHeaderTextColor) 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)) { TextButton(onClosed, colors = ButtonDefaults.buttonColors(contentColor = Colors.Zinc700, backgroundColor = Color.Transparent)) {
Icon(Icons.Filled.Close, contentDescription = "Close dialog", Modifier.size(32.dp)) Icon(Icons.Filled.Close, contentDescription = "Close dialog", Modifier.size(32.dp))
} }

View File

@ -1,11 +1,13 @@
package net.codinux.banking.ui package net.codinux.banking.ui
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember import androidx.compose.runtime.remember
import androidx.compose.ui.ExperimentalComposeUiApi import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.input.key.KeyEvent import androidx.compose.ui.input.key.KeyEvent
import androidx.compose.ui.platform.LocalDensity import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.platform.LocalWindowInfo import androidx.compose.ui.platform.LocalWindowInfo
import androidx.compose.ui.unit.dp
import kotlinx.coroutines.CoroutineDispatcher import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
@ -15,6 +17,10 @@ actual val Dispatchers.IOorDefault: CoroutineDispatcher
actual fun KeyEvent.isBackButtonPressedEvent(): Boolean = false actual fun KeyEvent.isBackButtonPressedEvent(): Boolean = false
@Composable
actual fun systemPaddings(): PaddingValues = PaddingValues(0.dp)
@OptIn(ExperimentalComposeUiApi::class) @OptIn(ExperimentalComposeUiApi::class)
@Composable @Composable
actual fun rememberScreenSizeInfo(): ScreenSizeInfo { actual fun rememberScreenSizeInfo(): ScreenSizeInfo {

View File

@ -1,5 +1,6 @@
package net.codinux.banking.ui package net.codinux.banking.ui
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember import androidx.compose.runtime.remember
import androidx.compose.ui.input.key.KeyEvent import androidx.compose.ui.input.key.KeyEvent
@ -11,6 +12,7 @@ import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.IO import kotlinx.coroutines.IO
import platform.CoreGraphics.CGRect import platform.CoreGraphics.CGRect
import platform.UIKit.UIApplication
import platform.UIKit.UIDevice import platform.UIKit.UIDevice
import platform.UIKit.UIScreen import platform.UIKit.UIScreen
@ -20,6 +22,18 @@ actual val Dispatchers.IOorDefault: CoroutineDispatcher
actual fun KeyEvent.isBackButtonPressedEvent(): Boolean = false // TODO 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) @OptIn(ExperimentalForeignApi::class)
@Composable @Composable
actual fun rememberScreenSizeInfo(): ScreenSizeInfo { actual fun rememberScreenSizeInfo(): ScreenSizeInfo {

View File

@ -1,11 +1,13 @@
package net.codinux.banking.ui package net.codinux.banking.ui
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember import androidx.compose.runtime.remember
import androidx.compose.ui.ExperimentalComposeUiApi import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.input.key.KeyEvent import androidx.compose.ui.input.key.KeyEvent
import androidx.compose.ui.platform.LocalDensity import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.platform.LocalWindowInfo import androidx.compose.ui.platform.LocalWindowInfo
import androidx.compose.ui.unit.dp
import kotlinx.coroutines.CoroutineDispatcher import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
@ -15,6 +17,10 @@ actual val Dispatchers.IOorDefault: CoroutineDispatcher
actual fun KeyEvent.isBackButtonPressedEvent(): Boolean = false actual fun KeyEvent.isBackButtonPressedEvent(): Boolean = false
@Composable
actual fun systemPaddings(): PaddingValues = PaddingValues(0.dp)
@OptIn(ExperimentalComposeUiApi::class) @OptIn(ExperimentalComposeUiApi::class)
@Composable @Composable
actual fun rememberScreenSizeInfo(): ScreenSizeInfo { actual fun rememberScreenSizeInfo(): ScreenSizeInfo {