Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Compose AdapterList update data Asynchronously

Hi I'm trying to update the AdapterList Composable item asynchronously. I put Image as one of the List Item. The image data is downloading from server using coroutine and update the value using state. When I fling the list items, got following error

    java.lang.IllegalStateException: Asking for measurement result of unmeasured layout modifier
        at androidx.ui.core.LayoutNodeWrapper.getMeasureResult(LayoutNodeWrapper.kt:58)
        at androidx.ui.core.LayoutNodeWrapper.getMeasuredSize(LayoutNodeWrapper.kt:48)
        at androidx.ui.core.Placeable.getWidth(Placeable.kt:40)
        at androidx.ui.core.LayoutNode.getWidth(ComponentNodes.kt:841)
        at androidx.ui.foundation.ListState.composeAndMeasureNextItem-BTEqjtU(AdapterList.kt:222)
        at androidx.ui.foundation.ListState.consumePendingScroll(AdapterList.kt:151)
        at androidx.ui.foundation.ListState.access$consumePendingScroll$3(Unknown Source:0)
        at androidx.ui.foundation.ListState$ListMeasureBlocks.measure(AdapterList.kt:277)
        at androidx.ui.core.InnerPlaceable.performMeasure(InnerPlaceable.kt:43)
        at androidx.ui.core.LayoutNodeWrapper.measure(LayoutNodeWrapper.kt:99)
        at androidx.ui.core.DelegatingLayoutNodeWrapper.performMeasure(DelegatingLayoutNodeWrapper.kt:79)
        at androidx.ui.core.LayerWrapper.performMeasure(LayerWrapper.kt:52)
        at androidx.ui.core.LayoutNodeWrapper.measure(LayoutNodeWrapper.kt:99)
        at androidx.ui.core.DelegatingLayoutNodeWrapper.performMeasure(DelegatingLayoutNodeWrapper.kt:79)
        at androidx.ui.core.LayoutNodeWrapper.measure(LayoutNodeWrapper.kt:99)
        at androidx.ui.core.DelegatingLayoutNodeWrapper.performMeasure(DelegatingLayoutNodeWrapper.kt:79)
        at androidx.ui.core.LayoutNodeWrapper.measure(LayoutNodeWrapper.kt:99)
        at androidx.ui.core.DelegatingLayoutNodeWrapper.performMeasure(DelegatingLayoutNodeWrapper.kt:79)
        at androidx.ui.core.LayoutNodeWrapper.measure(LayoutNodeWrapper.kt:99)
        at androidx.ui.core.LayoutNode$measure$2.invoke(ComponentNodes.kt:1177)
        at androidx.ui.core.LayoutNode$measure$2.invoke(Unknown Source:0)
        at androidx.ui.core.ModelObserver.observeReads(ModelObserver.kt:151)
        at androidx.ui.core.AndroidComposeView.observeMeasureModelReads(AndroidOwner.kt:487)
        at androidx.ui.core.LayoutNode.measure(ComponentNodes.kt:1176)
like image 299
Chandrakumar Avatar asked May 07 '20 12:05

Chandrakumar


People also ask

How to write asynchronous one-shot queries in jetpack?

You can use the LiveData wrapper class from Jetpack to write asynchronous observable queries. You can use the ListenableFuture<T> wrapper from Guava to write asynchronous one-shot queries.

How to update course activity in Android app?

Navigate to the app > java > your app’s package name > UpdateCourseActivity.java file and add the below code to it. Comments are added inside the code to understand the code in more detail. Now run your app and see the output of the app. Make sure to add data to the SQLite database before updating it.

How to add onclicklistener for recyclerview items in Android?

We have to add on click listener for the items of our RecycleView. For adding onClickListener () to our recycler view items navigate to the app > java > your app’s package name > CourseRVAdapter class and simply add an onClickListener () for our RecyclerView item.

Do too many async operations take place inside a database interactor?

Too many async operations take place to stick with that pattern — one for every row. RxJava to the rescue! I use PublishSubject (that will act both as Observable and Observer) inside my database interactor implementation:


1 Answers

I've seen this a few times myself with both lists downloading images like you're describing and also lists without any async work being done, but I don't think it's caused by anything we're specifically doing. My impression is that it's just a bug with the current state of Compose.

That being said, AndroidComposeViewAccessibilityDelegateCompat is at least one class that handles this error and references an internal Issue Tracker ticket that's indicating it will be fixed in Android R, at least for that instance.

} catch (e: IllegalStateException) {
    // We may get "Asking for measurement result of unmeasured layout modifier" error.
    // TODO(b/153198816): check whether we still get this exception when R is in.
    info.setBoundsInScreen(android.graphics.Rect())
}

There's also an upcoming change in dev11 that updates AdapterList to dispose of compositions scrolled off screen and I'm curious to see how this affects things.

And if you're just curious about where the error is being thrown you can check out LayoutNodeWrapper._measureResult.

like image 87
adneal Avatar answered Oct 22 '22 09:10

adneal