Skip to content

Commit

Permalink
feat: Grid state 파라미터 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
jinsu4755 committed Jan 9, 2024
1 parent ce5bf84 commit 6f3061d
Showing 1 changed file with 17 additions and 21 deletions.
38 changes: 17 additions & 21 deletions app/src/main/java/org/care/packie/ui/component/stuff/StuffsGrid.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,28 @@ package org.care.packie.ui.component.stuff

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.lazy.grid.GridCells
import androidx.compose.foundation.lazy.grid.LazyGridState
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
import androidx.compose.foundation.lazy.grid.items
import androidx.compose.foundation.lazy.grid.rememberLazyGridState
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.tooling.preview.PreviewParameter
import androidx.compose.ui.unit.dp
import org.care.packie.StuffsPreviewProvider
import org.care.packie.ui.theme.PackieTheme

@Composable
fun StuffsGrid(
modifier: Modifier = Modifier,
state: LazyGridState = rememberLazyGridState(),
stuffs: Map<String, Boolean>,
onToggle: (Boolean) -> Unit = {}
) {
LazyVerticalGrid(
modifier = modifier,
state = state,
columns = GridCells.Fixed(2),
horizontalArrangement = Arrangement.spacedBy(10.dp),
verticalArrangement = Arrangement.spacedBy(16.dp)
Expand All @@ -38,6 +44,7 @@ fun StuffsGrid(
@Composable
fun MutableStuffsGrid(
modifier: Modifier = Modifier,
state: LazyGridState = rememberLazyGridState(),
stuffs: Map<String, Boolean>,
onRemove: (String)-> Unit = {},
onAdd: () -> Unit = {}
Expand All @@ -46,7 +53,8 @@ fun MutableStuffsGrid(
modifier = modifier,
columns = GridCells.Fixed(2),
horizontalArrangement = Arrangement.spacedBy(10.dp),
verticalArrangement = Arrangement.spacedBy(16.dp)
verticalArrangement = Arrangement.spacedBy(16.dp),
state = state
) {
items(
items = stuffs.entries.toList(),
Expand All @@ -67,36 +75,24 @@ fun MutableStuffsGrid(

@Preview
@Composable
fun StuffsGridPreview() {
fun StuffsGridPreview(
@PreviewParameter(StuffsPreviewProvider::class) stuffs: Map<String, Boolean>
) {
PackieTheme {
StuffsGrid(
stuffs = mapOf(
"휴대폰" to false,
"" to false,
"하나둘셋넷" to false,
"일이삼사오육칠팔구" to false,
"어휴" to false,
"에휴" to false,
"오호" to false,
)
stuffs = stuffs
)
}
}

@Preview
@Composable
fun MutableStuffsGridPreview() {
fun MutableStuffsGridPreview(
@PreviewParameter(StuffsPreviewProvider::class) stuffs: Map<String, Boolean>
) {
PackieTheme {
MutableStuffsGrid(
stuffs = mapOf(
"휴대폰" to false,
"" to false,
"하나둘셋넷" to false,
"일이삼사오육칠팔구" to false,
"어휴" to false,
"에휴" to false,
"오호" to false,
)
stuffs = stuffs
)
}
}

0 comments on commit 6f3061d

Please sign in to comment.