Android Compose AdapterList异步更新数据

时间:2020-05-07 12:16:35

标签: android android-jetpack android-jetpack-compose

嗨,我正在尝试异步更新AdapterList Composable项目。我将图像作为列表项之一。正在使用协程从服务器下载图像数据,并使用状态更新值。当我拖出列表项时,出现以下错误

    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)

2 个答案:

答案 0 :(得分:3)

我本人已经看过几次了,它们既下载了您描述的图像,又列出了未完成任何异步工作的列表,但是我不认为这是我们专门做的事情造成的。我的印象是,这只是Compose当前状态的错误。

话虽这么说,AndroidComposeViewAccessibilityDelegateCompat至少是一个处理此错误的类,并引用一个内部Issue Tracker票证,该票证表明至少在该实例中它将在Android R中得到修复。

} 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())
}

dev11中还将有一个变化,它将更新AdapterList to dispose of compositions scrolled off screen,我很想知道这如何影响事物。

如果您只是想知道错误的出处,可以查看LayoutNodeWrapper._measureResult

答案 1 :(得分:0)

此问题已在Compose版本0.1.0-dev14中修复

您可以将撰写依赖项更新为

 composeOptions {
    kotlinCompilerExtensionVersion '0.1.0-dev14'
    kotlinCompilerVersion '1.3.70-dev-withExperimentalGoogleExtensions-20200424'
}