diff --git a/android/src/main/java/com/reactnativekeyboardcontroller/views/overlay/JSPointerDispatcherCompat.kt b/android/src/main/java/com/reactnativekeyboardcontroller/views/overlay/JSPointerDispatcherCompat.kt index a101e6431c..42b1feb2fe 100644 --- a/android/src/main/java/com/reactnativekeyboardcontroller/views/overlay/JSPointerDispatcherCompat.kt +++ b/android/src/main/java/com/reactnativekeyboardcontroller/views/overlay/JSPointerDispatcherCompat.kt @@ -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, @@ -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, ) @@ -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 + } }