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
|
package plus.rua.project
|
||||||
|
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
|
||||||
class AndroidPlatform : Platform {
|
class AndroidPlatform : Platform {
|
||||||
override val name: String = "Android ${Build.VERSION.SDK_INT}"
|
override val name: String = "Android ${Build.VERSION.SDK_INT}"
|
||||||
@ -11,3 +12,8 @@ actual fun getPlatform(): Platform = AndroidPlatform()
|
|||||||
actual fun getGifUri(gifFile: String): String = "file:///android_asset/gifs/$gifFile"
|
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,
|
modifier = Modifier,
|
||||||
onNavigateToAbout = { currentScreen = Screen.About }
|
onNavigateToAbout = { currentScreen = Screen.About }
|
||||||
)
|
)
|
||||||
Screen.About -> AboutScreen(
|
Screen.About -> {
|
||||||
onBack = { currentScreen = Screen.Main },
|
BackHandler { currentScreen = Screen.Main }
|
||||||
onNavigateToLicenses = { currentScreen = Screen.Licenses }
|
AboutScreen(
|
||||||
)
|
onBack = { currentScreen = Screen.Main },
|
||||||
Screen.Licenses -> LicensesScreen(
|
onNavigateToLicenses = { currentScreen = Screen.Licenses }
|
||||||
onBack = { currentScreen = Screen.About }
|
)
|
||||||
)
|
}
|
||||||
|
Screen.Licenses -> {
|
||||||
|
BackHandler { currentScreen = Screen.About }
|
||||||
|
LicensesScreen(
|
||||||
|
onBack = { currentScreen = Screen.About }
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,7 @@
|
|||||||
package plus.rua.project
|
package plus.rua.project
|
||||||
|
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
|
||||||
interface Platform {
|
interface Platform {
|
||||||
val name: String
|
val name: String
|
||||||
}
|
}
|
||||||
@ -15,3 +17,12 @@ expect fun getPlatform(): Platform
|
|||||||
expect fun getGifUri(gifFile: String): String
|
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
|
package plus.rua.project
|
||||||
|
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
import platform.UIKit.UIDevice
|
import platform.UIKit.UIDevice
|
||||||
|
|
||||||
class IOSPlatform : Platform {
|
class IOSPlatform : Platform {
|
||||||
@ -12,3 +13,8 @@ actual fun getPlatform(): Platform = IOSPlatform()
|
|||||||
actual fun getGifUri(gifFile: String): String = "compose.resource://files/$gifFile"
|
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