I want to encapsulate some composable code but I w...
# compose
a
I want to encapsulate some composable code but I want to expose some of the internal state, but not all of it. Any idea how to tackle this on Compose? Or would I have to hoist the whole painter state in this example:
Copy code
fun DecoratedImage(
  data: Any?
) {
  val painter = rememberImagePainter(data) {
     crossfade(true)
     // lots of styling/customization
  }
  val state = (painter as? Success)?.state // I want to expose this state
  Image(painter)
}
a
You could hoist an object holding a private reference to the Painter, which redeclares the desired portion of the Painter's methods & properties and delegates them to the identically named API on the Painter
a
I see, that could work. I haven’t figured out how to pass the painter to the
Image
though if it’s private. Maybe I can make painter a publicly accessible val