From 58ab7eab4e35c3fe9ae29ff0d72205c76efda7d2 Mon Sep 17 00:00:00 2001 From: xfy Date: Tue, 19 May 2026 17:45:24 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E9=A1=B5=E9=9D=A2=E5=88=87=E6=8D=A2?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=BB=91=E5=85=A5=E6=BB=91=E5=87=BA=E5=8A=A8?= =?UTF-8?q?=E6=95=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 使用 AnimatedContent 为 Main/About/Licenses 导航添加方向感知的 slide + fade 转场动画,向前导航从右滑入,返回从左滑入。 Co-Authored-By: Claude Opus 4.7 (1M context) --- .../commonMain/kotlin/plus/rua/project/App.kt | 55 +++++++++++++------ 1 file changed, 39 insertions(+), 16 deletions(-) diff --git a/shared/src/commonMain/kotlin/plus/rua/project/App.kt b/shared/src/commonMain/kotlin/plus/rua/project/App.kt index ed79e01..aa8bf72 100644 --- a/shared/src/commonMain/kotlin/plus/rua/project/App.kt +++ b/shared/src/commonMain/kotlin/plus/rua/project/App.kt @@ -1,6 +1,13 @@ package plus.rua.project +import androidx.compose.animation.AnimatedContent +import androidx.compose.animation.fadeIn +import androidx.compose.animation.fadeOut +import androidx.compose.animation.slideInHorizontally +import androidx.compose.animation.slideOutHorizontally +import androidx.compose.animation.togetherWith import androidx.compose.foundation.isSystemInDarkTheme +import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.material3.MaterialTheme import androidx.compose.material3.darkColorScheme import androidx.compose.material3.lightColorScheme @@ -27,23 +34,39 @@ fun App() { val colorScheme = if (isSystemInDarkTheme()) darkColorScheme() else lightColorScheme() MaterialTheme(colorScheme = colorScheme) { - when (currentScreen) { - Screen.Main -> CalendarMonthView( - modifier = Modifier, - onNavigateToAbout = { 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 } + AnimatedContent( + targetState = currentScreen, + transitionSpec = { + if (targetState.ordinal > initialState.ordinal) { + // 向前导航:新页面从右侧滑入覆盖,旧页面略微左移+淡出 + (slideInHorizontally { it } + fadeIn()) togetherWith + (slideOutHorizontally { -it / 4 } + fadeOut()) + } else { + // 向后导航:新页面从左侧滑入,旧页面略微右移+淡出 + (slideInHorizontally { -it } + fadeIn()) togetherWith + (slideOutHorizontally { it / 4 } + fadeOut()) + } + }, + modifier = Modifier.fillMaxSize() + ) { screen -> + when (screen) { + Screen.Main -> CalendarMonthView( + modifier = Modifier, + onNavigateToAbout = { 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 } + ) + } } } }