I have a weird API design consideration. I'm writi...
# compose
d
I have a weird API design consideration. I'm writing a container which can arrange and animate its items
Copy code
val state = rememberNiceState(itemPositions: Positions.Stage0)
NiceContainer(
  itemCount = 3,
  state: NiceState = state,
  itemContent = { index -> MyItem(index) }
)
LaunchedEffect(Unit) {
  state.animateItems(Positions.Stage1)
}
The problem is that to calculate an (x,y) of each item given the "stage" I need to know the
itemsCount
: both in State consctructor and in
animateItems
. I could make
itemCount
private val in State, but I do not want to require user to pass
itemsCount
both to
NiceContainer
composable and to State constructor, this feels weird. Similarly passing
itemCount
only to State constructor and removing it from
NiceContainer
argument list feels not like something you do in other composable container layouts... Any suggestions?
another option I have tried is to have
itemsCount
as a mutableState in
NiceState()
class and setting it always from inside
NiceContainer
body, but this feels strange too. and it also makes
NiceState
initialization quite complex insde, because there are other internal properties there which depend on
itemsCount