简体   繁体   中英

Jetpack Compose: Allow gestures to pass through Scaffold

I'm building an app using Scaffold for the home screen. I have a requirement that the Scaffold is over a map. (I'm using Google Maps for that. I'm using the implementation from the "Crane" app from the Compose sample apps.) The reason for this is so that even when the tab is changed, the map will remain the same.

在此处输入图像描述

I've successfully added the map and the scaffold over the top but I've run into a problem. I cannot drag the map when the scaffold is on top of it.

I know the problem isn't the map because if I remove the Scaffold then I can drag the map. I also know the problem isn't that the scaffold catches clicks because I added a clickable box under the Scaffold and was able to detect clicks on it.

I suspect that maybe the Scaffold's drawer gesture detection is consuming the gestures but I set drawerGesturesEnabled to false and still no luck.

Does anyone out there know why I can't drag my Google MapView through the Scaffold? Or have any suggestions how I might get around it?

I had a similar issue with Webview within scaffold content and when I disabled gestures on the scaffold the scroll improved on the webview.

             Scaffold(
                drawerGesturesEnabled = false, 

The bad thing is that the drawercontent then needs to be shown by commands

I had a similar use case to cover and this worked for me. You should use BackdropScaffold

val backdropState = rememberBackdropScaffoldState(BackdropValue.Revealed)
val frontLayerHeightDp = LocalConfiguration.current.screenHeightDp / 3

BackdropScaffold(
    modifier = modifier,
    scaffoldState = backdropState,
    peekHeight = 0.dp,
    headerHeight = frontLayerHeightDp.dp,
    frontLayerShape = BottomSheetShape,
    frontLayerScrimColor = Color.Transparent,
    appBar = {},
    backLayerContent = {
        BackContent()
    },
    frontLayerContent = {
        FrontContent()
    }
)

As BackContent I used the new GoogleMap composable, just check the example on github is really easy to use.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM