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

Feat: stuffs navigation #11

Merged
merged 3 commits into from
Jan 26, 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
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 = "출근"
)
}
}
Loading