[go: nahoru, domu]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
spremathilaka opened this issue Sep 22, 2023 · 6 comments
Labels
triage me I really want to be triaged. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@spremathilaka
Copy link
spremathilaka commented Sep 22, 2023

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

@spremathilaka spremathilaka added triage me I really want to be triaged. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. labels Sep 22, 2023
@wangela
Copy link
Member
wangela commented Sep 22, 2023

If you would like to upvote the priority of this issue, please comment below or react on the original post above with 👍 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
Copy link
Member
wangela commented Sep 22, 2023

Is this related to #305?

@spremathilaka
Copy link
Author
spremathilaka commented Sep 22, 2023

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
Copy link

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

@kikoso
Copy link
Collaborator
kikoso commented Jan 25, 2024

@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
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
triage me I really want to be triaged. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
Development

No branches or pull requests

5 participants