5

将 compose 升级到后,我遇到了一个奇怪的错误1.0.0-beta08

java.lang.IllegalStateException: Check failed.
        at androidx.compose.ui.node.OuterMeasurablePlaceable.getLastConstraints-msEJaDk(OuterMeasurablePlaceable.kt:36)
        at androidx.compose.ui.node.LayoutNode.remeasure-BRTryo0$ui_release$default(LayoutNode.kt:1202)
        at androidx.compose.ui.node.MeasureAndLayoutDelegate.doRemeasure-0kLqBqw(MeasureAndLayoutDelegate.kt:171)
        at androidx.compose.ui.node.MeasureAndLayoutDelegate.access$doRemeasure-0kLqBqw(MeasureAndLayoutDelegate.kt:38)
        at androidx.compose.ui.node.MeasureAndLayoutDelegate.measureAndLayout(MeasureAndLayoutDelegate.kt:207)
        at androidx.compose.ui.platform.AndroidComposeView.measureAndLayout(AndroidComposeView.android.kt:501)
        at androidx.compose.ui.platform.AndroidComposeView.dispatchDraw(AndroidComposeView.android.kt:650)
        at android.view.View.draw(View.java:22353)
        at android.view.View.updateDisplayListIfDirty(View.java:21226)
        at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:4500)
        at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:4473)
        at android.view.View.updateDisplayListIfDirty(View.java:21186)
        at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:4500)
        at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:4473)
        at android.view.View.updateDisplayListIfDirty(View.java:21186)
        at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:4500)
        at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:4473)
        at android.view.View.updateDisplayListIfDirty(View.java:21186)
        at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:4500)
        at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:4473)
        at android.view.View.updateDisplayListIfDirty(View.java:21186)
        at android.view.ThreadedRenderer.updateViewTreeDisplayList(ThreadedRenderer.java:559)
        at android.view.ThreadedRenderer.updateRootDisplayList(ThreadedRenderer.java:565)
        at android.view.ThreadedRenderer.draw(ThreadedRenderer.java:642)
        at android.view.ViewRootImpl.draw(ViewRootImpl.java:4106)
        at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:3833)
        at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:3104)
        at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1948)
        at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:8177)
        at android.view.Choreographer$CallbackRecord.run(Choreographer.java:972)
        at android.view.Choreographer.doCallbacks(Choreographer.java:796)
        at android.view.Choreographer.doFrame(Choreographer.java:731)
        at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:957)
        at android.os.Handler.handleCallback(Handler.java:938)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:223)
        at android.app.ActivityThread.main(ActivityThread.java:7664)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)

一段时间后,我可以通过创建 a 的NavHost内部ConstraintLayout并使用库的LazyListScope.items方法来准确地查明并重现此错误androidx.paging:paging-compose

一个全新的项目MainActivity将导致错误:

class MainActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        setContent {
            val navController = rememberNavController()
            val routeName = "route"

            ConstraintLayout() {
                val (navigation) = createRefs()

                NavHost(
                    navController = navController,
                    startDestination = routeName,
                    modifier = Modifier
                        .constrainAs(navigation) {
                            top.linkTo(parent.top)
                            end.linkTo(parent.end)
                            bottom.linkTo(parent.bottom)
                            start.linkTo(parent.start)
                        }
                ){
                    composable(routeName){
                        val items = flow {
                            emit(
                                PagingData.from(listOf(
                                    "Test", "Test2", "etc"
                                ))
                            )
                        }.collectAsLazyPagingItems()

                        LazyColumn {
                            items(items) { item ->
                                Text(item ?: "Empty")
                            }
                        }
                    }
                }
            }
        }
    }
}

LazyColumn没有该方法的items工作,以及将其移出 ConstraintLayout。

这些是依赖版本:

implementation "androidx.compose.ui:ui:1.0.0-beta08"
implementation "androidx.compose.material:material:1.0.0-beta08"
implementation "androidx.compose.ui:ui-tooling:1.0.0-beta08"
implementation 'androidx.activity:activity-compose:1.3.0-beta01'
implementation "androidx.navigation:navigation-compose:2.4.0-alpha02"
implementation "androidx.paging:paging-compose:1.0.0-alpha10"
implementation "androidx.constraintlayout:constraintlayout-compose:1.0.0-alpha07"
4

0 回答 0