Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jetpack Compose: Scaffold drawer opens when dragging MapView

When using the drawer in a Jetpack Compose scaffold, gestures can be used to open and close it. If the scaffold content contains a MapView, the map cannot be dragged around horizontally. Instead, the drawer is opened.

When scrollable rows are dragged (scrolled) through horizontally this does not happen, the drawer is not opened then.

How can I prevent the drawer from opening when the map is dragged by the user? When the rest of the scaffold content is dragged, the gesture should still work.

Unfortunately, wrapping the AndroidView with a Row does not solve the problem, as well as using the ModalDrawer instead of the scaffold.


Code to reproduce with Compose rc02 and kotlin 1.5.10 (EDIT: verified with Compose 1.0.3 and Kotlin 1.5.30):

class MainActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            MaterialTheme {
                Scaffold(
                    drawerContent = {
                        Text("Drawer Content")
                    },
                    content = {
                        Column {
                            Text("Dragging here should open the drawer")

                            val mapView = rememberMapViewWithLifecycle()
                            AndroidView({ mapView }, Modifier.fillMaxSize())
                        }
                    }
                )
            }
        }
    }
}

The function rememberMapViewWithLifecycle() is taken from the Crane sample app.

like image 617
qr_3 Avatar asked Jul 28 '21 12:07

qr_3


People also ask

What is mutableStateOf in jetpack compose?

mutableStateOf creates an observable MutableState<T> , which is an observable type integrated with the compose runtime. interface MutableState<T> : State<T> { override var value: T. } Any changes to value will schedule recomposition of any composable functions that read value .

What is LazyColumn in jetpack compose?

A LazyColumn is a vertically scrolling list that only composes and lays out the currently visible items. It's similar to a Recyclerview in the classic Android View system.

Is jetpack compose reactive?

Jetpack Compose is a modern toolkit designed to simplify UI development. It combines a reactive programming model with the conciseness and ease of use of the Kotlin programming language.

How do you scroll a column in jetpack compose?

We can make the Column scrollable by using the verticalScroll() modifier.


Video Answer


1 Answers

Something similar happened to me when trying to integrate MapBox into an app with NavigationDrawer using Jetpack Compose. What I did was add the property drawerGesturesEnabled = false, of the Scaffold, in this way the NavigationDrawer continues to work when I click on the menu Icon

If you use drawerGesturesEnabled = scaffoldState.drawerState.isOpen you can close it normally

like image 130
Orlando Novas Rodriguez Avatar answered Oct 24 '22 07:10

Orlando Novas Rodriguez