Skip to content

Commit

Permalink
[FEATURE] #130 : survey Detail 페이지 뒤로 가기 혹은 완료 버튼 누를 시 프로필 혹은 survey …
Browse files Browse the repository at this point in the history
…Check 페이지로 돌아가도록 변경
  • Loading branch information
tgyuuAn committed Feb 18, 2024
1 parent 51e4f00 commit 8e2dcc3
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 9 deletions.
2 changes: 1 addition & 1 deletion app/src/main/java/com/wap/wapp/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ private fun handleBottomBarState(
eventEditNavigationRoute -> setBottomBarState(false)
SurveyRoute.answerRoute("{id}") -> setBottomBarState(false)
surveyCheckRoute -> setBottomBarState(false)
SurveyCheckRoute.surveyDetailRoute("{id}") -> setBottomBarState(false)
SurveyCheckRoute.surveyDetailRoute("{id}", "{backStack}") -> setBottomBarState(false)
else -> setBottomBarState(true)
}

Expand Down
7 changes: 5 additions & 2 deletions app/src/main/java/com/wap/wapp/navigation/WappNavHost.kt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import com.wap.wapp.feature.profile.profilesetting.navigation.profileSettingScre
import com.wap.wapp.feature.splash.navigation.splashNavigationRoute
import com.wap.wapp.feature.splash.navigation.splashScreen
import com.wap.wapp.feature.survey.check.navigation.SurveyCheckRoute.surveyCheckRoute
import com.wap.wapp.feature.survey.check.navigation.SurveyDetailBackStack
import com.wap.wapp.feature.survey.check.navigation.navigateToSurveyCheck
import com.wap.wapp.feature.survey.check.navigation.navigateToSurveyDetail
import com.wap.wapp.feature.survey.check.navigation.surveyCheckNavGraph
Expand Down Expand Up @@ -98,6 +99,7 @@ fun WappNavHost(
navOptions { popUpTo(surveyCheckRoute) { inclusive = true } },
)
},
navigateToProfile = navController::navigateToProfile,
)
managementSurveyNavGraph(
navigateToManagement = navController::navigateToManagement,
Expand All @@ -113,8 +115,9 @@ fun WappNavHost(
},
navigateToSurveyDetail = { surveyId ->
navController.navigateToSurveyDetail(
surveyId,
navOptions { popUpTo(profileNavigationRoute) },
surveyId = surveyId,
backStack = SurveyDetailBackStack.PROFILE,
navOptions = navOptions { popUpTo(profileNavigationRoute) },
)
},
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,16 @@ import com.wap.designsystem.WappTheme
import com.wap.designsystem.component.WappButton
import com.wap.wapp.core.commmon.extensions.toSupportingText
import com.wap.wapp.core.model.survey.QuestionType
import com.wap.wapp.feature.survey.check.navigation.SurveyDetailBackStack
import kotlinx.coroutines.flow.collectLatest

@Composable
internal fun SurveyDetailRoute(
viewModel: SurveyDetailViewModel = hiltViewModel(),
surveyId: String,
backStack: String,
navigateToSurveyCheck: () -> Unit,
navigateToProfile: () -> Unit,
) {
val surveyUiState by viewModel.surveyUiState.collectAsStateWithLifecycle()
val snackBarHostState = remember { SnackbarHostState() }
Expand All @@ -45,8 +48,20 @@ internal fun SurveyDetailRoute(
SurveyDetailScreen(
snackBarHostState = snackBarHostState,
surveyUiState = surveyUiState,
onDoneButtonClicked = { navigateToSurveyCheck() },
onBackButtonClicked = { navigateToSurveyCheck() },
onDoneButtonClicked = {
if (backStack == SurveyDetailBackStack.SURVEY_CHECK.name) {
navigateToSurveyCheck()
} else {
navigateToProfile()
}
},
onBackButtonClicked = {
if (backStack == SurveyDetailBackStack.SURVEY_CHECK.name) {
navigateToSurveyCheck()
} else {
navigateToProfile()
}
},
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ import com.wap.wapp.feature.survey.check.detail.SurveyDetailRoute

fun NavController.navigateToSurveyDetail(
surveyId: String,
backStack: SurveyDetailBackStack = SurveyDetailBackStack.SURVEY_CHECK,
navOptions: NavOptions? = navOptions {},
) = this.navigate(SurveyCheckRoute.surveyDetailRoute(surveyId), navOptions)
) = this.navigate(SurveyCheckRoute.surveyDetailRoute(surveyId, backStack.name), navOptions)

fun NavController.navigateToSurveyCheck(navOptions: NavOptions? = navOptions {}) =
this.navigate(SurveyCheckRoute.surveyCheckRoute, navOptions)
Expand All @@ -22,6 +23,7 @@ fun NavGraphBuilder.surveyCheckNavGraph(
navigateToSurveyDetail: (String) -> Unit,
navigateToSurveyCheck: () -> Unit,
navigateToSurvey: () -> Unit,
navigateToProfile: () -> Unit,
) {
composable(route = SurveyCheckRoute.surveyCheckRoute) {
SurveyCheckScreen(
Expand All @@ -31,22 +33,33 @@ fun NavGraphBuilder.surveyCheckNavGraph(
}

composable(
route = SurveyCheckRoute.surveyDetailRoute("{id}"),
route = SurveyCheckRoute.surveyDetailRoute("{id}", "{backStack}"),
arguments = listOf(
navArgument("id") {
type = NavType.StringType
},
navArgument("backStack") {
type = NavType.StringType
},
),
) { navBackStackEntry ->
val surveyId = navBackStackEntry.arguments?.getString("id") ?: ""
val backStack = navBackStackEntry.arguments?.getString("backStack") ?: "SURVEY_CHECK"
SurveyDetailRoute(
navigateToSurveyCheck = navigateToSurveyCheck,
surveyId = surveyId,
backStack = backStack,
navigateToSurveyCheck = navigateToSurveyCheck,
navigateToProfile = navigateToProfile,
)
}
}

object SurveyCheckRoute {
const val surveyCheckRoute = "survey/check"
fun surveyDetailRoute(surveyId: String) = "survey/detail/$surveyId"
fun surveyDetailRoute(surveyId: String, backStack: String) =
"survey/detail/$surveyId/$backStack"
}

enum class SurveyDetailBackStack {
SURVEY_CHECK, PROFILE
}

0 comments on commit 8e2dcc3

Please sign in to comment.