Skip to content
Merged
Changes from all 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
@@ -1,17 +1,23 @@
package com.reactnativekeyboardcontroller.views.overlay

import android.view.MotionEvent
import android.view.View
import android.view.ViewGroup
import com.facebook.react.uimanager.JSPointerDispatcher
import com.facebook.react.uimanager.events.EventDispatcher
import java.lang.reflect.Method

/**
* Compat layer for `JSPointerDispatcher` interface for RN < 0.72
* Compat layer for `JSPointerDispatcher` interface for RN < 0.72.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@kirillzyusko also this is quote of an old version of RN. Perhaps the compat layer can go altogether?

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Yes @cortinico

I will do it this year. I'm going to drop old architecture support and bump minimal RN version to RN 0.77 or something like this 🤞

I know that RN has window support for only 3 versions, but I believe I don't have so much conditional code to support more RN versions, so I'm fine to leave with few additional if-statements 🙂

*
* Uses composition instead of inheritance because `JSPointerDispatcher`
* became a final Kotlin class in RN 0.87+.
*/
class JSPointerDispatcherCompat(
viewGroup: ViewGroup,
) : JSPointerDispatcher(viewGroup) {
) {
private val delegate = JSPointerDispatcher(viewGroup)

private val handleMotionEventMethod: Method? by lazy {
try {
// Try to get the 3-parameter method (for RN >= 0.72)
Expand Down Expand Up @@ -42,13 +48,25 @@ class JSPointerDispatcherCompat(
) {
handleMotionEventMethod?.let { method ->
if (method.parameterCount == RN_72_PARAMS_COUNT) {
method.invoke(this, event, eventDispatcher, isCapture)
method.invoke(delegate, event, eventDispatcher, isCapture)
} else {
method.invoke(this, event, eventDispatcher)
method.invoke(delegate, event, eventDispatcher)
}
}
}

fun onChildStartedNativeGesture(
childView: View?,
ev: MotionEvent,
eventDispatcher: EventDispatcher,
) {
delegate.onChildStartedNativeGesture(childView, ev, eventDispatcher)
}

fun onChildEndedNativeGesture() {
delegate.onChildEndedNativeGesture()
}

companion object {
private const val HANDLE_MOTION_EVENT = "handleMotionEvent"
private const val RN_72_PARAMS_COUNT = 3
Expand Down
Loading