Hi im attempting to build a jetpack compose generi...
# naming
t
Hi im attempting to build a jetpack compose generic Ui element to support the placing of max of 5 icons i have defined 11 cells that can each hold one icon and want to create an enum that defines each of the 11 cells in a descriptive way to help the developers that use this Ui Component understand which cell is which, i have the following so far and feel sure i can improve on it, any suggestions?
enum class FooterCell(val index: Int, val description: String) {
Left1(1, "Far left"),
Left2(2, "Second from left"),
Left3(3, "Third from left"),
Left4(4, "Fourth from left"),
Left5(5, "Fifth from left"),
Centre(6, "Middle / centre cell"),
Right5(7, "Fifth from right"),
Right4(8, "Fourth from right"),
Right3(9, "Third from right"),
Right2(10, "Second from right"),
Right1(11, "Far right");
companion object {
fun fromIndex(index: Int): FooterCell =
entries.firstOrNull { it.index == index }
?: throw IllegalArgumentException("Invalid cell index: $index")
}
}
t
Couldn't it just be a
List<String>
and you display in the order of the
List
?
t
it could be, however i want control over duplicates and i want to make other developers lives easier when using it
t
You can control duplicates by doing a
.distinct()
on the list, no? It seems easier to pass a List than having to understand the 11 enums 😅
t
im a control freak 😄 i thought this was a naming channel? 😂
😅 2