Browse Source

Add animation on screen navigation

feature/bma/flipper
ganfra 2 years ago
parent
commit
5dc7999a97
  1. 2
      app/build.gradle
  2. 43
      app/src/main/java/io/element/android/x/MainActivity.kt
  3. 1
      features/messages/build.gradle.kts

2
app/build.gradle

@ -81,7 +81,7 @@ dependencies { @@ -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')

43
app/src/main/java/io/element/android/x/MainActivity.kt

@ -1,4 +1,7 @@ @@ -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 @@ -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) { @@ -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(

1
features/messages/build.gradle.kts

@ -9,7 +9,6 @@ android { @@ -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)

Loading…
Cancel
Save