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

Merhawifissehaye

06/20/2020, 8:49 PM
While using view model with jetpack compose, I am trying to update the viewmodel from a button inside the view. I want the state of the composable to be updated from outside it inside the fragment. Below is the gist of what I tried to do. How can I update the composable on an event on a button inside it, however from an action outside of the composable? https://gist.github.com/mfissehaye/0761d3c91da5b355c57438a13021046e
l

Leland Richardson [G]

06/20/2020, 8:58 PM
You are assigning a variable to a new livedata instance instead of mutating the livedata instance itself
1
If you did that instead, then observing the livedata like you are there would be enough
m

Merhawifissehaye

06/22/2020, 10:09 AM
@Leland Richardson [G] Yes you are right. I am overwriting the existing live data, so it won't be observable from the view. However it's kind of tricky. I have to either observe the live data both inside my Fragment and the Composable; otherwise I have to pass the viewmodel itself to the Composable (which I didn't wanna do, I thought that's too much knowledge for the Composable).
4 Views