fix(android): Parent view steals map pan gesture#100
Open
ottor-o wants to merge 1 commit intopinpong:devfrom
Open
fix(android): Parent view steals map pan gesture#100ottor-o wants to merge 1 commit intopinpong:devfrom
ottor-o wants to merge 1 commit intopinpong:devfrom
Conversation
Owner
|
Thanks for the PR, diff --git a/android/src/main/java/com/rngooglemapsplus/GoogleMapsViewImpl.kt b/android/src/main/java/com/rngooglemapsplus/GoogleMapsViewImpl.kt
index 25339a8..b9953ff 100644
--- a/android/src/main/java/com/rngooglemapsplus/GoogleMapsViewImpl.kt
+++ b/android/src/main/java/com/rngooglemapsplus/GoogleMapsViewImpl.kt
@@ -10,6 +10,7 @@ import android.content.res.Configuration
import android.graphics.Bitmap
import android.location.Location
import android.util.Size
+import android.view.MotionEvent
import android.view.View
import android.widget.FrameLayout
import androidx.lifecycle.Lifecycle
@@ -106,6 +107,7 @@ class GoogleMapsViewImpl(
private val urlTileOverlaysById = mutableMapOf<String, TileOverlay>()
private var cameraMoveReason = -1
+ private var parentTouchInterceptDisallowed = false
val componentCallbacks =
object : ComponentCallbacks2 {
@@ -181,6 +183,52 @@ class GoogleMapsViewImpl(
}
}
+ private fun setParentTouchInterceptDisallowed(blocked: Boolean) {
+ if (parentTouchInterceptDisallowed == blocked) return
+ parentTouchInterceptDisallowed = blocked
+ var p = parent
+ while (p != null) {
+ p.requestDisallowInterceptTouchEvent(blocked)
+ p = p.parent
+ }
+ }
+
+ override fun dispatchTouchEvent(ev: MotionEvent): Boolean {
+ val panEnabled = uiSettings?.scrollEnabled == true
+ val zoomEnabled = uiSettings?.zoomGesturesEnabled == true
+ val rotateEnabled = uiSettings?.rotateEnabled == true
+ val tiltEnabled = uiSettings?.tiltEnabled == true
+
+ val multiTouchEnabled = zoomEnabled || rotateEnabled || tiltEnabled
+ val anyMapGestureEnabled = panEnabled || multiTouchEnabled
+ if (!anyMapGestureEnabled) return super.dispatchTouchEvent(ev)
+
+ when (ev.actionMasked) {
+ MotionEvent.ACTION_DOWN,
+ MotionEvent.ACTION_MOVE,
+ MotionEvent.ACTION_POINTER_DOWN,
+ -> {
+ val pointers = ev.pointerCount
+ val shouldBlockParent = pointers >= (if (panEnabled) 1 else 2)
+ setParentTouchInterceptDisallowed(shouldBlockParent)
+ }
+
+ MotionEvent.ACTION_POINTER_UP -> {
+ val pointers = ev.pointerCount - 1
+ val shouldBlockParent = pointers >= (if (panEnabled) 1 else 2)
+ setParentTouchInterceptDisallowed(shouldBlockParent)
+ }
+
+ MotionEvent.ACTION_UP,
+ MotionEvent.ACTION_CANCEL,
+ -> {
+ setParentTouchInterceptDisallowed(false)
+ }
+ }
+
+ return super.dispatchTouchEvent(ev)
+ }
+
override fun onCameraMoveStarted(reason: Int) =
onUi {
if (!mapViewLoaded) return@onUi
@@ -875,6 +923,7 @@ class GoogleMapsViewImpl(
}
override fun onDetachedFromWindow() {
+ setParentTouchInterceptDisallowed(false)
lifecycleObserver?.let { lifecycle?.removeObserver(it) }
lifecycle = null
super.onDetachedFromWindow() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Pull request
Please ensure this PR targets the
devbranch and follows the project conventions.CI already runs linting, formatting, and build checks automatically.
Before submitting
devbranch (notmain)Summary
This fixes an issue where parent PagerView (and ScrollView?) steals MapView's pan gesture.
Type of change
Scope
Related
List any related issues, pull requests, or discussions.
Use the format:
Fixes #123,Refs #456,Close #789Additional notes
If you have a map inside a PagerView (and ScrollView?) with touch events enabled, they override MapView's pan gesture. The expected behaviour is to be able to pan the map normally. This is the current behaviour on iOS.