diff --git a/composeApp/src/androidMain/kotlin/net/codinux/banking/ui/MainActivity.kt b/composeApp/src/androidMain/kotlin/net/codinux/banking/ui/MainActivity.kt index b444e8f..5c04b4e 100644 --- a/composeApp/src/androidMain/kotlin/net/codinux/banking/ui/MainActivity.kt +++ b/composeApp/src/androidMain/kotlin/net/codinux/banking/ui/MainActivity.kt @@ -6,8 +6,6 @@ import androidx.compose.runtime.Composable import androidx.compose.ui.tooling.preview.Preview import androidx.fragment.app.FragmentActivity import net.codinux.banking.persistence.AndroidContext -import net.codinux.banking.persistence.SqliteBankingRepository -import net.codinux.banking.ui.config.DI import net.codinux.banking.ui.service.AuthenticationService import net.codinux.banking.ui.service.BiometricAuthenticationService import net.codinux.banking.ui.service.ImageService 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 2074d5b..9d5b182 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 @@ -3,6 +3,7 @@ package net.codinux.banking.ui import android.os.Build import androidx.compose.runtime.Composable import androidx.compose.runtime.remember +import androidx.compose.ui.input.key.KeyEvent import androidx.compose.ui.platform.LocalConfiguration import androidx.compose.ui.unit.dp import kotlinx.coroutines.CoroutineDispatcher @@ -11,6 +12,10 @@ import kotlinx.coroutines.Dispatchers actual val Dispatchers.IOorDefault: CoroutineDispatcher get() = Dispatchers.IO +actual fun KeyEvent.isBackButtonPressedEvent(): Boolean = + this.nativeKeyEvent.keyCode == android.view.KeyEvent.KEYCODE_BACK + + @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 be0eb47..8b46316 100644 --- a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/Platform.kt +++ b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/Platform.kt @@ -1,6 +1,7 @@ package net.codinux.banking.ui import androidx.compose.runtime.Composable +import androidx.compose.ui.input.key.KeyEvent import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.dp import kotlinx.coroutines.CoroutineDispatcher @@ -9,6 +10,9 @@ import kotlinx.coroutines.Dispatchers expect val Dispatchers.IOorDefault: CoroutineDispatcher +expect fun KeyEvent.isBackButtonPressedEvent(): Boolean + + @Composable expect fun rememberScreenSizeInfo(): ScreenSizeInfo diff --git a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/appskeleton/FilterBar.kt b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/appskeleton/FilterBar.kt index 2bf49d3..08d07fd 100644 --- a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/appskeleton/FilterBar.kt +++ b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/appskeleton/FilterBar.kt @@ -1,18 +1,24 @@ package net.codinux.banking.ui.appskeleton import androidx.compose.foundation.background +import androidx.compose.foundation.focusable import androidx.compose.foundation.layout.* import androidx.compose.material.Text import androidx.compose.runtime.* import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier +import androidx.compose.ui.focus.FocusRequester +import androidx.compose.ui.focus.focusRequester +import androidx.compose.ui.focus.focusTarget import androidx.compose.ui.graphics.Color +import androidx.compose.ui.input.key.* import androidx.compose.ui.unit.dp import androidx.compose.ui.zIndex import net.codinux.banking.ui.config.DI import net.codinux.banking.ui.config.Internationalization import net.codinux.banking.ui.forms.RoundedCornersCard import net.codinux.banking.ui.forms.Select +import net.codinux.banking.ui.isBackButtonPressedEvent import net.codinux.banking.ui.model.settings.TransactionsGrouping private val uiState = DI.uiState @@ -37,10 +43,20 @@ fun FilterBar() { val months = listOf("Januar", "Februar", "März", "April", "Mai", "Juni", "Juli", "August", "September", "Oktober", "November", "Dezember" /*, "1. Quartal", "2. Quartal", "3. Quartal", "4. Quartal" */, null) + val filterBarFocus = remember { FocusRequester() } + + Box( contentAlignment = Alignment.BottomEnd, modifier = Modifier.fillMaxSize().zIndex(100f) - .padding(bottom = 64.dp, end = 74.dp) + .padding(bottom = 64.dp, end = 74.dp).focusable(true).focusRequester(filterBarFocus).focusTarget().onKeyEvent { event -> + if (event.isBackButtonPressedEvent() || event.key == Key.Escape) { + DI.uiState.showFilterBar.value = false + true + } else { + false + } + } ) { Column(Modifier.height(230.dp).width(390.dp)) { RoundedCornersCard(cornerSize = 4.dp, shadowElevation = 24.dp) { @@ -90,4 +106,9 @@ fun FilterBar() { } } + + LaunchedEffect(filterBarFocus) { + filterBarFocus.requestFocus() // focus filter bar so that it receives key events to handle e.g. Escape button press + } + } \ No newline at end of file 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 af796a7..96c9c9a 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 @@ -3,6 +3,7 @@ package net.codinux.banking.ui 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 kotlinx.coroutines.CoroutineDispatcher @@ -11,6 +12,9 @@ import kotlinx.coroutines.Dispatchers actual val Dispatchers.IOorDefault: CoroutineDispatcher get() = Dispatchers.IO +actual fun KeyEvent.isBackButtonPressedEvent(): Boolean = false + + @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 4911a4e..f3d1616 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 @@ -2,6 +2,7 @@ package net.codinux.banking.ui import androidx.compose.runtime.Composable import androidx.compose.runtime.remember +import androidx.compose.ui.input.key.KeyEvent import androidx.compose.ui.platform.LocalDensity import androidx.compose.ui.unit.dp import kotlinx.cinterop.ExperimentalForeignApi @@ -16,6 +17,9 @@ import platform.UIKit.UIScreen actual val Dispatchers.IOorDefault: CoroutineDispatcher get() = Dispatchers.IO +actual fun KeyEvent.isBackButtonPressedEvent(): Boolean = false // TODO + + @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 12fdfff..e7f1446 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 @@ -3,6 +3,7 @@ package net.codinux.banking.ui 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 kotlinx.coroutines.CoroutineDispatcher @@ -11,6 +12,9 @@ import kotlinx.coroutines.Dispatchers actual val Dispatchers.IOorDefault: CoroutineDispatcher get() = Dispatchers.Default +actual fun KeyEvent.isBackButtonPressedEvent(): Boolean = false + + @OptIn(ExperimentalComposeUiApi::class) @Composable actual fun rememberScreenSizeInfo(): ScreenSizeInfo {