Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(android): requestDisallowInterceptTouchEvent broken #3333

Merged
merged 3 commits into from
Jan 21, 2024

Conversation

VolkerLieber
Copy link
Contributor

Description

Fixes #3326 by waiting until mMapView has been initialized.

@@ -327,7 +327,9 @@ open class RNMBXMapViewManager(context: ReactApplicationContext, val viewTagReso

@ReactProp(name = "requestDisallowInterceptTouchEvent")
override fun setRequestDisallowInterceptTouchEvent(mapView: RNMBXMapView, requestDisallowInterceptTouchEvent: Dynamic) {
mapView.requestDisallowInterceptTouchEvent = requestDisallowInterceptTouchEvent.asBoolean()
mapView.withMapView {
it.requestDisallowInterceptTouchEvent = requestDisallowInterceptTouchEvent.asBoolean()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
it.requestDisallowInterceptTouchEvent = requestDisallowInterceptTouchEvent.asBoolean()
it.requestDisallowInterceptTouchEvent = mapView.requestDisallowInterceptTouchEvent

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would that not just be x = x ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Variable naming is a bit confusing there. ‘it’ is mapbox’s MapView, mapView is RNMBXMapView

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My bad, I have to admit, that I tried to fix this issue while being on the go. I've now correctly set up the development environment and my new commit seems to be the best solution for me.

@ReactProp(name = "requestDisallowInterceptTouchEvent")
override fun setRequestDisallowInterceptTouchEvent(mapView: RNMBXMapView, requestDisallowInterceptTouchEvent: Dynamic) {
    mapView.requestDisallowInterceptTouchEvent = requestDisallowInterceptTouchEvent.asBoolean()
}

Calls

var requestDisallowInterceptTouchEvent: Boolean = false
    set(value) {
        val oldValue = field
        field = value
        updateRequestDisallowInterceptTouchEvent(oldValue, value)
    }

Which calls

fun RNMBXMapView.updateRequestDisallowInterceptTouchEvent(oldValue: Boolean, value: Boolean) {
    if (oldValue == value) {
        return
    }
    if (value) {
        mapView.setOnTouchListener { view, event ->
            this.requestDisallowInterceptTouchEvent(true)
            mapView.onTouchEvent(event)
            true
        }
    } else {
        mapView.setOnTouchListener { view, event ->
            mapView.onTouchEvent(event)
        }
    }
}

The issue arises, because mapView is not initialized then mapView.setOnTouchListener is first called. By wrapping it with withMapView, this should be fixed.

What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good

@mfazekas mfazekas changed the title Fix requestDisallowInterceptTouchEvent broken fix(android): requestDisallowInterceptTouchEvent broken Jan 21, 2024
@mfazekas mfazekas merged commit 2784b74 into rnmapbox:main Jan 21, 2024
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: requestDisallowInterceptTouchEvent broken
2 participants