Skip to content

Commit

Permalink
Feat: stuffs navigation (#11)
Browse files Browse the repository at this point in the history
* feat: 카테고리 그래프 받을 수 있도록 수정

* feat: 카테고리를 통해 화면을 구성하도록 수정

* feat: 카테고리를 통해 화면을 호출할 수 있는 확장함수 작성
  • Loading branch information
jinsu4755 authored Jan 26, 2024
1 parent f2bf71d commit 7ff030c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 8 deletions.
33 changes: 27 additions & 6 deletions app/src/main/java/org/care/packie/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,17 @@ import androidx.compose.ui.Modifier
import androidx.navigation.NavController
import androidx.navigation.NavGraph
import androidx.navigation.NavGraphBuilder
import androidx.navigation.NavType
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.compose.rememberNavController
import androidx.navigation.navArgument
import androidx.navigation.navigation
import dagger.hilt.android.AndroidEntryPoint
import org.care.packie.feature.category.CategoryScreen
import org.care.packie.feature.stuffs.StuffsScreenRoot
import org.care.packie.ui.theme.PackieTheme
import java.lang.IllegalArgumentException

@AndroidEntryPoint
class MainActivity : ComponentActivity() {
Expand Down Expand Up @@ -51,10 +54,21 @@ private fun NavGraphBuilder.packingGraph(navController: NavController) {
composable(PackieNavDestination.CategoryScreen.route) {
CategoryScreen()
}
composable(PackieNavDestination.StuffsScreen.route) {
composable(
route = PackieNavDestination.StuffsScreen.route,
arguments = listOf(
navArgument(PackieNavDestination.StuffsScreen.categoryNavArgumentKey) {
type = NavType.StringType
}
)
) { entry ->
val category = entry.arguments
?.getString(PackieNavDestination.StuffsScreen.categoryNavArgumentKey)
?: throw IllegalArgumentException("category is required")
StuffsScreenRoot(
category = category,
navigateToCategory = {
navController.navigate(PackieNavDestination.CategoryScreen.route)
navController.popBackStack()
}
)
}
Expand All @@ -64,10 +78,17 @@ private fun NavGraphBuilder.packingGraph(navController: NavController) {
sealed class PackieNavDestination(
val route: String
) {
object CategoryScreen: PackieNavDestination(
object CategoryScreen : PackieNavDestination(
route = "category"
)
object StuffsScreen: PackieNavDestination(
route = "stuffs"
)

object StuffsScreen : PackieNavDestination(
route = "stuffs/{category}"
) {
val categoryNavArgumentKey = "category"

fun NavController.navigateToStuff(category: String) {
this.navigate("stuffs/${category}")
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ private val ALREADY_REMOVED = "이미 삭제된 물건이에요"

@Composable
fun StuffsScreenRoot(
category: String,
viewModel: StuffsViewModel = hiltViewModel(),
navigateToCategory: () -> Unit = {}
) {
val category = "출근"
val state by viewModel.uiState.collectAsState()
val scope = rememberCoroutineScope()
var isAddStuffTextFieldDialogOpen by remember {
Expand Down Expand Up @@ -161,6 +161,8 @@ fun ShowDoneDialog(
@Composable
fun StuffsScreenRootPreview() {
PackieTheme {
StuffsScreenRoot()
StuffsScreenRoot(
category = "출근"
)
}
}

0 comments on commit 7ff030c

Please sign in to comment.