diff --git a/shared/src/androidMain/kotlin/plus/rua/project/Platform.android.kt b/shared/src/androidMain/kotlin/plus/rua/project/Platform.android.kt index e0ddf8b..39289ab 100644 --- a/shared/src/androidMain/kotlin/plus/rua/project/Platform.android.kt +++ b/shared/src/androidMain/kotlin/plus/rua/project/Platform.android.kt @@ -1,6 +1,7 @@ package plus.rua.project import android.os.Build +import androidx.compose.runtime.Composable class AndroidPlatform : Platform { override val name: String = "Android ${Build.VERSION.SDK_INT}" @@ -10,4 +11,9 @@ actual fun getPlatform(): Platform = AndroidPlatform() actual fun getGifUri(gifFile: String): String = "file:///android_asset/gifs/$gifFile" -actual fun getAppIconUri(): String = "file:///android_asset/app_icon.png" \ No newline at end of file +actual fun getAppIconUri(): String = "file:///android_asset/app_icon.png" + +@Composable +actual fun BackHandler(enabled: Boolean, onBack: () -> Unit) { + androidx.activity.compose.BackHandler(enabled = enabled, onBack = onBack) +} \ No newline at end of file diff --git a/shared/src/commonMain/kotlin/plus/rua/project/App.kt b/shared/src/commonMain/kotlin/plus/rua/project/App.kt index abc6d21..ed79e01 100644 --- a/shared/src/commonMain/kotlin/plus/rua/project/App.kt +++ b/shared/src/commonMain/kotlin/plus/rua/project/App.kt @@ -32,13 +32,19 @@ fun App() { modifier = Modifier, onNavigateToAbout = { currentScreen = Screen.About } ) - Screen.About -> AboutScreen( - onBack = { currentScreen = Screen.Main }, - onNavigateToLicenses = { currentScreen = Screen.Licenses } - ) - Screen.Licenses -> LicensesScreen( - onBack = { currentScreen = Screen.About } - ) + Screen.About -> { + BackHandler { currentScreen = Screen.Main } + AboutScreen( + onBack = { currentScreen = Screen.Main }, + onNavigateToLicenses = { currentScreen = Screen.Licenses } + ) + } + Screen.Licenses -> { + BackHandler { currentScreen = Screen.About } + LicensesScreen( + onBack = { currentScreen = Screen.About } + ) + } } } } diff --git a/shared/src/commonMain/kotlin/plus/rua/project/Platform.kt b/shared/src/commonMain/kotlin/plus/rua/project/Platform.kt index d76804f..6faab22 100644 --- a/shared/src/commonMain/kotlin/plus/rua/project/Platform.kt +++ b/shared/src/commonMain/kotlin/plus/rua/project/Platform.kt @@ -1,5 +1,7 @@ package plus.rua.project +import androidx.compose.runtime.Composable + interface Platform { val name: String } @@ -14,4 +16,13 @@ expect fun getPlatform(): Platform */ expect fun getGifUri(gifFile: String): String -expect fun getAppIconUri(): String \ No newline at end of file +expect fun getAppIconUri(): String + +/** + * 拦截系统返回手势。 + * + * @param enabled 是否启用拦截 + * @param onBack 返回回调 + */ +@Composable +expect fun BackHandler(enabled: Boolean = true, onBack: () -> Unit) \ No newline at end of file diff --git a/shared/src/iosMain/kotlin/plus/rua/project/Platform.ios.kt b/shared/src/iosMain/kotlin/plus/rua/project/Platform.ios.kt index 09db9f7..3c1efc8 100644 --- a/shared/src/iosMain/kotlin/plus/rua/project/Platform.ios.kt +++ b/shared/src/iosMain/kotlin/plus/rua/project/Platform.ios.kt @@ -1,5 +1,6 @@ package plus.rua.project +import androidx.compose.runtime.Composable import platform.UIKit.UIDevice class IOSPlatform : Platform { @@ -11,4 +12,9 @@ actual fun getPlatform(): Platform = IOSPlatform() actual fun getGifUri(gifFile: String): String = "compose.resource://files/$gifFile" -actual fun getAppIconUri(): String = "compose.resource://files/app_icon.png" \ No newline at end of file +actual fun getAppIconUri(): String = "compose.resource://files/app_icon.png" + +@Composable +actual fun BackHandler(enabled: Boolean, onBack: () -> Unit) { + // iOS 没有系统返回键,由导航栏按钮处理 +} \ No newline at end of file