Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google map touch on bottom sheet dialog

I have a google map fragment on the top of my bottom sheet dialog. I disabled the draggable touch action on the bottom sheet behavior so that I could control the map. The problem is that I can't scroll the map using up or down touch actions because of my bottom sheet draggable disabled. I was thinking to disable the touch action of the bottom sheet behavior when the user touches the map but I don't know how to do this. How can I fix this?

like image 338
Dan Ponce Avatar asked Sep 06 '25 03:09

Dan Ponce


2 Answers

Try adding nestedScrollingEnabled="true" to the bottom sheet layout:

 <androidx.constraintlayout.widget.ConstraintLayout
    android:id="@+id/bottom_sheet"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:nestedScrollingEnabled="true"
    app:behavior_hideable="true"
    app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior">
like image 98
David Jarvis Avatar answered Sep 07 '25 23:09

David Jarvis


I have a BottomSheetDialogFragment (parent View) that contains SupportMapFragment (child View). Panning the map works only for horizontal gestures. As OP mentioned, this is because BottomSheet and Map touch events are in conflict when it comes to vertical gestures.

This is how I handled it. My BottomSheetDialogFragment implements OnMapReadyCallback and GoogleMap.OnCameraMoveStartedListener.

override fun onMapReady(p0: GoogleMap) {
    p0.setOnCameraMoveStartedListener(this)
}

override fun onCameraMoveStarted(reason: Int) {
    when(reason) {
        GoogleMap.OnCameraMoveStartedListener.REASON_GESTURE -> {
            // The user gestured on the map
            childView?.parent?.requestDisallowInterceptTouchEvent(true)
        }
        GoogleMap.OnCameraMoveStartedListener.REASON_API_ANIMATION -> {
            // The user tapped something on the map
            childView?.parent?.requestDisallowInterceptTouchEvent(true)
        }
        GoogleMap.OnCameraMoveStartedListener.REASON_DEVELOPER_ANIMATION -> {
            // The app moved the camera
            childView?.parent?.requestDisallowInterceptTouchEvent(true)
        }
    }
}

When set as true, requestDisallowInterceptTouchEvent() does not allow the parent View to intercept with the touch events of the child View. I can now zoom in/out the map (horizontal and vertical gestures) in my bottom sheet dialog fragment.

like image 40
zeenosaur Avatar answered Sep 07 '25 21:09

zeenosaur