【问题标题】:Android Compose AdapterList update data AsynchronouslyAndroid Compose AdapterList 异步更新数据
【发布时间】:2020-06-28 03:49:14
【问题描述】:

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

    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)

【问题讨论】:

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


    【解决方案1】:

    我自己也见过几次这样的情况,两个列表都下载了您所描述的图像,也有列表没有完成任何异步工作,但我认为这不是由我们专门做的任何事情引起的。我的印象是,这只是 Compose 当前状态的一个错误。

    话虽如此,AndroidComposeViewAccessibilityDelegateCompat 至少是一个处理此错误并引用内部问题跟踪器票证的类,该票证表明它将在 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

    【讨论】:

    【解决方案2】:

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

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-11-24
      • 1970-01-01
      • 2023-03-18
      • 1970-01-01
      • 1970-01-01
      • 2014-02-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多