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
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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

}
}

@ReactProp(name = "deselectAnnotationOnTap")
Expand Down
Loading