Closing FilterBar on Android back button press or Escape press
This commit is contained in:
parent
97282adf12
commit
4d7cca7a7e
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
}
|
|
@ -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 {
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue