瀏覽代碼

working on animations, need to fast navigation..

Khubaib 1 年之前
父節點
當前提交
7746f54021

+ 17 - 1
app/src/main/java/com/vpn/fastestvpnservice/navigation/NavGraph.kt

@@ -1,6 +1,11 @@
 package com.vpn.fastestvpnservice.navigation
 
 import androidx.activity.ComponentActivity
+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.slideInVertically
 import androidx.compose.runtime.Composable
 import androidx.lifecycle.viewmodel.compose.viewModel
 import androidx.navigation.NavHostController
@@ -20,6 +25,8 @@ import com.vpn.fastestvpnservice.sealedClass.Screen
 fun SetUpNavGraph(navHostController: NavHostController,
                   activity: ComponentActivity
 ) {
+
+
     NavHost(navController = navHostController,
         startDestination = Screen.Splash.route,
         ) {
@@ -45,4 +52,13 @@ fun SetUpNavGraph(navHostController: NavHostController,
             TermsAndConditions(navHostController = navHostController, true)
         }
     }
-}
+}
+
+// Define custom navigation animations
+val navigationAnimation = slideInVertically(
+    initialOffsetY = { -it },
+    animationSpec = tween(
+        durationMillis = 500, // Adjust duration to slow down animation
+        easing = LinearEasing // Apply easing for smooth transition
+    )
+) + fadeIn() // Apply fade-in animation

+ 26 - 15
app/src/main/java/com/vpn/fastestvpnservice/screens/BottomBarMainScreen.kt

@@ -4,6 +4,7 @@ import android.app.Activity
 import android.content.res.Configuration
 import android.util.Log
 import androidx.activity.ComponentActivity
+import androidx.compose.animation.AnimatedVisibility
 import androidx.compose.foundation.layout.Box
 import androidx.compose.foundation.layout.Column
 import androidx.compose.foundation.layout.RowScope
@@ -22,6 +23,7 @@ import androidx.compose.material3.MaterialTheme
 import androidx.compose.material3.Scaffold
 import androidx.compose.material3.Text
 import androidx.compose.runtime.Composable
+import androidx.compose.runtime.LaunchedEffect
 import androidx.compose.runtime.getValue
 import androidx.compose.runtime.mutableStateOf
 import androidx.compose.runtime.remember
@@ -41,6 +43,7 @@ import androidx.navigation.compose.currentBackStackEntryAsState
 import androidx.navigation.compose.rememberNavController
 import com.vpn.fastestvpnservice.R
 import com.vpn.fastestvpnservice.navigation.BottomBarNavGraph
+import com.vpn.fastestvpnservice.navigation.navigationAnimation
 import com.vpn.fastestvpnservice.sealedClass.BottomBarScreen
 import com.vpn.fastestvpnservice.ui.theme.customTypography2
 
@@ -109,8 +112,30 @@ fun RowScope.AddItem(
     currentDestination: NavDestination?,
     navHostController: NavHostController
 ) {
+    var isClicked by remember { mutableStateOf(false) }
     val route = currentRoute(navController = navHostController)
     Log.d("currentRoute -> ", route.toString())
+
+    if (isClicked) {
+        if (currentDestination?.route != screen.route) {
+            Log.d("test_bottom_navbar",
+                "currentDestination -> " + currentDestination?.route
+                        + "Screen Clicked -> " + screen.route
+            )
+
+            LaunchedEffect(Unit) {
+                navHostController.navigate(screen.route) {
+                    popUpTo(
+                        navHostController.graph
+                            .findStartDestination().id) {
+                        saveState = true
+                    }
+                    launchSingleTop = true
+                }
+            }
+        }
+        isClicked = false
+    }
     BottomNavigationItem(
         label = {
             if (currentDestination?.route == screen.route) {
@@ -132,24 +157,10 @@ fun RowScope.AddItem(
             it.route == screen.route
         } == true,
         onClick = {
+            isClicked = true
 
             /* First time currentDestination is different when on BottomBar Item */
 
-            if (currentDestination?.route != screen.route) {
-                Log.d("test_bottom_navbar",
-                    "currentDestination -> " + currentDestination?.route
-                            + "Screen Clicked -> " + screen.route
-                )
-
-                navHostController.navigate(screen.route) {
-                    popUpTo(
-                        navHostController.graph
-                            .findStartDestination().id) {
-                        saveState = true
-                    }
-                    launchSingleTop = true
-                }
-            }
         },
         icon = {
             if (currentDestination?.route == screen.route) {

+ 3 - 0
app/src/main/java/com/vpn/fastestvpnservice/screens/bottomNavBarScreens/AccountScreen.kt

@@ -3,6 +3,7 @@ package com.vpn.fastestvpnservice.screens.bottomNavBarScreens
 import android.content.res.Configuration
 import android.util.Log
 import android.widget.Toast
+import androidx.compose.animation.AnimatedVisibility
 import androidx.compose.foundation.Image
 import androidx.compose.foundation.background
 import androidx.compose.foundation.gestures.detectTapGestures
@@ -59,6 +60,7 @@ import androidx.navigation.NavHostController
 import androidx.navigation.compose.rememberNavController
 import com.vpn.fastestvpnservice.R
 import com.vpn.fastestvpnservice.helpers.BasePreferenceHelper
+import com.vpn.fastestvpnservice.navigation.navigationAnimation
 import com.vpn.fastestvpnservice.sealedClass.Screen
 import com.vpn.fastestvpnservice.viewmodels.AccountViewModel
 import kotlinx.coroutines.delay
@@ -70,6 +72,7 @@ import kotlinx.coroutines.delay
 fun Account(navHostController: NavHostController,
             settingsNavHostController: NavHostController)
 {
+
     var isLoggedOut by remember { mutableStateOf(false) }
     var isDelete by remember { mutableStateOf(false) }
 

+ 3 - 0
app/src/main/java/com/vpn/fastestvpnservice/screens/bottomNavBarScreens/HelpScreen.kt

@@ -1,6 +1,7 @@
 package com.vpn.fastestvpnservice.screens.bottomNavBarScreens
 
 import android.util.Log
+import androidx.compose.animation.AnimatedVisibility
 import androidx.compose.foundation.Image
 import androidx.compose.foundation.background
 import androidx.compose.foundation.clickable
@@ -51,10 +52,12 @@ import androidx.compose.ui.unit.sp
 import androidx.navigation.NavHostController
 import androidx.navigation.compose.rememberNavController
 import com.vpn.fastestvpnservice.R
+import com.vpn.fastestvpnservice.navigation.navigationAnimation
 import com.vpn.fastestvpnservice.sealedClass.Screen
 
 @Composable
 fun Help(navHostController: NavHostController) {
+
     Box(modifier = Modifier
         .background(MaterialTheme.colorScheme.background)
         .fillMaxSize(),

+ 5 - 2
app/src/main/java/com/vpn/fastestvpnservice/screens/bottomNavBarScreens/HomeScreen.kt

@@ -7,6 +7,7 @@ import android.os.Handler
 import android.util.Log
 import android.widget.Toast
 import androidx.activity.ComponentActivity
+import androidx.compose.animation.AnimatedVisibility
 import androidx.compose.foundation.BorderStroke
 import androidx.compose.foundation.ExperimentalFoundationApi
 import androidx.compose.foundation.Image
@@ -104,6 +105,7 @@ import com.vpn.fastestvpnservice.constants.AppEnum
 import com.vpn.fastestvpnservice.constants.smartConnect
 import com.vpn.fastestvpnservice.helpers.BasePreferenceHelper
 import com.vpn.fastestvpnservice.interfaces.ServerCallbacks
+import com.vpn.fastestvpnservice.navigation.navigationAnimation
 import com.vpn.fastestvpnservice.sealedClass.BottomBarScreen
 import com.vpn.fastestvpnservice.ui.theme.FastestVPNTheme
 import com.vpn.fastestvpnservice.ui.theme.customTypography
@@ -202,6 +204,7 @@ lateinit var homeViewModel1: HomeViewModel
 @OptIn(ExperimentalFoundationApi::class, ExperimentalMaterial3Api::class)
 @Composable
 fun Home(navHostController: NavHostController, activity: ComponentActivity) {
+
     Log.d("OnChangeProtocol", "Home called!")
     navHostController1 = navHostController
 
@@ -634,7 +637,7 @@ fun Home(navHostController: NavHostController, activity: ComponentActivity) {
                             .fillMaxWidth()
                             .padding(20.dp)
                             .padding(top = 0.dp)
-                            .height(114.dp)
+                            .height(120.dp)
                             .border(
                                 border = BorderStroke(2.dp, Color.White),
                                 shape = RoundedCornerShape(28.dp)
@@ -682,7 +685,7 @@ fun Home(navHostController: NavHostController, activity: ComponentActivity) {
                                 .align(Alignment.BottomCenter)
                                 .background(colorResource(id = R.color.transparent))
                                 .fillMaxWidth()
-                                .height(35.dp),
+                                .height(40.dp),
                             shape = RoundedCornerShape(16.dp),
                             colors = ButtonDefaults.buttonColors(
                                 contentColor = colorResource(id = R.color.white),

+ 3 - 0
app/src/main/java/com/vpn/fastestvpnservice/screens/bottomNavBarScreens/SettingsScreen.kt

@@ -8,6 +8,7 @@ import android.os.Build
 import android.os.Bundle
 import android.util.Log
 import android.widget.Toast
+import androidx.compose.animation.AnimatedVisibility
 import androidx.compose.foundation.Image
 import androidx.compose.foundation.background
 import androidx.compose.foundation.clickable
@@ -97,6 +98,7 @@ import com.vpn.fastestvpnservice.beans.themesList
 import com.vpn.fastestvpnservice.constants.AppEnum
 import com.vpn.fastestvpnservice.constants.smartConnect
 import com.vpn.fastestvpnservice.helpers.BasePreferenceHelper
+import com.vpn.fastestvpnservice.navigation.navigationAnimation
 import com.vpn.fastestvpnservice.sealedClass.BottomBarScreen
 import com.vpn.fastestvpnservice.sealedClass.Screen
 import kotlinx.coroutines.launch
@@ -105,6 +107,7 @@ import kotlinx.coroutines.launch
 @Composable
 fun Settings(navHostController: NavHostController) {
 
+
     Box(modifier = Modifier
         .background(MaterialTheme.colorScheme.background)
         .fillMaxSize(),