refactor: replace LazyVerticalGrid with Column/Row layout in AllergenSelectionGrid for improved performance and layout control

This commit is contained in:
Bruno Charest 2026-04-26 12:42:51 -04:00
parent 1656b189f4
commit a9eb582c93

View File

@ -7,12 +7,10 @@ import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size import androidx.compose.foundation.layout.size
import androidx.compose.foundation.lazy.grid.GridCells
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
import androidx.compose.foundation.lazy.grid.items
import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Card import androidx.compose.material3.Card
import androidx.compose.material3.CardDefaults import androidx.compose.material3.CardDefaults
@ -71,27 +69,38 @@ fun AllergenSelectionGrid(
modifier: Modifier = Modifier modifier: Modifier = Modifier
) { ) {
val dimens = LocalDimens.current val dimens = LocalDimens.current
val columns = 3
val rows = AllergenType.entries.toList().chunked(columns)
LazyVerticalGrid( Column(
columns = GridCells.Fixed(3),
modifier = modifier.fillMaxWidth(), modifier = modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.spacedBy(dimens.spacingSm),
verticalArrangement = Arrangement.spacedBy(dimens.spacingSm) verticalArrangement = Arrangement.spacedBy(dimens.spacingSm)
) { ) {
items(AllergenType.entries.toList()) { allergen -> rows.forEach { row ->
val currentLevel = selectedAllergens[allergen] ?: AllergenLevel.NONE Row(
AllergenSelectionChip( modifier = Modifier.fillMaxWidth(),
allergen = allergen, horizontalArrangement = Arrangement.spacedBy(dimens.spacingSm)
level = currentLevel, ) {
onClick = { row.forEach { allergen ->
val nextLevel = when (currentLevel) { val currentLevel = selectedAllergens[allergen] ?: AllergenLevel.NONE
AllergenLevel.NONE -> AllergenLevel.TRACE AllergenSelectionChip(
AllergenLevel.TRACE -> AllergenLevel.SEVERE modifier = Modifier.weight(1f),
AllergenLevel.SEVERE -> AllergenLevel.NONE allergen = allergen,
} level = currentLevel,
onLevelChanged(allergen, nextLevel) onClick = {
val nextLevel = when (currentLevel) {
AllergenLevel.NONE -> AllergenLevel.TRACE
AllergenLevel.TRACE -> AllergenLevel.SEVERE
AllergenLevel.SEVERE -> AllergenLevel.NONE
}
onLevelChanged(allergen, nextLevel)
}
)
} }
) repeat(columns - row.size) {
Spacer(modifier = Modifier.weight(1f))
}
}
} }
} }
} }