Skip to content

Commit

Permalink
fix: missing import, detekt
Browse files Browse the repository at this point in the history
  • Loading branch information
kirillzyusko committed Nov 12, 2024
1 parent b696ead commit 95344b8
Showing 1 changed file with 14 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,19 @@ import android.view.MotionEvent
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
*/
class JSPointerDispatcherCompat(
private val viewGroup: ViewGroup,
viewGroup: ViewGroup,
) : JSPointerDispatcher(viewGroup) {
private val handleMotionEventMethod: Method? by lazy {
try {
// Try to get the 3-parameter method (for RN >= 0.72)
JSPointerDispatcher::class.java.getMethod(
"handleMotionEvent",
HANDLE_MOTION_EVENT,
MotionEvent::class.java,
EventDispatcher::class.java,
Boolean::class.javaPrimitiveType,
Expand All @@ -24,7 +25,7 @@ class JSPointerDispatcherCompat(
try {
// Fallback to 2-parameter method (for RN < 0.72)
JSPointerDispatcher::class.java.getMethod(
"handleMotionEvent",
HANDLE_MOTION_EVENT,
MotionEvent::class.java,
EventDispatcher::class.java,
)
Expand All @@ -40,13 +41,16 @@ class JSPointerDispatcherCompat(
isCapture: Boolean,
) {
handleMotionEventMethod?.let { method ->
val parameters =
if (method.parameterCount == 3) {
arrayOf(event, eventDispatcher, isCapture)
} else {
arrayOf(event, eventDispatcher)
}
method.invoke(this, *parameters)
if (method.parameterCount == THREE_PARAMETERS) {
method.invoke(this, event, eventDispatcher, isCapture)
} else {
method.invoke(this, event, eventDispatcher)
}
}
}

companion object {
private const val HANDLE_MOTION_EVENT = "handleMotionEvent"
private const val THREE_PARAMETERS = 3
}
}

0 comments on commit 95344b8

Please sign in to comment.