diff --git a/app/src/main/java/org/thoughtcrime/securesms/registration/olddevice/QuickTransferOldDeviceNavigation.kt b/app/src/main/java/org/thoughtcrime/securesms/registration/olddevice/QuickTransferOldDeviceNavigation.kt index 439968f8f1..6c841d4591 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/registration/olddevice/QuickTransferOldDeviceNavigation.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/registration/olddevice/QuickTransferOldDeviceNavigation.kt @@ -72,7 +72,7 @@ fun TransferAccountNavHost( modifier = modifier, transitionSpec = TransitionSpecs.HorizontalSlide.transitionSpec, popTransitionSpec = TransitionSpecs.HorizontalSlide.popTransitionSpec, - predictivePopTransitionSpec = TransitionSpecs.HorizontalSlide.predictivePopTransitonSpec + predictivePopTransitionSpec = TransitionSpecs.HorizontalSlide.predictivePopTransitionSpec ) } diff --git a/core/ui/src/main/java/org/signal/core/ui/navigation/TransitionSpecs.kt b/core/ui/src/main/java/org/signal/core/ui/navigation/TransitionSpecs.kt index b46fd006a8..aaad5db064 100644 --- a/core/ui/src/main/java/org/signal/core/ui/navigation/TransitionSpecs.kt +++ b/core/ui/src/main/java/org/signal/core/ui/navigation/TransitionSpecs.kt @@ -11,7 +11,9 @@ import androidx.compose.animation.core.tween import androidx.compose.animation.fadeIn import androidx.compose.animation.fadeOut import androidx.compose.animation.slideInHorizontally +import androidx.compose.animation.slideInVertically import androidx.compose.animation.slideOutHorizontally +import androidx.compose.animation.slideOutVertically import androidx.compose.animation.togetherWith import androidx.navigation3.runtime.NavKey import androidx.navigation3.scene.Scene @@ -26,18 +28,20 @@ object TransitionSpecs { * Screens slide in from the right and slide out from the left. */ object HorizontalSlide { + private const val DURATION = 200 + val transitionSpec: AnimatedContentTransitionScope>.() -> ContentTransform = { ( slideInHorizontally( initialOffsetX = { it }, - animationSpec = tween(200) - ) + fadeIn(animationSpec = tween(200)) + animationSpec = tween(DURATION) + ) + fadeIn(animationSpec = tween(DURATION)) ) togetherWith ( slideOutHorizontally( targetOffsetX = { -it }, - animationSpec = tween(200) - ) + fadeOut(animationSpec = tween(200)) + animationSpec = tween(DURATION) + ) + fadeOut(animationSpec = tween(DURATION)) ) } @@ -45,30 +49,61 @@ object TransitionSpecs { ( slideInHorizontally( initialOffsetX = { -it }, - animationSpec = tween(200) - ) + fadeIn(animationSpec = tween(200)) + animationSpec = tween(DURATION) + ) + fadeIn(animationSpec = tween(DURATION)) ) togetherWith ( slideOutHorizontally( targetOffsetX = { it }, - animationSpec = tween(200) - ) + fadeOut(animationSpec = tween(200)) + animationSpec = tween(DURATION) + ) + fadeOut(animationSpec = tween(DURATION)) ) } - val predictivePopTransitonSpec: AnimatedContentTransitionScope>.(@NavigationEvent.SwipeEdge Int) -> ContentTransform = { + val predictivePopTransitionSpec: AnimatedContentTransitionScope>.(@NavigationEvent.SwipeEdge Int) -> ContentTransform = { ( slideInHorizontally( initialOffsetX = { -it }, - animationSpec = tween(200) - ) + fadeIn(animationSpec = tween(200)) + animationSpec = tween(DURATION) + ) + fadeIn(animationSpec = tween(DURATION)) ) togetherWith ( slideOutHorizontally( targetOffsetX = { it }, - animationSpec = tween(200) - ) + fadeOut(animationSpec = tween(200)) + animationSpec = tween(DURATION) + ) + fadeOut(animationSpec = tween(DURATION)) ) } } + + /** + * Screens slide in from the bottom and slide out to the bottom, like a sheet. + */ + object VerticalSlide { + private const val DURATION = 300 + + val transitionSpec: AnimatedContentTransitionScope>.() -> ContentTransform = { + slideInVertically( + initialOffsetY = { it }, + animationSpec = tween(DURATION) + ) + fadeIn(animationSpec = tween(DURATION)) togetherWith + fadeOut(animationSpec = tween(DURATION)) + } + + val popTransitionSpec: AnimatedContentTransitionScope>.() -> ContentTransform = { + fadeIn(animationSpec = tween(DURATION)) togetherWith + slideOutVertically( + targetOffsetY = { it }, + animationSpec = tween(DURATION) + ) + fadeOut(animationSpec = tween(DURATION)) + } + + val predictivePopTransitionSpec: AnimatedContentTransitionScope>.(@NavigationEvent.SwipeEdge Int) -> ContentTransform = { + fadeIn(animationSpec = tween(DURATION)) togetherWith + slideOutVertically( + targetOffsetY = { it }, + animationSpec = tween(DURATION) + ) + fadeOut(animationSpec = tween(DURATION)) + } + } } diff --git a/demo/video/src/main/java/org/thoughtcrime/video/app/MainActivity.kt b/demo/video/src/main/java/org/thoughtcrime/video/app/MainActivity.kt index 366d865369..40afe703a6 100644 --- a/demo/video/src/main/java/org/thoughtcrime/video/app/MainActivity.kt +++ b/demo/video/src/main/java/org/thoughtcrime/video/app/MainActivity.kt @@ -85,7 +85,7 @@ private fun TranscodeApp() { backStack = backStack, transitionSpec = TransitionSpecs.HorizontalSlide.transitionSpec, popTransitionSpec = TransitionSpecs.HorizontalSlide.popTransitionSpec, - predictivePopTransitionSpec = TransitionSpecs.HorizontalSlide.predictivePopTransitonSpec, + predictivePopTransitionSpec = TransitionSpecs.HorizontalSlide.predictivePopTransitionSpec, entryProvider = entryProvider { addEntryProvider( key = Screen.VideoSelection, diff --git a/feature/registration/src/main/java/org/signal/registration/RegistrationNavigation.kt b/feature/registration/src/main/java/org/signal/registration/RegistrationNavigation.kt index c46c3a67cc..204586c654 100644 --- a/feature/registration/src/main/java/org/signal/registration/RegistrationNavigation.kt +++ b/feature/registration/src/main/java/org/signal/registration/RegistrationNavigation.kt @@ -8,12 +8,6 @@ package org.signal.registration import android.os.Parcelable -import androidx.compose.animation.core.tween -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.runtime.Composable import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.getValue @@ -32,6 +26,7 @@ import com.google.accompanist.permissions.rememberMultiplePermissionsState import kotlinx.parcelize.Parcelize import kotlinx.serialization.Serializable import org.signal.core.ui.navigation.ResultEffect +import org.signal.core.ui.navigation.TransitionSpecs import org.signal.registration.screens.accountlocked.AccountLockedScreen import org.signal.registration.screens.accountlocked.AccountLockedScreenEvents import org.signal.registration.screens.accountlocked.AccountLockedState @@ -172,51 +167,25 @@ fun RegistrationNavHost( onBack = { viewModel.onEvent(RegistrationFlowEvent.NavigateBack) }, modifier = modifier, transitionSpec = { - // Slide in from right and fade in when navigating forward - ( - slideInHorizontally( - initialOffsetX = { it }, - animationSpec = tween(200) - ) + fadeIn(animationSpec = tween(200)) - ) togetherWith - // Slide out to left and fade out - ( - slideOutHorizontally( - targetOffsetX = { -it }, - animationSpec = tween(200) - ) + fadeOut(animationSpec = tween(200)) - ) + if (targetState.key == RegistrationRoute.CountryCodePicker.toString()) { + TransitionSpecs.VerticalSlide.transitionSpec.invoke(this) + } else { + TransitionSpecs.HorizontalSlide.transitionSpec.invoke(this) + } }, popTransitionSpec = { - // Slide in from left and fade in when navigating back - ( - slideInHorizontally( - initialOffsetX = { -it }, - animationSpec = tween(200) - ) + fadeIn(animationSpec = tween(200)) - ) togetherWith - // Slide out to right and fade out - ( - slideOutHorizontally( - targetOffsetX = { it }, - animationSpec = tween(200) - ) + fadeOut(animationSpec = tween(200)) - ) + if (initialState.key == RegistrationRoute.CountryCodePicker.toString()) { + TransitionSpecs.VerticalSlide.popTransitionSpec.invoke(this) + } else { + TransitionSpecs.HorizontalSlide.popTransitionSpec.invoke(this) + } }, predictivePopTransitionSpec = { - // Same as popTransitionSpec for predictive back gestures - ( - slideInHorizontally( - initialOffsetX = { -it }, - animationSpec = tween(200) - ) + fadeIn(animationSpec = tween(200)) - ) togetherWith - ( - slideOutHorizontally( - targetOffsetX = { it }, - animationSpec = tween(200) - ) + fadeOut(animationSpec = tween(200)) - ) + if (initialState.key == RegistrationRoute.CountryCodePicker.toString()) { + TransitionSpecs.VerticalSlide.predictivePopTransitionSpec.invoke(this, it) + } else { + TransitionSpecs.HorizontalSlide.predictivePopTransitionSpec.invoke(this, it) + } } ) }