Skip to content

Commit

Permalink
Merge pull request #13 from AdultOfNineteen/fix/issue-12
Browse files Browse the repository at this point in the history
[FIX] onInit 메소드 제거
  • Loading branch information
DongChyeon authored Dec 28, 2023
2 parents b978b60 + b027e59 commit aec8462
Show file tree
Hide file tree
Showing 15 changed files with 94 additions and 92 deletions.
32 changes: 5 additions & 27 deletions app/src/main/java/com/teamwiney/winey/WineyNavHost.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
import androidx.lifecycle.viewmodel.compose.viewModel
import androidx.navigation.NavDestination
import androidx.navigation.compose.NavHost
import com.teamwiney.analysis.analysisGraph
Expand All @@ -27,12 +26,9 @@ import com.teamwiney.core.common.navigation.TopLevelDestination
import com.teamwiney.core.common.rememberWineyAppState
import com.teamwiney.core.common.rememberWineyBottomSheetState
import com.teamwiney.createnote.mapGraph
import com.teamwiney.home.HomeViewModel
import com.teamwiney.home.homeGraph
import com.teamwiney.mypage.MyPageViewModel
import com.teamwiney.mypage.myPageGraph
import com.teamwiney.noteGraph
import com.teamwiney.notecollection.NoteViewModel
import com.teamwiney.ui.components.BottomNavigationBar
import com.teamwiney.ui.components.BottomNavigationItem
import com.teamwiney.ui.theme.WineyTheme
Expand All @@ -44,20 +40,6 @@ fun WineyNavHost() {
val bottomSheetState = rememberWineyBottomSheetState()
val navController = appState.navController

// 메인화면 뷰 모델들
val homeViewModel: HomeViewModel = viewModel()
val noteViewModel: NoteViewModel = viewModel()
val myPageViewModel: MyPageViewModel = viewModel()

// 초기 메인 화면 진입 시 수행해야할 작업을 정의합니다.
val onInit: () -> Unit = {
homeViewModel.getRecommendWines()
homeViewModel.getWineTips()
noteViewModel.getTastingNotes()
myPageViewModel.getUserWineGrade()
myPageViewModel.getWineGradeStandard()
}

ModalBottomSheetLayout(
sheetContent = {
bottomSheetState.bottomSheetContent.value?.invoke(this)
Expand Down Expand Up @@ -92,26 +74,22 @@ fun WineyNavHost() {
) {
authGraph(
appState = appState,
bottomSheetState = bottomSheetState,
onInit = onInit
bottomSheetState = bottomSheetState
)
homeGraph(
appState = appState,
homeViewModel = homeViewModel,
appState = appState
)
mapGraph(
appState = appState,
bottomSheetState = bottomSheetState,
bottomSheetState = bottomSheetState
)
noteGraph(
appState = appState,
noteViewModel = noteViewModel,
bottomSheetState = bottomSheetState,
bottomSheetState = bottomSheetState
)
myPageGraph(
appState = appState,
myPageViewModel = myPageViewModel,
bottomSheetState = bottomSheetState,
bottomSheetState = bottomSheetState
)
analysisGraph(
appState = appState,
Expand Down
12 changes: 3 additions & 9 deletions feature/auth/src/main/java/com/teamwiney/auth/AuthNavigation.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,22 @@ import com.teamwiney.core.common.navigation.AuthDestinations
fun NavGraphBuilder.authGraph(
appState: WineyAppState,
bottomSheetState: WineyBottomSheetState,
onInit: () -> Unit,
) {
navigation(
route = AuthDestinations.ROUTE,
startDestination = AuthDestinations.SPLASH
) {
composable(route = AuthDestinations.SPLASH) {
SplashScreen(
appState = appState,
onInit = onInit,
appState = appState
)
}

loginGraph(
appState = appState,
onInit = onInit,
)
loginGraph(appState = appState)

signUpGraph(
appState = appState,
bottomSheetState = bottomSheetState,
onInit = onInit,
bottomSheetState = bottomSheetState
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ import com.teamwiney.core.common.WineyAppState
import com.teamwiney.core.common.navigation.AuthDestinations

fun NavGraphBuilder.loginGraph(
appState: WineyAppState,
onInit: () -> Unit
appState: WineyAppState
) {
navigation(
route = AuthDestinations.Login.ROUTE,
Expand All @@ -20,8 +19,7 @@ fun NavGraphBuilder.loginGraph(

LoginScreen(
appState = appState,
viewModel = viewModel,
onInit = onInit
viewModel = viewModel
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ import kotlinx.coroutines.flow.collectLatest
@Composable
fun LoginScreen(
appState: WineyAppState,
viewModel: LoginViewModel,
onInit: () -> Unit
viewModel: LoginViewModel
) {
val uiState by viewModel.uiState.collectAsStateWithLifecycle()
val effectFlow = viewModel.effect
Expand All @@ -74,9 +73,6 @@ fun LoginScreen(
effectFlow.collectLatest { effect ->
when (effect) {
is LoginContract.Effect.NavigateTo -> {
if (effect.destination == HomeDestinations.ROUTE) {
onInit()
}
appState.navigate(effect.destination, effect.navOptions)
}

Expand Down Expand Up @@ -142,7 +138,6 @@ fun LoginScreen(
SocialLoginButton(drawable = R.mipmap.img_lock) {
appState.showSnackbar("홈 화면 테스트 입니다.")
viewModel.testLogin {
onInit()
appState.navigate(HomeDestinations.ROUTE) {
popUpTo(AuthDestinations.Login.ROUTE) {
inclusive = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import androidx.hilt.navigation.compose.hiltViewModel
import com.teamwiney.core.common.WineyAppState
import com.teamwiney.core.common.navigation.AuthDestinations
import com.teamwiney.core.common.navigation.HomeDestinations
Expand All @@ -21,12 +20,10 @@ import com.teamwiney.ui.theme.WineyTheme

@Composable
fun SignUpCompleteScreen(
appState: WineyAppState,
onInit: () -> Unit
appState: WineyAppState
) {

val onSignUpComplete = {
onInit()
appState.navigate(HomeDestinations.ROUTE) {
popUpTo(AuthDestinations.SignUp.ROUTE) {
inclusive = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import com.teamwiney.core.common.navigation.AuthDestinations
fun NavGraphBuilder.signUpGraph(
appState: WineyAppState,
bottomSheetState: WineyBottomSheetState,
onInit: () -> Unit,
) {
navigation(
route = "${AuthDestinations.SignUp.ROUTE}?userId={userId}",
Expand Down Expand Up @@ -73,10 +72,7 @@ fun NavGraphBuilder.signUpGraph(
}

composable(route = AuthDestinations.SignUp.COMPLETE) {
SignUpCompleteScreen(
appState = appState,
onInit = onInit
)
SignUpCompleteScreen(appState = appState)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,13 @@ import androidx.compose.ui.unit.dp
import androidx.hilt.navigation.compose.hiltViewModel
import com.teamwiney.auth.login.component.SplashBackground
import com.teamwiney.core.common.WineyAppState
import com.teamwiney.core.common.navigation.HomeDestinations
import com.teamwiney.core.design.R
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.collectLatest

@Composable
fun SplashScreen(
appState: WineyAppState,
onInit: () -> Unit,
appState: WineyAppState
) {
val viewModel: SplashViewModel = hiltViewModel()
val effectFlow = viewModel.effect
Expand All @@ -41,9 +39,6 @@ fun SplashScreen(
}

is SplashContract.Effect.NavigateTo -> {
if (effect.destination == HomeDestinations.ROUTE) {
onInit()
}
appState.navigate(effect.destination, builder = effect.builder)
}
}
Expand Down
39 changes: 33 additions & 6 deletions feature/home/src/main/java/com/teamwiney/home/HomeNavigation.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package com.teamwiney.home

import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.navigation.NavBackStackEntry
import androidx.navigation.NavController
import androidx.navigation.NavGraphBuilder
import androidx.navigation.NavType
import androidx.navigation.compose.composable
Expand All @@ -10,25 +15,33 @@ import com.teamwiney.core.common.navigation.HomeDestinations


fun NavGraphBuilder.homeGraph(
appState: WineyAppState,
homeViewModel: HomeViewModel,
appState: WineyAppState
) {

navigation(
route = HomeDestinations.ROUTE,
startDestination = HomeDestinations.HOME
) {
composable(route = HomeDestinations.HOME) {
val backStackEntry = rememberNavControllerBackStackEntry(
entry = it,
navController = appState.navController,
graph = HomeDestinations.ROUTE
)
HomeScreen(
appState = appState,
viewModel = homeViewModel
viewModel = hiltViewModel(backStackEntry)
)
}

composable(route = HomeDestinations.WINE_TIP) {
val backStackEntry = rememberNavControllerBackStackEntry(
entry = it,
navController = appState.navController,
graph = HomeDestinations.ROUTE
)
WineTipScreen(
appState = appState,
viewModel = homeViewModel
viewModel = hiltViewModel(backStackEntry)
)
}

Expand Down Expand Up @@ -56,11 +69,25 @@ fun NavGraphBuilder.homeGraph(
}
)
) { entry ->
val backStackEntry = rememberNavControllerBackStackEntry(
entry = entry,
navController = appState.navController,
graph = HomeDestinations.ROUTE
)
WineDetailScreen(
appState = appState,
wineId = entry.arguments?.getLong("wineId") ?: 0L,
viewModel = homeViewModel
viewModel = hiltViewModel(backStackEntry)
)
}
}
}

@Composable
fun rememberNavControllerBackStackEntry(
entry: NavBackStackEntry,
navController: NavController,
graph: String,
) = remember(entry) {
navController.getBackStackEntry(graph)
}
3 changes: 3 additions & 0 deletions feature/home/src/main/java/com/teamwiney/home/HomeScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ fun HomeScreen(
}

LaunchedEffect(true) {
viewModel.getRecommendWines()
viewModel.getWineTips()

effectFlow.collectLatest { effect ->
when (effect) {
is HomeContract.Effect.NavigateTo -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.teamwiney.mypage

import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.navigation.NavBackStackEntry
import androidx.navigation.NavController
import androidx.navigation.NavGraphBuilder
Expand All @@ -13,17 +14,21 @@ import com.teamwiney.core.common.navigation.MyPageDestinations

fun NavGraphBuilder.myPageGraph(
appState: WineyAppState,
myPageViewModel: MyPageViewModel,
bottomSheetState: WineyBottomSheetState
) {
navigation(
route = MyPageDestinations.ROUTE,
startDestination = MyPageDestinations.MY_PAGE
) {
composable(route = MyPageDestinations.MY_PAGE) {
val backStackEntry = rememberNavControllerBackStackEntry(
entry = it,
navController = appState.navController,
graph = MyPageDestinations.ROUTE
)
MyPageScreen(
appState = appState,
viewModel = myPageViewModel
viewModel = hiltViewModel(backStackEntry)
)
}

Expand All @@ -34,25 +39,40 @@ fun NavGraphBuilder.myPageGraph(
}

composable(route = MyPageDestinations.ACCOUNT) {
val backStackEntry = rememberNavControllerBackStackEntry(
entry = it,
navController = appState.navController,
graph = MyPageDestinations.ROUTE
)
MyPageAccountScreen(
appState = appState,
viewModel = myPageViewModel,
viewModel = hiltViewModel(backStackEntry),
bottomSheetState = bottomSheetState
)
}

composable(route = MyPageDestinations.WITHDRAWAL_REASON_SELECT) {
val backStackEntry = rememberNavControllerBackStackEntry(
entry = it,
navController = appState.navController,
graph = MyPageDestinations.ROUTE
)
MyPageWithdrawalReasonSelectScreen(
appState = appState,
viewModel = myPageViewModel,
viewModel = hiltViewModel(backStackEntry),
bottomSheetState = bottomSheetState
)
}

composable(route = MyPageDestinations.WITHDRAWAL_CONFIRM) {
val backStackEntry = rememberNavControllerBackStackEntry(
entry = it,
navController = appState.navController,
graph = MyPageDestinations.ROUTE
)
MyPageWithdrawalConfirmScreen(
appState = appState,
viewModel = myPageViewModel,
viewModel = hiltViewModel(backStackEntry),
bottomSheetState = bottomSheetState
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ fun MyPageScreen(
val context = LocalContext.current

LaunchedEffect(true) {
viewModel.getUserWineGrade()
viewModel.getWineGradeStandard()

effectFlow.collectLatest { effect ->
when (effect) {
is MyPageContract.Effect.NavigateTo -> {
Expand Down
Loading

0 comments on commit aec8462

Please sign in to comment.