feat: 新增 BackHandler expect/actual 拦截系统返回手势
Android 通过 androidx.activity.compose.BackHandler 接管返回键, 在关于页与许可页返回上一级;iOS 无系统返回键,actual 为空实现。 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
43579b2866
commit
0b1d89f06d
@ -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"
|
||||
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)
|
||||
}
|
||||
@ -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 }
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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
|
||||
expect fun getAppIconUri(): String
|
||||
|
||||
/**
|
||||
* 拦截系统返回手势。
|
||||
*
|
||||
* @param enabled 是否启用拦截
|
||||
* @param onBack 返回回调
|
||||
*/
|
||||
@Composable
|
||||
expect fun BackHandler(enabled: Boolean = true, onBack: () -> Unit)
|
||||
@ -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"
|
||||
actual fun getAppIconUri(): String = "compose.resource://files/app_icon.png"
|
||||
|
||||
@Composable
|
||||
actual fun BackHandler(enabled: Boolean, onBack: () -> Unit) {
|
||||
// iOS 没有系统返回键,由导航栏按钮处理
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user