Halil Ozercan

    Halil Ozercan

    1 year ago
    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.
    = 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.
    Adam Powell

    Adam Powell

    1 year ago
    Yep. I think we added an
    onSizeChanged
    modifier for cases like this too
    Halil Ozercan

    Halil Ozercan

    1 year ago
    and that was exactly what I was looking for, thanks 🙂