Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Impl nested navGraph #1

Merged
merged 1 commit into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions app/src/main/java/dev/devunion/myportfolio/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.navigation.NavHostController
import androidx.navigation.compose.rememberNavController
import dev.devunion.myportfolio.navigation.MainNavGraph
import dev.devunion.myportfolio.navigation.RootNav
import dev.devunion.myportfolio.navigation.Screens
import dev.devunion.myportfolio.navigation.ScreenRoutes

class MainActivity : ComponentActivity() {

Expand All @@ -23,26 +22,26 @@ class MainActivity : ComponentActivity() {
RootNav(
navController = navController
)
val currentApiVersion = Build.VERSION.SDK_INT
if (currentApiVersion < Build.VERSION_CODES.S) {
navigateToSplashScreen()
}
// val currentApiVersion = Build.VERSION.SDK_INT
// if (currentApiVersion < Build.VERSION_CODES.S) {
// navigateToSplashScreen()
// }
}
}

private fun navigateToSplashScreen() {
navController.popBackStack()
navController.navigate(route = Screens.SplashScreen.route)
navController.navigate(route = ScreenRoutes.SplashScreen.route)
}


private fun navigateToMainScreen() {
navController.popBackStack()
navController.navigate(route = Screens.MainScreen.route)
navController.navigate(route = ScreenRoutes.MainScreen.route)
}

private fun navigateToLoginScreen() {
navController.popBackStack()
navController.navigate(route = Screens.LoginScreen.route)
navController.navigate(route = ScreenRoutes.LoginScreen.route)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package dev.devunion.myportfolio.models

import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.outlined.Home
import androidx.compose.ui.graphics.vector.ImageVector
import dev.devunion.myportfolio.R
import dev.devunion.myportfolio.navigation.ScreenRoutes

sealed class BottomNavItems(
val title: String,
val route: String,
val icon: ImageVector
) {
data object HomeItem : BottomNavItems(
title = "Home",
route = ScreenRoutes.HomeScreen.route,
icon = Icons.Outlined.Home,
)

data object Profile : BottomNavItems(
title = "Profile",
route = ScreenRoutes.AccountScreen.route,
icon = Icons.Outlined.Home
)
}
18 changes: 11 additions & 7 deletions app/src/main/java/dev/devunion/myportfolio/navigation/AuthNav.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import androidx.navigation.NavHostController
import androidx.navigation.compose.composable
import androidx.navigation.compose.navigation
import dev.devunion.myportfolio.ui.auth.login.LoginScreen
import dev.devunion.myportfolio.ui.auth.reset_password.ResetPasswordScreen
import dev.devunion.myportfolio.ui.auth.signup.SignUpScreen
import dev.devunion.myportfolio.viewmodels.auth.FirebaseAuthViewModel

Expand All @@ -14,15 +15,18 @@ fun NavGraphBuilder.AuthNav(
) {
val authViewModel = FirebaseAuthViewModel()
navigation(
startDestination = Screens.LoginScreen.route,
route = Screens.AuthNav.route
){
composable(route = Screens.SignUpScreen.route){
SignUpScreen(authViewModel,navController = navController)
startDestination = ScreenRoutes.LoginScreen.route,
route = ScreenRoutes.AuthNav.route
) {
composable(route = ScreenRoutes.LoginScreen.route) {
LoginScreen(authViewModel, navController = navController)
}
composable(route = ScreenRoutes.SignUpScreen.route) {
SignUpScreen(authViewModel, navController = navController)
}

composable(route = Screens.LoginScreen.route){
LoginScreen(authViewModel,navController = navController)
composable(route = ScreenRoutes.ResetPasswordScreen.route) {
ResetPasswordScreen(authViewModel, navController = navController)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,52 +16,46 @@ import dev.devunion.myportfolio.ui.main.MainScreen
import dev.devunion.myportfolio.ui.profile.ProfileScreen
import dev.devunion.myportfolio.ui.splash.SplashScreen
import dev.devunion.myportfolio.ui.updates.UpdatesScreen
import dev.devunion.myportfolio.utils.PreferenceHelper
import dev.devunion.myportfolio.viewmodels.auth.FirebaseAuthViewModel

@Composable
fun MainNavGraph(navController: NavHostController) {
fun MainNavGraph(navController: NavHostController, logout: () -> Unit) {
val user = Firebase.auth.currentUser
val context = LocalContext.current
// val preferenceHelper: PreferenceHelper = PreferenceHelper(context)
val preferenceHelper: PreferenceHelper = PreferenceHelper(context)

NavHost(
navController = navController,
route = Screens.MainNav.route,
startDestination = when (user) {
null -> Screens.LoginScreen.route
else -> Screens.MainScreen.route
}
route = ScreenRoutes.MainNav.route,
startDestination = ScreenRoutes.HomeScreen.route


) {

composable(route = Screens.SplashScreen.route) {
SplashScreen(navController)
}
composable(route = Screens.MainScreen.route) {
MainScreen(navController)
composable(route = ScreenRoutes.HomeScreen.route) {
HomeScreen(navController)
}
composable(route = Screens.LoginScreen.route) {
val authViewModel = FirebaseAuthViewModel()
LoginScreen(authViewModel, navController)
composable(route = ScreenRoutes.ProfileScreen.route) {
ProfileScreen(navController)
}
composable(route = Screens.SignUpScreen.route) {
val authViewModel = FirebaseAuthViewModel()
SignUpScreen(authViewModel, navController)
composable(route = ScreenRoutes.UpdatesScreen.route) {
UpdatesScreen(navController)
}
composable(route = Screens.ResetPasswordScreen.route) {
composable(route = ScreenRoutes.AccountScreen.route) {
val authViewModel = FirebaseAuthViewModel()
ResetPasswordScreen(authViewModel, navController)
AccountScreen(authViewModel, navController, logout)
}


/* composable(route = Screens.OnboardingScreen.route) {
/* composable(route = ScreenRoutes.OnboardingScreen.route) {
OnboardingScreen {
navController.popBackStack()
navController.navigate(route = Screens.AuthScreen.route)
navController.navigate(route = ScreenRoutes.AuthScreen.route)
}
}

composable(route = Screens.AuthScreen.route, enterTransition = {
composable(route = ScreenRoutes.AuthScreen.route, enterTransition = {
slideIntoContainer(
AnimatedContentTransitionScope.SlideDirection.Left, animationSpec = tween(700)
)
Expand All @@ -72,35 +66,35 @@ fun MainNavGraph(navController: NavHostController) {
}) {
AuthScreen(navigateToMainScreen = {
navController.popBackStack()
navController.navigate(route = Screens.MainScreen.route)
navController.navigate(route = ScreenRoutes.MainScreen.route)
})
}*/


}
}

@Composable
fun BottomNavGraph(
navController: NavHostController
) {

NavHost(
navController = navController,
startDestination = Screens.HomeScreen.route
) {
composable(route = Screens.HomeScreen.route) {
HomeScreen(navController)
}
composable(route = Screens.ProfileScreen.route) {
ProfileScreen(navController)
}
composable(route = Screens.UpdatesScreen.route) {
UpdatesScreen(navController)
}
composable(route = Screens.AccountScreen.route) {
val authViewModel = FirebaseAuthViewModel()
AccountScreen(authViewModel, navController)
}
}
}
//@Composable
//fun BottomNavGraph(
// navController: NavHostController
//) {
//
// NavHost(
// navController = navController,
// startDestination = ScreenRoutes.HomeScreen.route
// ) {
// composable(route = ScreenRoutes.HomeScreen.route) {
// HomeScreen(navController)
// }
// composable(route = ScreenRoutes.ProfileScreen.route) {
// ProfileScreen(navController)
// }
// composable(route = ScreenRoutes.UpdatesScreen.route) {
// UpdatesScreen(navController)
// }
// composable(route = ScreenRoutes.AccountScreen.route) {
// val authViewModel = FirebaseAuthViewModel()
// AccountScreen(authViewModel, navController)
// }
// }
//}
31 changes: 16 additions & 15 deletions app/src/main/java/dev/devunion/myportfolio/navigation/RootNav.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,32 @@ import androidx.compose.runtime.Composable
import androidx.navigation.NavHostController
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.compose.navigation
import androidx.navigation.compose.rememberNavController
import com.google.firebase.auth.ktx.auth
import com.google.firebase.ktx.Firebase
import dev.devunion.myportfolio.ui.main.MainScreen


@Composable
fun RootNav(navController: NavHostController) {
val user = Firebase.auth.currentUser
NavHost(
navController = navController,
startDestination = Screens.MainNav.route
startDestination = when (user) {
null -> ScreenRoutes.AuthNav.route
else -> ScreenRoutes.MainNav.route
}
) {

AuthNav(navController)
composable(route = Screens.MainNav.route) {
MainNavGraph(navController = navController)
}

// composable(route = Screens.MainNav.route){
// MainScreen(navController
// logout = {
// navController.navigate(Screens.AuthNav.route) {
// popUpTo(0){}
// }
// }
// )
// }
composable(route = ScreenRoutes.MainNav.route) {
MainScreen(navController,
logout = {
navController.navigate(ScreenRoutes.AuthNav.route) {
popUpTo(0) {}
}
}
)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package dev.devunion.myportfolio.navigation


sealed class ScreenRoutes(val route: String) {
// object OnboardingScreen : ScreenRoutes("onboarding_screen")
//
// // Onboarding screens
// data object OnboardingScreen1 : ScreenRoutes("onboarding_screen_1")
// data object OnboardingScreen2 : ScreenRoutes("onboarding_screen_2")
// data object OnboardingScreen3 : ScreenRoutes("onboarding_screen_3")
// data object OnboardingScreen4 : ScreenRoutes("onboarding_screen_4")

// App screens
data object SplashScreen : ScreenRoutes("splash_screen")

data object MainScreen : ScreenRoutes("main_screen")

data object LoginScreen : ScreenRoutes("login_screen")
data object SignUpScreen : ScreenRoutes("signup_screen")
data object ResetPasswordScreen : ScreenRoutes("reset_password_screen")

data object HomeScreen : ScreenRoutes("home_screen")
data object ProfileScreen : ScreenRoutes("profile_screen")
data object UpdatesScreen : ScreenRoutes("updates_screen")
data object AccountScreen : ScreenRoutes("account_screen")

//Graph Routes
data object AuthNav : ScreenRoutes("AUTH_NAV_GRAPH")

data object MainNav : ScreenRoutes("MAIN_NAV_GRAPH")
}
31 changes: 0 additions & 31 deletions app/src/main/java/dev/devunion/myportfolio/navigation/Screens.kt

This file was deleted.

Loading