Hello, does anyone know how to keep the state of A...
# compose
f
Hello, does anyone know how to keep the state of AndroidView in Compose UI correctly? I have a custom ImageView which shows a
Path
and some control points, I’d like to keep the same state after going back to the screen but don’t know how to keep the state in Compose UI
c
this might not be easy to hear, but the best way to maintain the state of the view would be to make it extrinsic to the view, that way you can simply pass the state in via the
update
lambda that you can provide to the
AndroidView
composable. If that's not feasible, I imagine implementing onSaveInstanceState/onRestoreInstanceState may work? What have you tried?
f
Thanks! I think I will try onSaveInstanceState to see it works or not. Because the Path and control points are the private properties in the view.
I’ve tried to use onSaveInstanceState/onRestoreInstanceState to keep the view state, but only
onSaveInstanceState
is invoked and
onRestoreInstanceState
is never invoked in Compose UI. The workaround is to export the saved state to Compose. Still finding a better solution