https://kotlinlang.org logo
#compose
Title
# compose
h

Halil Ozercan

10/31/2020, 5:08 PM
What should I do if I want to create a custom modifier which will be stateful (
composed
) and that state depends on the size of the composable that it is attached to. For example, initial state is going to have 50 random objects if size is smaller than a threshold, 100 objects if it is larger.
currently, I'm just starting with a nullable state in
composed
and then initializing that state after first call to
drawBehind
modifier.
Copy code
= composed {
  var state by remeber { ... }
  drawBehind {
    if(state.value == null) {
      state.value = init(size)  
    }
  }
}
Better yet, using
layout
modifier to initialize the state according to the size instead of
drawBehind
makes more sense.
a

Adam Powell

10/31/2020, 7:21 PM
Yep. I think we added an
onSizeChanged
modifier for cases like this too
h

Halil Ozercan

10/31/2020, 8:25 PM
and that was exactly what I was looking for, thanks 🙂
👍 1