Dustin
10/04/2023, 1:05 PMDustin
10/04/2023, 1:06 PMRow(){
if(condition1){
View1()
}
if(condition2){
View2()
}
if(condition3){
View3()
}
}
Then if you want to add dividers between each optional view, you need to do something like this
Row(){
if(condition1){
View1()
}
if(condition2){
if(condition1){
Divider()
}
View2()
}
if(condition3) {
if(condition1 || condition2){
Divider()
}
View3()
}
}
Dustin
10/04/2023, 1:06 PMStylianos Gakis
10/04/2023, 1:12 PMDustin
10/04/2023, 1:17 PMjw
10/04/2023, 1:29 PMjw
10/04/2023, 1:30 PMDustin
10/04/2023, 1:37 PM@Composable
fun DividedRow(
modifier: Modifier = Modifier,
divider: @Composable () -> Unit,
vararg items: @Composable() () -> Unit,
) {
if (items.isEmpty()) {
return
}
Row(modifier = modifier) {
items.forEachIndexed { index, item ->
item()
if (index != items.size - 1) {
divider()
}
}
}
}
yes thanks, still not that prettiest code but much more scalablejw
10/04/2023, 1:38 PMlastIndex
, but it would be better to put the conditional before the item and check index > 0
because it's faster