Skip to content

Commit

Permalink
fix: aware exception invoke
Browse files Browse the repository at this point in the history
  • Loading branch information
gronxb committed Nov 12, 2024
1 parent 391f68d commit d3112b9
Showing 1 changed file with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,25 @@ class JSPointerDispatcherCompat(
eventDispatcher: EventDispatcher?,
isCapture: Boolean,
) {
val method =
try {
// The RN version with 3 arguments (i.e., RN >= 0.72)
try {
// Try to get the method with 3 parameters (for RN >= 0.72)
val method =
JSPointerDispatcher::class.java.getMethod(
"handleMotionEvent",
MotionEvent::class.java,
EventDispatcher::class.java,
Boolean::class.javaPrimitiveType,
)
} catch (_: NoSuchMethodException) {
// The RN version with 2 arguments (i.e., RN < 0.72)
method.invoke(this, event, eventDispatcher, isCapture)
} catch (_: NoSuchMethodException) {
// Fallback to 2-parameter version (for RN < 0.72)
val method =
JSPointerDispatcher::class.java.getMethod(
"handleMotionEvent",
MotionEvent::class.java,
EventDispatcher::class.java,
)
}
method.invoke(this, event, eventDispatcher, isCapture)
method.invoke(this, event, eventDispatcher)
}
}
}

0 comments on commit d3112b9

Please sign in to comment.