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

[Feature] LoginNavGraph & LoginMainDestination 만들기 #12

Merged
merged 3 commits into from
Jan 24, 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
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,7 @@ import ac.dnd.bookkeeping.android.presentation.ui.main.home.homeDestination
import ac.dnd.bookkeeping.android.presentation.ui.main.login.loginNavGraph
import ac.dnd.bookkeeping.android.presentation.ui.main.splash.SplashConstant
import ac.dnd.bookkeeping.android.presentation.ui.main.splash.splashDestination
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Surface
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.navigation.compose.NavHost

Expand All @@ -20,30 +15,19 @@ fun MainScreen(
viewModel: MainViewModel = hiltViewModel()
) {
BookkeepingTheme {
Surface(
modifier = Modifier.fillMaxSize(),
color = MaterialTheme.colors.background
) {
val appState = rememberApplicationState()
ManageSystemUiState(appState = appState)
val appState = rememberApplicationState()
ManageSystemUiState(appState = appState)

NavHost(
navController = appState.navController,
startDestination = makeRoute(
SplashConstant.ROUTE,
listOf(SplashConstant.ROUTE_ARGUMENT_ENTRY_POINT_MAIN to SplashConstant.ROUTE_ARGUMENT_ENTRY_POINT_MAIN)
)
) {
loginNavGraph(appState = appState)
homeDestination(appState = appState)
splashDestination(appState = appState)
}
NavHost(
navController = appState.navController,
startDestination = makeRoute(
SplashConstant.ROUTE,
listOf(SplashConstant.ROUTE_ARGUMENT_ENTRY_POINT_MAIN to SplashConstant.ROUTE_ARGUMENT_ENTRY_POINT_MAIN)
)
) {
loginNavGraph(appState = appState)
homeDestination(appState = appState)
splashDestination(appState = appState)
}
}
}

@Preview
@Composable
fun PreviewMainUi() {
MainScreen()
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package ac.dnd.bookkeeping.android.presentation.ui.main

import ac.dnd.bookkeeping.android.presentation.common.util.parseRoute
import ac.dnd.bookkeeping.android.presentation.ui.main.splash.SplashConstant
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.navigation.compose.currentBackStackEntryAsState
Expand All @@ -15,15 +14,9 @@ fun ManageSystemUiState(
parseRoute(it).first
}.orEmpty()

when {
route.startsWith(SplashConstant.ROUTE) -> {
appState.systemUiController.isStatusBarVisible = false
appState.systemUiController.isNavigationBarVisible = false
}

when (route) {
else -> {
appState.systemUiController.isStatusBarVisible = false
appState.systemUiController.isNavigationBarVisible = true
appState.systemUiController.isStatusBarVisible = true
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,4 @@ package ac.dnd.bookkeeping.android.presentation.ui.main.login

object LoginConstant {
const val ROUTE = "/login"

const val ROUTE_STEP_1 = "$ROUTE/step1"
const val ROUTE_STEP_2 = "$ROUTE/step2"
}
Original file line number Diff line number Diff line change
@@ -1,39 +1,18 @@
package ac.dnd.bookkeeping.android.presentation.ui.main.login

import ac.dnd.bookkeeping.android.presentation.ui.main.ApplicationState
import androidx.compose.runtime.remember
import androidx.hilt.navigation.compose.hiltViewModel
import ac.dnd.bookkeeping.android.presentation.ui.main.login.main.LoginMainConstant
import ac.dnd.bookkeeping.android.presentation.ui.main.login.main.loginMainDestination
import androidx.navigation.NavGraphBuilder
import androidx.navigation.compose.composable
import androidx.navigation.navigation

fun NavGraphBuilder.loginNavGraph(
appState: ApplicationState
) {
navigation(
startDestination = LoginConstant.ROUTE_STEP_1,
startDestination = LoginMainConstant.ROUTE,
route = LoginConstant.ROUTE
) {
// TODO : 분리
composable(
route = LoginConstant.ROUTE_STEP_1
) {
val backStackEntry = remember(it) {
appState.navController.getBackStackEntry(LoginConstant.ROUTE_STEP_1)
}
val loginViewModel: LoginViewModel = hiltViewModel(backStackEntry)
LoginScreen(appState = appState, viewModel = loginViewModel)
}

// TODO : 분리
composable(
route = LoginConstant.ROUTE_STEP_2
) {
val backStackEntry = remember(it) {
appState.navController.getBackStackEntry(LoginConstant.ROUTE)
}
val loginViewModel: LoginViewModel = hiltViewModel(backStackEntry)
OnBoardScreen(appState = appState, viewModel = loginViewModel)
}
loginMainDestination(appState = appState)
}
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package ac.dnd.bookkeeping.android.presentation.ui.main.login.main

import ac.dnd.bookkeeping.android.presentation.ui.main.login.LoginConstant

object LoginMainConstant {
const val ROUTE: String = "${LoginConstant.ROUTE}/main"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package ac.dnd.bookkeeping.android.presentation.ui.main.login.main

import ac.dnd.bookkeeping.android.presentation.common.util.ErrorObserver
import ac.dnd.bookkeeping.android.presentation.ui.main.ApplicationState
import ac.dnd.bookkeeping.android.presentation.ui.main.login.LoginConstant
import ac.dnd.bookkeeping.android.presentation.ui.main.login.LoginViewModel
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.navigation.NavGraphBuilder
import androidx.navigation.compose.composable

fun NavGraphBuilder.loginMainDestination(
ajou4095 marked this conversation as resolved.
Show resolved Hide resolved
appState: ApplicationState
) {
composable(
route = LoginMainConstant.ROUTE
) { backStackEntry ->
val parentEntry = remember(backStackEntry) {
appState.navController.getBackStackEntry(LoginConstant.ROUTE)
}
val parentViewModel: LoginViewModel = hiltViewModel(parentEntry)
val viewModel: LoginMainViewModel = hiltViewModel()

val model: LoginMainModel = let {
val state by viewModel.state.collectAsStateWithLifecycle()

LoginMainModel(
state = state
)
}

ErrorObserver(viewModel)
ajou4095 marked this conversation as resolved.
Show resolved Hide resolved

LoginMainScreen(
appState = appState,
model = model,
event = viewModel.event,
intent = viewModel::onIntent,
handler = viewModel.handler
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package ac.dnd.bookkeeping.android.presentation.ui.main.login.main

import ac.dnd.bookkeeping.android.domain.model.error.ServerException

sealed interface LoginMainEvent {
sealed interface Login : LoginMainEvent {
data object Success : Login
data class Failure(val exception: ServerException) : Login
data class Error(val exception: Throwable) : Login
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package ac.dnd.bookkeeping.android.presentation.ui.main.login.main

sealed interface LoginMainIntent {
data object Click : LoginMainIntent
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package ac.dnd.bookkeeping.android.presentation.ui.main.login.main

data class LoginMainModel(
val state: LoginMainState,
)
Loading