ソースを参照

remove default animations in navigation, set color of tabRow..

Khubaib 1 年間 前
コミット
7a2ae3c037

+ 26 - 2
app/src/main/java/com/vpn/fastestvpnservice/navigation/BottomBarNavGraph.kt

@@ -1,8 +1,15 @@
 package com.vpn.fastestvpnservice.navigation
 
 import androidx.activity.ComponentActivity
+import androidx.compose.animation.AnimatedContentTransitionScope
+import androidx.compose.animation.EnterTransition
+import androidx.compose.animation.ExitTransition
+import androidx.compose.animation.core.tween
+import androidx.compose.animation.fadeIn
+import androidx.compose.animation.fadeOut
 import androidx.compose.material.Surface
 import androidx.compose.runtime.Composable
+import androidx.navigation.NavBackStackEntry
 import androidx.navigation.NavHostController
 import androidx.navigation.compose.NavHost
 import androidx.navigation.compose.composable
@@ -31,8 +38,25 @@ fun BottomBarNavGraph(navHostController: NavHostController,
                       settingsNavHostController: NavHostController,
                       activity: ComponentActivity
 ) {
-        NavHost(navController = navHostController,
-            startDestination = BottomBarScreen.Home.route) {
+    val noEnterTransition : AnimatedContentTransitionScope<NavBackStackEntry>.() -> EnterTransition = {
+        fadeIn(
+            animationSpec = tween(durationMillis = 0),
+            initialAlpha = 1f
+        )
+    }
+
+    val noExitTransition : AnimatedContentTransitionScope<NavBackStackEntry>.() -> ExitTransition = {
+        fadeOut(
+            animationSpec = tween(durationMillis = 0),
+            targetAlpha = 1f
+        )
+    }
+        NavHost(
+            navController = navHostController,
+            startDestination = BottomBarScreen.Home.route,
+            enterTransition = noEnterTransition,
+            exitTransition = noExitTransition
+            ) {
 
             composable(route = BottomBarScreen.Home.route) {
                 Home(navHostController = navHostController, activity)

+ 19 - 0
app/src/main/java/com/vpn/fastestvpnservice/navigation/NavGraph.kt

@@ -1,13 +1,18 @@
 package com.vpn.fastestvpnservice.navigation
 
 import androidx.activity.ComponentActivity
+import androidx.compose.animation.AnimatedContentTransitionScope
+import androidx.compose.animation.EnterTransition
+import androidx.compose.animation.ExitTransition
 import androidx.compose.animation.core.FastOutSlowInEasing
 import androidx.compose.animation.core.LinearEasing
 import androidx.compose.animation.core.tween
 import androidx.compose.animation.fadeIn
+import androidx.compose.animation.fadeOut
 import androidx.compose.animation.slideInVertically
 import androidx.compose.runtime.Composable
 import androidx.lifecycle.viewmodel.compose.viewModel
+import androidx.navigation.NavBackStackEntry
 import androidx.navigation.NavHostController
 import androidx.navigation.compose.NavHost
 import androidx.navigation.compose.composable
@@ -25,10 +30,24 @@ import com.vpn.fastestvpnservice.sealedClass.Screen
 fun SetUpNavGraph(navHostController: NavHostController,
                   activity: ComponentActivity
 ) {
+    val noEnterTransition : AnimatedContentTransitionScope<NavBackStackEntry>.() -> EnterTransition = {
+        fadeIn(
+            animationSpec = tween(durationMillis = 0),
+            initialAlpha = 1f
+        )
+    }
 
+    val noExitTransition : AnimatedContentTransitionScope<NavBackStackEntry>.() -> ExitTransition = {
+        fadeOut(
+            animationSpec = tween(durationMillis = 0),
+            targetAlpha = 1f
+        )
+    }
 
     NavHost(navController = navHostController,
         startDestination = Screen.Splash.route,
+        enterTransition = noEnterTransition,
+        exitTransition = noExitTransition
         ) {
         composable(route = Screen.Splash.route) {
             Splash(navHostController)

+ 21 - 17
app/src/main/java/com/vpn/fastestvpnservice/screens/ServerListScreen.kt

@@ -131,18 +131,19 @@ fun ServerList(
         ) {
             ShowSearchBar(serverListViewModel, basePreferenceHelper, navHostController)
 
+            val currentPageIndex = if (Screen.ServerList.isTrue) 1 else 0
+            val scope = rememberCoroutineScope()
             val serverTabItems = listOf("Recommended", "All Locations")
-            val pagerState = rememberPagerState(pageCount = {serverTabItems.size})
+            val pagerState = rememberPagerState(initialPage = currentPageIndex, pageCount = {serverTabItems.size})
             val selectedIndex by remember { derivedStateOf { pagerState.currentPage } }
-            val scope = rememberCoroutineScope()
 
-            if (Screen.ServerList.isTrue) {
-                LaunchedEffect(key1 = true) {
-                    scope.launch {
-                        pagerState.animateScrollToPage(1)
-                    }
-                }
-            }
+//            if (Screen.ServerList.isTrue) {
+//                LaunchedEffect(key1 = true) {
+//                    scope.launch {
+//                        pagerState.animateScrollToPage(1)
+//                    }
+//                }
+//            }
 
             // Tab Row [Recommended, All Locations]
 
@@ -177,14 +178,17 @@ fun ServerList(
                 ) {
                     serverTabItems.forEachIndexed { index, currentTab ->
 
-                        val color = remember { Animatable(Color.White) }
+//                        val color = remember { Animatable(Color.White) }
+                        var colorTab by remember { mutableStateOf(Color.White) }
+                        colorTab = if (selectedIndex == index) Color(0xFFE9EDF9)
+                        else Color.White
 
-                        LaunchedEffect(key1 = selectedIndex == index) {
-                            color.animateTo(
-                                if (selectedIndex == index) Color(0xFFE9EDF9)
-                                else Color.White
-                            )
-                        }
+//                        LaunchedEffect(key1 = selectedIndex == index) {
+//                            color.animateTo(
+//                                if (selectedIndex == index) Color(0xFFE9EDF9)
+//                                else Color.White
+//                            )
+//                        }
 
                         Tab(
                             selected = selectedIndex == index,
@@ -205,7 +209,7 @@ fun ServerList(
                                     top = 10.dp, bottom = 10.dp
                                 )
                                 .background(
-                                    color = color.value,
+                                    color = colorTab,
                                     shape = RoundedCornerShape(20.dp)
                                 )