-
Hi there ! I've been trying to update several third party libraries so that they support both old and new architecture. I'm struggling on this one: ibitcy/react-native-hole-view#22 The legacy code of this lib draws a "hole" in the component UI and re-dispatches all touch events to the components behind it. The related code to that in the lib is: // ...
class RNHoleView(context: Context) : ReactViewGroup(context) {
// ...
private val mEventDispatcher: EventDispatcher
init {
// ...
val uiManager = (context as ReactContext).getNativeModule(UIManagerModule::class.java)
mEventDispatcher = uiManager!!.eventDispatcher
}
// ...
override fun dispatchTouchEvent(ev: MotionEvent): Boolean {
val inside = isTouchInsideHole(ev.x.toInt(), ev.y.toInt())
if (inside) {
passTouchEventToViewAndChildren(getRoot(), ev)
}
return !inside
}
private fun passTouchEventToViewAndChildren(v: ViewGroup, ev: MotionEvent) {
val childrenCount = v.childCount
for (i in 0 until childrenCount) {
val child = v.getChildAt(i)
if (child.id > 0 && isViewInsideTouch(ev, child) && child.visibility == View.VISIBLE) {
try {
mEventDispatcher.dispatchEvent(
TouchEvent.obtain(
child.id,
TouchEventType.START,
ev,
ev.eventTime,
ev.x,
ev.y,
TouchEventCoalescingKeyHelper()
)
)
} catch (e: Exception) {
}
if (child is ViewGroup && child.childCount > 0) {
passTouchEventToViewAndChildren(child, ev)
}
}
}
}
// ... At runtime, when touching the component's "hole", I'm getting errors like those below in logcat:
Now, I understand that the UIManager should probably not be used with the new architecture but how can I dispatch events to the other components ? Thanks in advance for any help on this... |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
I've tried passing a surface id to Also, I always get the value println("debug 1 "+UIManagerHelper.getSurfaceId(v))
println("debug 2 "+UIManagerHelper.getSurfaceId(getRoot()))
println("debug 3 "+UIManagerHelper.getSurfaceId(this as ViewGroup)) |
Beta Was this translation helpful? Give feedback.
-
OK, I've fixed my problem by changing the way I get the event dispatcher I use. I now do this: private fun passTouchEventToViewAndChildren(v: ViewGroup, ev: MotionEvent) {
val childrenCount = v.childCount
for (i in 0 until childrenCount) {
val child = v.getChildAt(i)
if (child.id > 0 && isViewInsideTouch(ev, child) && child.visibility == View.VISIBLE) {
try {
val mmEventDispatcher = UIManagerHelper.getEventDispatcherForReactTag((context as ReactContext), child.id) ;
mmEventDispatcher!!.dispatchEvent(
TouchEvent.obtain(
UIManagerHelper.getSurfaceId(child),
child.id,
TouchEventType.START,
ev,
ev.eventTime,
ev.x,
ev.y,
TouchEventCoalescingKeyHelper()
)
)
} catch (e: Exception) {
}
if (child is ViewGroup && child.childCount > 0) {
passTouchEventToViewAndChildren(child, ev)
}
}
}
} It works on both old and new arch. |
Beta Was this translation helpful? Give feedback.
OK, I've fixed my problem by changing the way I get the event dispatcher I use.
I now do this: