From fd8fcb9b4c4d8e0722b27869ab31b091431f174a Mon Sep 17 00:00:00 2001 From: Rene Luria Date: Tue, 4 Aug 2026 12:02:30 +0200 Subject: [PATCH] fix(ui): Wire system back gesture to in-app navigation Add PlatformBackHandler (expect/actual) to intercept the back gesture on Android via BackHandler, and enable OnBackInvokedCallback in the manifest so the swipe-back gesture triggers onBack instead of exiting the app. Fixes the back gesture exiting to home from the event detail screen. --- .../src/androidMain/AndroidManifest.xml | 1 + .../myice/ui/PlatformBackHandler.android.kt | 26 +++++++++++++++++++ .../ch/parano/myice/ui/PlatformBackHandler.kt | 23 ++++++++++++++++ .../myice/ui/screens/EventDetailScreen.kt | 3 +++ .../myice/ui/PlatformBackHandler.desktop.kt | 24 +++++++++++++++++ .../myice/ui/PlatformBackHandler.ios.kt | 24 +++++++++++++++++ 6 files changed, 101 insertions(+) create mode 100644 composeApp/src/androidMain/kotlin/ch/parano/myice/ui/PlatformBackHandler.android.kt create mode 100644 composeApp/src/commonMain/kotlin/ch/parano/myice/ui/PlatformBackHandler.kt create mode 100644 composeApp/src/desktopMain/kotlin/ch/parano/myice/ui/PlatformBackHandler.desktop.kt create mode 100644 composeApp/src/iosMain/kotlin/ch/parano/myice/ui/PlatformBackHandler.ios.kt diff --git a/composeApp/src/androidMain/AndroidManifest.xml b/composeApp/src/androidMain/AndroidManifest.xml index e7ae6e4..72e2439 100644 --- a/composeApp/src/androidMain/AndroidManifest.xml +++ b/composeApp/src/androidMain/AndroidManifest.xml @@ -7,6 +7,7 @@ android:label="MyIce" android:icon="@mipmap/ic_launcher" android:supportsRtl="true" + android:enableOnBackInvokedCallback="true" android:theme="@android:style/Theme.Material.Light.NoActionBar"> . + +package ch.parano.myice.ui + +import androidx.activity.compose.BackHandler +import androidx.compose.runtime.Composable + +@Composable +actual fun PlatformBackHandler(enabled: Boolean, onBack: () -> Unit) { + BackHandler(enabled = enabled, onBack = onBack) +} diff --git a/composeApp/src/commonMain/kotlin/ch/parano/myice/ui/PlatformBackHandler.kt b/composeApp/src/commonMain/kotlin/ch/parano/myice/ui/PlatformBackHandler.kt new file mode 100644 index 0000000..08366e4 --- /dev/null +++ b/composeApp/src/commonMain/kotlin/ch/parano/myice/ui/PlatformBackHandler.kt @@ -0,0 +1,23 @@ +// SPDX-License-Identifier: GPL-3.0-or-later +// MyIce Kotlin Multiplatform — schedule/convocation viewer +// Copyright (C) 2026 parano.ch +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +package ch.parano.myice.ui + +import androidx.compose.runtime.Composable + +@Composable +expect fun PlatformBackHandler(enabled: Boolean = true, onBack: () -> Unit) diff --git a/composeApp/src/commonMain/kotlin/ch/parano/myice/ui/screens/EventDetailScreen.kt b/composeApp/src/commonMain/kotlin/ch/parano/myice/ui/screens/EventDetailScreen.kt index ebd3842..203bc7f 100644 --- a/composeApp/src/commonMain/kotlin/ch/parano/myice/ui/screens/EventDetailScreen.kt +++ b/composeApp/src/commonMain/kotlin/ch/parano/myice/ui/screens/EventDetailScreen.kt @@ -43,6 +43,7 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.unit.dp +import ch.parano.myice.ui.PlatformBackHandler import ch.parano.myice.ui.components.LoadingIndicator import ch.parano.myice.util.formatEventDate import ch.parano.myice.util.formatEventTimeRange @@ -60,6 +61,8 @@ fun EventDetailScreen( onBack: () -> Unit, modifier: Modifier = Modifier, ) { + PlatformBackHandler { onBack() } + LaunchedEffect(gameId, account) { viewModel.loadEventDetail(gameId, account) } diff --git a/composeApp/src/desktopMain/kotlin/ch/parano/myice/ui/PlatformBackHandler.desktop.kt b/composeApp/src/desktopMain/kotlin/ch/parano/myice/ui/PlatformBackHandler.desktop.kt new file mode 100644 index 0000000..2dd7981 --- /dev/null +++ b/composeApp/src/desktopMain/kotlin/ch/parano/myice/ui/PlatformBackHandler.desktop.kt @@ -0,0 +1,24 @@ +// SPDX-License-Identifier: GPL-3.0-or-later +// MyIce Kotlin Multiplatform — schedule/convocation viewer +// Copyright (C) 2026 parano.ch +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +package ch.parano.myice.ui + +import androidx.compose.runtime.Composable + +@Composable +actual fun PlatformBackHandler(enabled: Boolean, onBack: () -> Unit) { +} diff --git a/composeApp/src/iosMain/kotlin/ch/parano/myice/ui/PlatformBackHandler.ios.kt b/composeApp/src/iosMain/kotlin/ch/parano/myice/ui/PlatformBackHandler.ios.kt new file mode 100644 index 0000000..2dd7981 --- /dev/null +++ b/composeApp/src/iosMain/kotlin/ch/parano/myice/ui/PlatformBackHandler.ios.kt @@ -0,0 +1,24 @@ +// SPDX-License-Identifier: GPL-3.0-or-later +// MyIce Kotlin Multiplatform — schedule/convocation viewer +// Copyright (C) 2026 parano.ch +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +package ch.parano.myice.ui + +import androidx.compose.runtime.Composable + +@Composable +actual fun PlatformBackHandler(enabled: Boolean, onBack: () -> Unit) { +}