Skip to content

Commit b85663f

Browse files
committed
BottomSheetOptionDSL: Add items method for a list of items
1 parent 415d42a commit b85663f

File tree

1 file changed

+21
-0
lines changed
  • ui/widgets/compose/option-bottom-sheet/src/main/kotlin/io/github/edricchan03/optionbottomsheet/models/dsl

1 file changed

+21
-0
lines changed

ui/widgets/compose/option-bottom-sheet/src/main/kotlin/io/github/edricchan03/optionbottomsheet/models/dsl/BottomSheetOptionDSL.kt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,27 @@ class BottomSheetOptionGroupBuilder {
7373
}
7474
}
7575

76+
/**
77+
* Adds the list of [items] to this option group.
78+
*
79+
* [itemInit] is used to determine how to add an item, see [item].
80+
* @param items The list of items to be added.
81+
* @param itemId Lambda used to map an item [T] to its ID form. Defaults to
82+
* the index if not specified.
83+
* @param itemInit Lambda used to create an item from [T].
84+
* @see item
85+
*/
86+
@Composable
87+
fun <T> items(
88+
items: List<T>,
89+
itemId: (IndexedValue<T>) -> Int = IndexedValue<T>::index,
90+
itemInit: @Composable BottomSheetOptionGroupItemBuilder.(T) -> Unit
91+
): List<BottomSheetOption> = items.withIndex().map {
92+
item(id = itemId(it)) {
93+
itemInit(it.value)
94+
}
95+
}
96+
7697
// Group properties
7798
var title: String? = null
7899
var visible = true

0 commit comments

Comments
 (0)