From b692803ceae6ffbe4f2d8c8d591471c115e72bd7 Mon Sep 17 00:00:00 2001 From: Avently <7953703+avently@users.noreply.github.com> Date: Thu, 6 Oct 2022 01:49:35 +0300 Subject: [PATCH] Experiments --- apps/android/app/build.gradle | 4 +- .../java/chat/simplex/app/MainActivity.kt | 14 ++-- .../app/views/helpers/AnimationUtils.kt | 83 +++++++++++++++++++ 3 files changed, 92 insertions(+), 9 deletions(-) diff --git a/apps/android/app/build.gradle b/apps/android/app/build.gradle index 78fd7e7ce6..3a31f768d6 100644 --- a/apps/android/app/build.gradle +++ b/apps/android/app/build.gradle @@ -5,7 +5,7 @@ plugins { } android { - compileSdk 32 + compileSdk 33 defaultConfig { applicationId "chat.simplex.app" @@ -113,6 +113,8 @@ dependencies { //Camera Permission implementation "com.google.accompanist:accompanist-permissions:0.23.0" + implementation "com.google.accompanist:accompanist-navigation-animation:0.26.4-beta" + // Link Previews implementation 'org.jsoup:jsoup:1.13.1' diff --git a/apps/android/app/src/main/java/chat/simplex/app/MainActivity.kt b/apps/android/app/src/main/java/chat/simplex/app/MainActivity.kt index a23590f408..d5e9ce5931 100644 --- a/apps/android/app/src/main/java/chat/simplex/app/MainActivity.kt +++ b/apps/android/app/src/main/java/chat/simplex/app/MainActivity.kt @@ -29,7 +29,6 @@ import chat.simplex.app.ui.theme.SimpleXTheme import chat.simplex.app.views.SplashView import chat.simplex.app.views.call.ActiveCallView import chat.simplex.app.views.call.IncomingCallAlertView -import chat.simplex.app.views.chat.ChatView import chat.simplex.app.views.chatlist.* import chat.simplex.app.views.database.DatabaseErrorView import chat.simplex.app.views.helpers.* @@ -327,13 +326,12 @@ fun MainPage( else { showAdvertiseLAAlert = true val stopped = chatModel.chatRunning.value == false - AnimateScreensNullable(chatModel.chatId) { currentChatId -> - if (currentChatId == null) { - if (chatModel.sharedContent.value == null) - ChatListView(chatModel, setPerformLA, stopped) - else - ShareListView(chatModel, stopped) - } else ChatView(currentChatId, chatModel) + val nav = ExperimentalAnimationNav(chatModel, setPerformLA, stopped) + val currentChatId = chatModel.chatId.value + LaunchedEffect(currentChatId) { + if (currentChatId == null && nav.backQueue.size == 2) nav.navigate("LEFT") + else if (currentChatId == null) nav.popBackStack() + else nav.navigate("RIGHT") } } } diff --git a/apps/android/app/src/main/java/chat/simplex/app/views/helpers/AnimationUtils.kt b/apps/android/app/src/main/java/chat/simplex/app/views/helpers/AnimationUtils.kt index 12408ccc3d..8c9fbfef24 100644 --- a/apps/android/app/src/main/java/chat/simplex/app/views/helpers/AnimationUtils.kt +++ b/apps/android/app/src/main/java/chat/simplex/app/views/helpers/AnimationUtils.kt @@ -5,6 +5,12 @@ import androidx.compose.animation.core.FastOutSlowInEasing import androidx.compose.animation.core.tween import androidx.compose.runtime.Composable import androidx.compose.runtime.MutableState +import androidx.navigation.NavHostController +import chat.simplex.app.model.ChatModel +import chat.simplex.app.views.chat.ChatView +import chat.simplex.app.views.chatlist.ChatListView +import chat.simplex.app.views.chatlist.ShareListView +import com.google.accompanist.navigation.animation.* @OptIn(ExperimentalAnimationApi::class) @Composable @@ -42,6 +48,83 @@ fun AnimateScreensNullable( ) } +@OptIn(ExperimentalAnimationApi::class) +@Composable +fun ExperimentalAnimationNav(chatModel: ChatModel, setPerformLA: (Boolean) -> Unit, stopped: Boolean, ): NavHostController { + val navController = rememberAnimatedNavController() + AnimatedNavHost(navController, startDestination = "LEFT") { + composable( + "LEFT", + enterTransition = { + when (initialState.destination.route) { + "RIGHT" -> + slideIntoContainer(AnimatedContentScope.SlideDirection.Left, animationSpec = tween(700)) + else -> null + } + }, + exitTransition = { + when (targetState.destination.route) { + "RIGHT" -> + slideOutOfContainer(AnimatedContentScope.SlideDirection.Left, animationSpec = tween(700)) + else -> null + } + }, + popEnterTransition = { + when (initialState.destination.route) { + "RIGHT" -> + slideIntoContainer(AnimatedContentScope.SlideDirection.Right, animationSpec = tween(700)) + else -> null + } + }, + popExitTransition = { + when (targetState.destination.route) { + "RIGHT" -> + slideOutOfContainer(AnimatedContentScope.SlideDirection.Right, animationSpec = tween(700)) + else -> null + } + } + ) { + if (chatModel.sharedContent.value == null) + ChatListView(chatModel, setPerformLA, stopped) + else + ShareListView(chatModel, stopped) + } + composable( + "RIGHT", + enterTransition = { + when (initialState.destination.route) { + "LEFT" -> + slideIntoContainer(AnimatedContentScope.SlideDirection.Left, animationSpec = tween(700)) + else -> null + } + }, + exitTransition = { + when (targetState.destination.route) { + "LEFT" -> + slideOutOfContainer(AnimatedContentScope.SlideDirection.Left, animationSpec = tween(700)) + else -> null + } + }, + popEnterTransition = { + when (initialState.destination.route) { + "LEFT" -> + slideIntoContainer(AnimatedContentScope.SlideDirection.Right, animationSpec = tween(700)) + else -> null + } + }, + popExitTransition = { + when (targetState.destination.route) { + "LEFT" -> + slideOutOfContainer(AnimatedContentScope.SlideDirection.Right, animationSpec = tween(700)) + else -> null + } + } + ) { ChatView("@2", chatModel) } + } + + return navController +} + @OptIn(ExperimentalAnimationApi::class) private fun fromStartToEndTransition() = slideInHorizontally(