Add animation on screen navigation
This commit is contained in:
parent
a53b1c6aa2
commit
f356e2262b
3 changed files with 40 additions and 6 deletions
|
|
@ -81,7 +81,7 @@ dependencies {
|
||||||
implementation project(":features:messages")
|
implementation project(":features:messages")
|
||||||
|
|
||||||
coreLibraryDesugaring "com.android.tools:desugar_jdk_libs:1.2.0"
|
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'
|
ksp 'io.github.raamcosta.compose-destinations:ksp:1.7.23-beta'
|
||||||
|
|
||||||
def composeBom = platform('androidx.compose:compose-bom:2022.10.00')
|
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
|
package io.element.android.x
|
||||||
|
|
||||||
|
|
@ -6,14 +9,18 @@ import android.os.Bundle
|
||||||
import androidx.activity.ComponentActivity
|
import androidx.activity.ComponentActivity
|
||||||
import androidx.activity.compose.setContent
|
import androidx.activity.compose.setContent
|
||||||
import androidx.activity.viewModels
|
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.foundation.background
|
||||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
|
||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.tooling.preview.Preview
|
import androidx.compose.ui.tooling.preview.Preview
|
||||||
|
import com.google.accompanist.navigation.material.ExperimentalMaterialNavigationApi
|
||||||
import com.ramcosta.composedestinations.DestinationsNavHost
|
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 com.ramcosta.composedestinations.spec.Route
|
||||||
import io.element.android.x.core.compose.OnLifecycleEvent
|
import io.element.android.x.core.compose.OnLifecycleEvent
|
||||||
import io.element.android.x.designsystem.ElementXTheme
|
import io.element.android.x.designsystem.ElementXTheme
|
||||||
|
|
@ -55,9 +62,37 @@ private fun MainScreen(viewModel: MainViewModel) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private const val transitionAnimationDuration = 500
|
||||||
@Composable
|
@Composable
|
||||||
private fun MainContent(startRoute: Route) {
|
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()
|
val navController = engine.rememberNavController()
|
||||||
|
|
||||||
DestinationsNavHost(
|
DestinationsNavHost(
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,6 @@ android {
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation(project(":libraries:core"))
|
implementation(project(":libraries:core"))
|
||||||
implementation(project(":libraries:matrix"))
|
implementation(project(":libraries:matrix"))
|
||||||
implementation(project(":libraries:blurhash"))
|
|
||||||
implementation(project(":libraries:designsystem"))
|
implementation(project(":libraries:designsystem"))
|
||||||
implementation(project(":libraries:textcomposer"))
|
implementation(project(":libraries:textcomposer"))
|
||||||
implementation(libs.mavericks.compose)
|
implementation(libs.mavericks.compose)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue