I'm using viewModel to pass data to my compose view. The thing is I wanna handle expand and collapse view by filed inside my models in viewModel. So If some UI click on expand method I will call viewModel and doExpand method like this:
private val _acquiredCoupons = MutableLiveData<List<AcquiredCoupon>>(listOf())
val acquiredCoupons: LiveData<List<AcquiredCoupon>> = _acquiredCoupons
fun doExpand(coupon : AcquiredCoupon){
val index = _acquiredCoupons.value?.indexOf(coupon) ?: -1
val newItems = _acquiredCoupons.value?.toMutableList().also {
it?.get(index)?.isExpanded = true
}
_acquiredCoupons.value = newItems
Timber.i("Mahdi $index")
}
But the thing is after update models in compose UI will not trigger and re compose is not happening! I'm observing the live data like this:
val items = viewModel.acquiredCoupons.observeAsState(initial = emptyList())