Просмотр исходного кода

fix navigation back animation toggle

HapeLee 3 месяцев назад
Родитель
Сommit
a48a83d80f

+ 12 - 14
app/src/main/java/io/legado/app/ui/main/MainActivity.kt

@@ -8,13 +8,12 @@ import android.text.format.DateUtils
 import android.view.InputDevice
 import android.view.KeyEvent
 import android.view.MotionEvent
+import androidx.activity.compose.BackHandler
 import androidx.compose.animation.AnimatedContentTransitionScope
 import androidx.compose.animation.ExperimentalSharedTransitionApi
 import androidx.compose.animation.SharedTransitionLayout
 import androidx.compose.animation.core.FastOutSlowInEasing
 import androidx.compose.animation.core.LinearOutSlowInEasing
-import androidx.compose.animation.EnterTransition
-import androidx.compose.animation.ExitTransition
 import androidx.compose.animation.core.tween
 import androidx.compose.animation.fadeIn
 import androidx.compose.animation.fadeOut
@@ -298,18 +297,14 @@ open class MainActivity : BaseComposeActivity(), VariableDialog.Callback {
                     ) + fadeOut(animationSpec = tween(durationMillis = 360)))
                 },
                 predictivePopTransitionSpec = { _ ->
-                    if (!AppConfig.isPredictiveBackEnabled) {
-                        EnterTransition.None togetherWith ExitTransition.None
-                    } else {
-                        (slideIntoContainer(
-                            towards = AnimatedContentTransitionScope.SlideDirection.Start,
-                            animationSpec = tween(easing = FastOutSlowInEasing),
-                            initialOffset = { fullWidth -> -fullWidth / 4 }
-                        ) + fadeIn(animationSpec = tween(easing = LinearOutSlowInEasing))) togetherWith (scaleOut(
-                            targetScale = 0.8f,
-                            animationSpec = tween(easing = FastOutSlowInEasing)
-                        ) + fadeOut(animationSpec = tween()))
-                    }
+                    (slideIntoContainer(
+                        towards = AnimatedContentTransitionScope.SlideDirection.Start,
+                        animationSpec = tween(easing = FastOutSlowInEasing),
+                        initialOffset = { fullWidth -> -fullWidth / 4 }
+                    ) + fadeIn(animationSpec = tween(easing = LinearOutSlowInEasing))) togetherWith (scaleOut(
+                        targetScale = 0.8f,
+                        animationSpec = tween(easing = FastOutSlowInEasing)
+                    ) + fadeOut(animationSpec = tween()))
                 },
                 onBack = { MainNavigator.navigateBack(this@MainActivity, backStack) },
                 entryProvider = mainEntryProvider(
@@ -326,6 +321,9 @@ open class MainActivity : BaseComposeActivity(), VariableDialog.Callback {
                     onRegisterVariableSetter = { setter -> bookInfoVariableSetter = setter }
                 )
             )
+            BackHandler(enabled = !AppConfig.isPredictiveBackEnabled) {
+                MainNavigator.navigateBack(this@MainActivity, backStack)
+            }
         }
     }
 

+ 26 - 24
app/src/main/java/io/legado/app/ui/replace/ReplaceRuleActivity.kt

@@ -3,11 +3,10 @@
 import android.content.Context
 import android.content.Intent
 import androidx.activity.compose.LocalActivity
+import androidx.activity.compose.BackHandler
 import androidx.compose.animation.AnimatedContentTransitionScope
 import androidx.compose.animation.core.FastOutSlowInEasing
 import androidx.compose.animation.core.LinearOutSlowInEasing
-import androidx.compose.animation.EnterTransition
-import androidx.compose.animation.ExitTransition
 import androidx.compose.animation.core.tween
 import androidx.compose.animation.fadeIn
 import androidx.compose.animation.fadeOut
@@ -111,28 +110,24 @@ class ReplaceRuleActivity : BaseComposeActivity() {
                     ))
                 },
                 predictivePopTransitionSpec = { _ ->
-                    if (!AppConfig.isPredictiveBackEnabled) {
-                        EnterTransition.None togetherWith ExitTransition.None
-                    } else {
-                        (slideIntoContainer(
-                            towards = AnimatedContentTransitionScope.SlideDirection.Start,
-                            animationSpec = tween(
-                                easing = FastOutSlowInEasing
-                            ),
-                            initialOffset = { fullWidth -> -fullWidth / 4 }
-                        ) + fadeIn(
-                            animationSpec = tween(
-                                easing = LinearOutSlowInEasing
-                            )
-                        )) togetherWith (scaleOut(
-                            targetScale = 0.8f,
-                            animationSpec = tween(
-                                easing = FastOutSlowInEasing
-                            )
-                        ) + fadeOut(
-                            animationSpec = tween()
-                        ))
-                    }
+                    (slideIntoContainer(
+                        towards = AnimatedContentTransitionScope.SlideDirection.Start,
+                        animationSpec = tween(
+                            easing = FastOutSlowInEasing
+                        ),
+                        initialOffset = { fullWidth -> -fullWidth / 4 }
+                    ) + fadeIn(
+                        animationSpec = tween(
+                            easing = LinearOutSlowInEasing
+                        )
+                    )) togetherWith (scaleOut(
+                        targetScale = 0.8f,
+                        animationSpec = tween(
+                            easing = FastOutSlowInEasing
+                        )
+                    ) + fadeOut(
+                        animationSpec = tween()
+                    ))
                 },
                 onBack = {
                     if (backStack.size > 1) {
@@ -174,6 +169,13 @@ class ReplaceRuleActivity : BaseComposeActivity() {
                     }
                 }
             )
+            BackHandler(enabled = !AppConfig.isPredictiveBackEnabled) {
+                if (backStack.size > 1) {
+                    backStack.removeLastOrNull()
+                } else {
+                    finish()
+                }
+            }
         }
     }