googlemaps / android-maps-compose

Jetpack Compose composables for the Maps SDK for Android
https://developers.google.com/maps/documentation/android-sdk/maps-compose
Apache License 2.0
1.16k stars 142 forks source link

Jetpack Compose Map throwing this when TalkBack is turned on. -> java.lang.IllegalStateException: LayoutNode should be attached to an owner #404

Open spremathilaka opened 1 year ago

spremathilaka commented 1 year ago

Library version and other environment information

        composeBOMVersion = "2023.06.01"
        composeCompilerVersion="1.4.0-alpha02"
        composeNavigationVersion = "2.5.3"

    implementation 'com.google.maps.android:maps-compose:2.14.1'
    implementation 'com.google.android.gms:play-services-maps:18.1.0'

Steps to reproduce

Turn on Talk back and Navigate to This compose

When TalkBack is turned off, the app works as expected

Crash Report Screenshot 2023-09-22 at 11 36 16 am

Code:


@Composable
fun LocationPickerScreen(
    uiState: LocationPickerScreenContract.UiState,
) {

    val configuration = LocalConfiguration.current

    val screenHeight = configuration.screenHeightDp.dp

    val currentLoc = uiState.locationInfo.addressLatLng

    val cameraState = rememberCameraPositionState()

    LaunchedEffect(key1 = currentLoc) {
        cameraState.centerOnLocation(currentLoc)
    }

    val marker = LatLng(currentLoc.latitude, currentLoc.longitude)

    Surface(
        modifier = Modifier.fillMaxSize(),
        color = MaterialTheme.colors.background
    ) {
        Box(
            modifier = Modifier.fillMaxSize()
        ) {
            GoogleMap(
                modifier = Modifier
                    .fillMaxWidth()
                    .height(screenHeight - 300.dp)
                    .align(Alignment.TopCenter),
                cameraPositionState = cameraState,
                properties = MapProperties(
                    isMyLocationEnabled = true,
                    mapType = MapType.HYBRID,
                    isTrafficEnabled = true
                )
            ) {
                Marker(
                    state = MarkerState(position = marker),
                    title = "MyPosition",
                    snippet = "This is a description of this Marker",
                    draggable = true
                )
            }

            Column(
                modifier = Modifier
                    .fillMaxWidth()
                    .height(308.dp)
                    .align(Alignment.BottomCenter),
                horizontalAlignment = Alignment.CenterHorizontally,
                verticalArrangement = Arrangement.Center,
            ) {

                Text(
                    text = "Data Place Holder",
                    modifier = Modifier
                        .semantics {
                            contentDescription = "data"
                        }
                        .padding(bottom = 8.dp),
                    style = MaterialTheme.typography.body2.copy(
                        fontSize = 14.sp,
                        fontWeight = FontWeight.SemiBold,
                        lineHeight = 16.sp
                    ),
                )
            }
        }
    }
}

private suspend fun CameraPositionState.centerOnLocation(
    location: LatLng
) = animate(
    update = CameraUpdateFactory.newLatLngZoom(
        location,
        15f
    ),
    durationMs = 1500
)

Screenshot 2023-09-22 at 11 25 23 am

wangela commented 1 year ago

If you would like to upvote the priority of this issue, please comment below or react on the original post above with :+1: so we can see what is popular when we triage.

@spremathilaka Thank you for opening this issue. 🙏 Please check out these other resources that might help you get to a resolution in the meantime:

This is an automated message, feel free to ignore.

wangela commented 1 year ago

Is this related to #305?

spremathilaka commented 1 year ago

I tried the same workaround suggested on [#305 ], still getting the same error

Surface(
        modifier = Modifier.fillMaxSize(),
        color = MaterialTheme.colors.background
    ) {
        Box(
            modifier = Modifier
                .fillMaxSize()

                // <<< --- ADDING THIS NO LUCK 🤦 ------>>>>

                **.semantics(mergeDescendants = true) { }
                .clearAndSetSemantics { contentDescription = "Google Map" }**

               <<< ---ADDING THIS NO LUCK 🤦 ------>>>>

        ) {
            GoogleMap(
                modifier = Modifier
                    .fillMaxWidth()
                    .height(screenHeight - 300.dp)
                    .align(Alignment.TopCenter),
                cameraPositionState = cameraState,
                properties = MapProperties(
                    isMyLocationEnabled = true,
                    mapType = MapType.HYBRID,
                    isTrafficEnabled = true
                )
            ) {
                Marker(
                    state = MarkerState(position = marker),
                    title = "MyPosition",
                    snippet = "This is a description of this Marker",
                    draggable = true
                )
            }

            Column(
                modifier = Modifier
                    .fillMaxWidth()
                    .height(308.dp)
                    .align(Alignment.BottomCenter),
                horizontalAlignment = Alignment.CenterHorizontally,
                verticalArrangement = Arrangement.Center,
            ) {

                Text(
                    text = "Data Place Holder",
                    modifier = Modifier
                        .semantics {
                            contentDescription = "data"
                        }
                        .padding(bottom = 8.dp),
                    style = MaterialTheme.typography.body2.copy(
                        fontSize = 14.sp,
                        fontWeight = FontWeight.SemiBold,
                        lineHeight = 16.sp
                    ),
                )
            }
        }
    }
lildeeOg commented 9 months ago

@spremathilaka Were you able to fix this issue? I am also experiencing this one on variety of devices.

kikoso commented 9 months ago

@spremathilaka , which version from Material are you using? There is a potentially related issue reported in Compose Multiplatform that could relate to an old version from Material.

egorikftp commented 9 months ago

Please check in Compose 1.6.0, there are a lot of issues fixed with LayoutNode

mrugendra commented 1 month ago

We have Maps View with all the gestures and buttons turned off inside Column with verticalScroll. Still happening on multiple devices

Using

          Fatal Exception: java.lang.IllegalStateException: LayoutNode should be attached to an owner
       at androidx.compose.ui.internal.InlineClassHelperKt.throwIllegalStateExceptionForNullCheck(InlineClassHelper.kt:30)
       at androidx.compose.ui.node.LayoutNodeKt.requireOwner(LayoutNode.kt:1561)
       at androidx.compose.ui.node.LayoutNodeLayoutDelegate$MeasurePassDelegate.remeasure-BRTryo0(LayoutNodeLayoutDelegate.kt:683)
       at androidx.compose.ui.node.LayoutNodeLayoutDelegate$MeasurePassDelegate.measure-BRTryo0(LayoutNodeLayoutDelegate.kt:672)
       at androidx.compose.foundation.layout.RowColumnMeasurePolicyKt.measure(RowColumnMeasurePolicy.kt:119)
       at androidx.compose.foundation.layout.RowColumnMeasurePolicyKt.measure$default(RowColumnMeasurePolicy.kt:74)
       at androidx.compose.foundation.layout.ColumnMeasurePolicy.measure-3p2s80s(Column.kt:208)
       at androidx.compose.ui.node.InnerNodeCoordinator.measure-BRTryo0(InnerNodeCoordinator.kt:135)
       at androidx.compose.ui.node.LayoutNodeLayoutDelegate$performMeasureBlock$1.invoke(LayoutNodeLayoutDelegate.kt:316)
       at androidx.compose.ui.node.LayoutNodeLayoutDelegate$performMeasureBlock$1.invoke(LayoutNodeLayoutDelegate.kt:315)
       at androidx.compose.runtime.snapshots.Snapshot$Companion.observe(Snapshot.kt:503)
       at androidx.compose.runtime.snapshots.SnapshotStateObserver$ObservedScopeMap.observe(SnapshotStateObserver.kt:502)
       at androidx.compose.runtime.snapshots.SnapshotStateObserver.observeReads(SnapshotStateObserver.kt:258)
       at androidx.compose.ui.node.OwnerSnapshotObserver.observeReads$ui_release(OwnerSnapshotObserver.kt:133)
       at androidx.compose.ui.node.OwnerSnapshotObserver.observeMeasureSnapshotReads$ui_release(OwnerSnapshotObserver.kt:113)
       at androidx.compose.ui.node.LayoutNodeLayoutDelegate.performMeasure-BRTryo0(LayoutNodeLayoutDelegate.java:1775)
       at androidx.compose.ui.node.LayoutNodeLayoutDelegate.access$performMeasure-BRTryo0(LayoutNodeLayoutDelegate.java:40)
       at androidx.compose.ui.node.LayoutNodeLayoutDelegate$MeasurePassDelegate.remeasure-BRTryo0(LayoutNodeLayoutDelegate.kt:696)
       at androidx.compose.ui.node.LayoutNodeLayoutDelegate$MeasurePassDelegate.measure-BRTryo0(LayoutNodeLayoutDelegate.kt:672)
       at androidx.compose.foundation.layout.BoxMeasurePolicy.measure-3p2s80s(Box.kt:151)
       at androidx.compose.ui.node.InnerNodeCoordinator.measure-BRTryo0(InnerNodeCoordinator.kt:135)
       at androidx.compose.ui.graphics.SimpleGraphicsLayerModifier.measure-3p2s80s(GraphicsLayerModifier.kt)
       at androidx.compose.ui.node.LayoutModifierNodeCoordinator.measure-BRTryo0(LayoutModifierNodeCoordinator.kt:188)
       at androidx.compose.ui.graphics.BlockGraphicsLayerModifier.measure-3p2s80s(GraphicsLayerModifier.kt)
       at androidx.compose.ui.node.LayoutModifierNodeCoordinator.measure-BRTryo0(LayoutModifierNodeCoordinator.kt:188)
       at androidx.compose.foundation.layout.PaddingNode.measure-3p2s80s(Padding.kt:414)
       at androidx.compose.ui.node.LayoutModifierNodeCoordinator.measure-BRTryo0(LayoutModifierNodeCoordinator.kt:188)
       at androidx.compose.ui.node.LayoutNodeLayoutDelegate$performMeasureBlock$1.invoke(LayoutNodeLayoutDelegate.kt:316)
       at androidx.compose.ui.node.LayoutNodeLayoutDelegate$performMeasureBlock$1.invoke(LayoutNodeLayoutDelegate.kt:315)
       at androidx.compose.runtime.snapshots.Snapshot$Companion.observe(Snapshot.kt:503)
       at androidx.compose.runtime.snapshots.SnapshotStateObserver$ObservedScopeMap.observe(SnapshotStateObserver.kt:502)
       at androidx.compose.runtime.snapshots.SnapshotStateObserver.observeReads(SnapshotStateObserver.kt:258)
       at androidx.compose.ui.node.OwnerSnapshotObserver.observeReads$ui_release(OwnerSnapshotObserver.kt:133)
       at androidx.compose.ui.node.OwnerSnapshotObserver.observeMeasureSnapshotReads$ui_release(OwnerSnapshotObserver.kt:113)
       at androidx.compose.ui.node.LayoutNodeLayoutDelegate.performMeasure-BRTryo0(LayoutNodeLayoutDelegate.java:1775)
       at androidx.compose.ui.node.LayoutNodeLayoutDelegate.access$performMeasure-BRTryo0(LayoutNodeLayoutDelegate.java:40)
       at androidx.compose.ui.node.LayoutNodeLayoutDelegate$MeasurePassDelegate.remeasure-BRTryo0(LayoutNodeLayoutDelegate.kt:696)
       at androidx.compose.ui.node.LayoutNodeLayoutDelegate$MeasurePassDelegate.measure-BRTryo0(LayoutNodeLayoutDelegate.kt:672)
       at androidx.compose.foundation.layout.RowColumnMeasurePolicyKt.measure(RowColumnMeasurePolicy.kt:119)
       at androidx.compose.foundation.layout.RowColumnMeasurePolicyKt.measure$default(RowColumnMeasurePolicy.kt:74)
       at androidx.compose.foundation.layout.ColumnMeasurePolicy.measure-3p2s80s(Column.kt:208)
       at androidx.compose.ui.node.InnerNodeCoordinator.measure-BRTryo0(InnerNodeCoordinator.kt:135)
       at androidx.compose.foundation.ScrollingLayoutNode.measure-3p2s80s(Scroll.kt:416)
       at androidx.compose.ui.node.LayoutModifierNodeCoordinator.measure-BRTryo0(LayoutModifierNodeCoordinator.kt:188)
       at androidx.compose.ui.graphics.SimpleGraphicsLayerModifier.measure-3p2s80s(GraphicsLayerModifier.kt)
       at androidx.compose.ui.node.LayoutModifierNodeCoordinator.measure-BRTryo0(LayoutModifierNodeCoordinator.kt:188)
       at androidx.compose.foundation.layout.InsetsPaddingModifier.measure-3p2s80s(WindowInsetsPadding.kt:359)
       at androidx.compose.ui.node.BackwardsCompatNode.measure-3p2s80s(BackwardsCompatNode.kt:312)
       at androidx.compose.ui.node.LayoutModifierNodeCoordinator.measure-BRTryo0(LayoutModifierNodeCoordinator.kt:188)
       at androidx.compose.foundation.layout.FillNode.measure-3p2s80s(Size.kt:699)
       at androidx.compose.ui.node.LayoutModifierNodeCoordinator.measure-BRTryo0(LayoutModifierNodeCoordinator.kt:188)
       at androidx.compose.ui.node.LayoutNodeLayoutDelegate$performMeasureBlock$1.invoke(LayoutNodeLayoutDelegate.kt:316)
       at androidx.compose.ui.node.LayoutNodeLayoutDelegate$performMeasureBlock$1.invoke(LayoutNodeLayoutDelegate.kt:315)
       at androidx.compose.runtime.snapshots.Snapshot$Companion.observe(Snapshot.kt:2441)
       at androidx.compose.runtime.snapshots.SnapshotStateObserver$ObservedScopeMap.observe(SnapshotStateObserver.kt:502)
       at androidx.compose.runtime.snapshots.SnapshotStateObserver.observeReads(SnapshotStateObserver.kt:258)
       at androidx.compose.ui.node.OwnerSnapshotObserver.observeReads$ui_release(OwnerSnapshotObserver.kt:133)
       at androidx.compose.ui.node.OwnerSnapshotObserver.observeMeasureSnapshotReads$ui_release(OwnerSnapshotObserver.kt:113)
       at androidx.compose.ui.node.LayoutNodeLayoutDelegate.performMeasure-BRTryo0(LayoutNodeLayoutDelegate.java:1775)
       at androidx.compose.ui.node.LayoutNodeLayoutDelegate.access$performMeasure-BRTryo0(LayoutNodeLayoutDelegate.java:40)
       at androidx.compose.ui.node.LayoutNodeLayoutDelegate$MeasurePassDelegate.remeasure-BRTryo0(LayoutNodeLayoutDelegate.kt:696)
       at androidx.compose.ui.node.LayoutNode.remeasure-_Sx5XlM$ui_release(LayoutNode.kt:1222)
       at androidx.compose.ui.node.LayoutNode.remeasure-_Sx5XlM$ui_release$default(LayoutNode.kt:1213)
       at androidx.compose.ui.node.MeasureAndLayoutDelegate.doRemeasure-sdFAvZA(MeasureAndLayoutDelegate.kt:369)
       at androidx.compose.ui.node.MeasureAndLayoutDelegate.remeasureAndRelayoutIfNeeded(MeasureAndLayoutDelegate.kt:566)
       at androidx.compose.ui.node.MeasureAndLayoutDelegate.onlyRemeasureIfScheduled(MeasureAndLayoutDelegate.kt:660)
       at androidx.compose.ui.node.MeasureAndLayoutDelegate.forceMeasureTheSubtreeInternal(MeasureAndLayoutDelegate.kt:686)
       at androidx.compose.ui.node.MeasureAndLayoutDelegate.forceMeasureTheSubtreeInternal(MeasureAndLayoutDelegate.kt:693)
       at androidx.compose.ui.node.MeasureAndLayoutDelegate.forceMeasureTheSubtreeInternal(MeasureAndLayoutDelegate.kt:693)
       at androidx.compose.ui.node.MeasureAndLayoutDelegate.forceMeasureTheSubtreeInternal(MeasureAndLayoutDelegate.kt:693)
       at androidx.compose.ui.node.MeasureAndLayoutDelegate.forceMeasureTheSubtree(MeasureAndLayoutDelegate.kt:649)
       at androidx.compose.ui.platform.AndroidComposeView.forceMeasureTheSubtree(AndroidComposeView.android.kt:1304)
       at androidx.compose.ui.node.Owner.forceMeasureTheSubtree$default(Owner.java:263)
       at androidx.compose.ui.node.LayoutNodeLayoutDelegate$MeasurePassDelegate.remeasure-BRTryo0(LayoutNodeLayoutDelegate.kt:708)
       at androidx.compose.ui.node.LayoutNode.remeasure-_Sx5XlM$ui_release(LayoutNode.kt:1222)
       at androidx.compose.ui.node.MeasureAndLayoutDelegate.doRemeasure-sdFAvZA(MeasureAndLayoutDelegate.kt:367)
       at androidx.compose.ui.node.MeasureAndLayoutDelegate.remeasureOnly(MeasureAndLayoutDelegate.kt:622)
       at androidx.compose.ui.node.MeasureAndLayoutDelegate.measureOnly(MeasureAndLayoutDelegate.kt:420)
       at androidx.compose.ui.platform.AndroidComposeView.onMeasure(AndroidComposeView.android.kt:1375)
       at android.view.View.measure(View.java:28571)
       at androidx.compose.ui.platform.AbstractComposeView.internalOnMeasure$ui_release(ComposeView.android.kt:309)
       at androidx.compose.ui.platform.AbstractComposeView.onMeasure(ComposeView.android.kt:296)
       at android.view.View.measure(View.java:28571)
       at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:7390)
       at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
       at android.view.View.measure(View.java:28571)
       at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:7390)
       at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
       at android.view.View.measure(View.java:28571)
       at android.widget.LinearLayout.measureVertical(LinearLayout.java:1031)
       at android.widget.LinearLayout.onMeasure(LinearLayout.java:721)
       at android.view.View.measure(View.java:28571)
       at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:7390)
       at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
       at androidx.appcompat.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:141)
       at android.view.View.measure(View.java:28571)
       at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:7390)
       at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1608)
       at android.widget.LinearLayout.measureVertical(LinearLayout.java:878)
       at android.widget.LinearLayout.onMeasure(LinearLayout.java:721)
       at android.view.View.measure(View.java:28571)
       at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:7390)
       at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
       at android.view.View.measure(View.java:28571)
       at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:7390)
       at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1608)
       at android.widget.LinearLayout.measureVertical(LinearLayout.java:878)
       at android.widget.LinearLayout.onMeasure(LinearLayout.java:721)
       at android.view.View.measure(View.java:28571)
       at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:7390)
       at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
       at com.android.internal.policy.DecorView.onMeasure(DecorView.java:1036)
       at android.view.View.measure(View.java:28571)
       at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:5203)
       at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:3603)
       at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:3973)
       at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:3288)
       at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:11344)
       at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1689)
       at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1698)
       at android.view.Choreographer.doCallbacks(Choreographer.java:1153)
       at android.view.Choreographer.doFrame(Choreographer.java:1079)
       at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:1646)
       at android.os.Handler.handleCallback(Handler.java:958)
       at android.os.Handler.dispatchMessage(Handler.java:99)
       at android.os.Looper.loopOnce(Looper.java:230)
       at android.os.Looper.loop(Looper.java:319)
       at android.app.ActivityThread.main(ActivityThread.java:8919)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:578)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1103)