Add animation on screen navigation
This commit is contained in:
@@ -81,7 +81,7 @@ dependencies {
|
||||
implementation project(":features:messages")
|
||||
|
||||
coreLibraryDesugaring "com.android.tools:desugar_jdk_libs:1.2.0"
|
||||
implementation 'io.github.raamcosta.compose-destinations:core:1.7.23-beta'
|
||||
implementation 'io.github.raamcosta.compose-destinations:animations-core:1.7.23-beta'
|
||||
ksp 'io.github.raamcosta.compose-destinations:ksp:1.7.23-beta'
|
||||
|
||||
def composeBom = platform('androidx.compose:compose-bom:2022.10.00')
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
@file:OptIn(ExperimentalMaterial3Api::class)
|
||||
@file:OptIn(
|
||||
ExperimentalAnimationApi::class,
|
||||
ExperimentalMaterialNavigationApi::class
|
||||
)
|
||||
|
||||
package io.element.android.x
|
||||
|
||||
@@ -6,14 +9,18 @@ import android.os.Bundle
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.activity.compose.setContent
|
||||
import androidx.activity.viewModels
|
||||
import androidx.compose.animation.AnimatedContentScope
|
||||
import androidx.compose.animation.ExperimentalAnimationApi
|
||||
import androidx.compose.animation.core.tween
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import com.google.accompanist.navigation.material.ExperimentalMaterialNavigationApi
|
||||
import com.ramcosta.composedestinations.DestinationsNavHost
|
||||
import com.ramcosta.composedestinations.rememberNavHostEngine
|
||||
import com.ramcosta.composedestinations.animations.defaults.RootNavGraphDefaultAnimations
|
||||
import com.ramcosta.composedestinations.animations.rememberAnimatedNavHostEngine
|
||||
import com.ramcosta.composedestinations.spec.Route
|
||||
import io.element.android.x.core.compose.OnLifecycleEvent
|
||||
import io.element.android.x.designsystem.ElementXTheme
|
||||
@@ -55,9 +62,37 @@ private fun MainScreen(viewModel: MainViewModel) {
|
||||
}
|
||||
}
|
||||
|
||||
private const val transitionAnimationDuration = 500
|
||||
@Composable
|
||||
private fun MainContent(startRoute: Route) {
|
||||
val engine = rememberNavHostEngine()
|
||||
val engine = rememberAnimatedNavHostEngine(
|
||||
rootDefaultAnimations = RootNavGraphDefaultAnimations(
|
||||
enterTransition = {
|
||||
slideIntoContainer(
|
||||
AnimatedContentScope.SlideDirection.Left,
|
||||
animationSpec = tween(transitionAnimationDuration)
|
||||
)
|
||||
},
|
||||
exitTransition = {
|
||||
slideOutOfContainer(
|
||||
AnimatedContentScope.SlideDirection.Left,
|
||||
animationSpec = tween(transitionAnimationDuration)
|
||||
)
|
||||
},
|
||||
popEnterTransition = {
|
||||
slideIntoContainer(
|
||||
AnimatedContentScope.SlideDirection.Right,
|
||||
animationSpec = tween(transitionAnimationDuration)
|
||||
)
|
||||
},
|
||||
popExitTransition = {
|
||||
slideOutOfContainer(
|
||||
AnimatedContentScope.SlideDirection.Right,
|
||||
animationSpec = tween(transitionAnimationDuration)
|
||||
)
|
||||
}
|
||||
)
|
||||
)
|
||||
val navController = engine.rememberNavController()
|
||||
|
||||
DestinationsNavHost(
|
||||
|
||||
@@ -9,7 +9,6 @@ android {
|
||||
dependencies {
|
||||
implementation(project(":libraries:core"))
|
||||
implementation(project(":libraries:matrix"))
|
||||
implementation(project(":libraries:blurhash"))
|
||||
implementation(project(":libraries:designsystem"))
|
||||
implementation(project(":libraries:textcomposer"))
|
||||
implementation(libs.mavericks.compose)
|
||||
|
||||
Reference in New Issue
Block a user