Skip to content

Commit 46f27fc

Browse files
authored
fix(android): use composition for JSPointerDispatcherCompat (#1477)
## 📜 Description JSPointerDispatcher became a final Kotlin class in React Native 0.87+ (after the Java-to-Kotlin migration in react/react-native#56910), so JSPointerDispatcherCompat can no longer extend it. While I'm restoring it in: - react/react-native#57022 Ideally we would want to reduce the API surface of RN apis. So here I'm switching from inheritance to composition by holding an internal JSPointerDispatcher delegate and forwarding calls to it. ## 🤔 How Has This Been Tested? Looking for guidance on how to test this. <!-- Please describe in detail how you tested your changes. --> <!-- Include details of your testing environment, and the tests you ran to --> <!-- see how your change affects other areas of the code, etc. --> ## 📸 Screenshots (if appropriate): N/A <!-- Add screenshots/video if needed --> <!-- That would be highly appreciated if you can add how it looked before and after your changes --> ## 📝 Checklist - [ ] CI successfully passed - [ ] I added new mocks and corresponding unit-tests if library API was changed
1 parent adafcc8 commit 46f27fc

1 file changed

Lines changed: 22 additions & 4 deletions

File tree

android/src/main/java/com/reactnativekeyboardcontroller/views/overlay/JSPointerDispatcherCompat.kt

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,23 @@
11
package com.reactnativekeyboardcontroller.views.overlay
22

33
import android.view.MotionEvent
4+
import android.view.View
45
import android.view.ViewGroup
56
import com.facebook.react.uimanager.JSPointerDispatcher
67
import com.facebook.react.uimanager.events.EventDispatcher
78
import java.lang.reflect.Method
89

910
/**
10-
* Compat layer for `JSPointerDispatcher` interface for RN < 0.72
11+
* Compat layer for `JSPointerDispatcher` interface for RN < 0.72.
12+
*
13+
* Uses composition instead of inheritance because `JSPointerDispatcher`
14+
* became a final Kotlin class in RN 0.87+.
1115
*/
1216
class JSPointerDispatcherCompat(
1317
viewGroup: ViewGroup,
14-
) : JSPointerDispatcher(viewGroup) {
18+
) {
19+
private val delegate = JSPointerDispatcher(viewGroup)
20+
1521
private val handleMotionEventMethod: Method? by lazy {
1622
try {
1723
// Try to get the 3-parameter method (for RN >= 0.72)
@@ -42,13 +48,25 @@ class JSPointerDispatcherCompat(
4248
) {
4349
handleMotionEventMethod?.let { method ->
4450
if (method.parameterCount == RN_72_PARAMS_COUNT) {
45-
method.invoke(this, event, eventDispatcher, isCapture)
51+
method.invoke(delegate, event, eventDispatcher, isCapture)
4652
} else {
47-
method.invoke(this, event, eventDispatcher)
53+
method.invoke(delegate, event, eventDispatcher)
4854
}
4955
}
5056
}
5157

58+
fun onChildStartedNativeGesture(
59+
childView: View?,
60+
ev: MotionEvent,
61+
eventDispatcher: EventDispatcher,
62+
) {
63+
delegate.onChildStartedNativeGesture(childView, ev, eventDispatcher)
64+
}
65+
66+
fun onChildEndedNativeGesture() {
67+
delegate.onChildEndedNativeGesture()
68+
}
69+
5270
companion object {
5371
private const val HANDLE_MOTION_EVENT = "handleMotionEvent"
5472
private const val RN_72_PARAMS_COUNT = 3

0 commit comments

Comments
 (0)