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.
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 .
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.
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.
We can make the Column scrollable by using the verticalScroll() modifier.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With