Closed cortinico closed 7 months ago
Thanks @cortinico for working on this. I've tested the code and it seems to work well.
Have tested by creating a test app using this guide: https://gist.github.com/cipolleschi/82b7a9561b8861330efabbd3eb08c6f5
RN version: 0.74.0-rc.9
tested: old architecture, new architecture(bridge + bridgeless)
With the newArchEnabled=true
set in gradle.properties
, I occasionally see below error without this PR applied:
(cc @Naturalclar )
java.lang.IllegalStateException: Tried to access a JS module before the React instance was fully set up. Calls to ReactContext#getJSModule should only happen once initialize() has been called on your native module.
at com.facebook.react.bridge.ReactContext.getJSModule(ReactContext.java:180)
at com.reactnativemenu.MenuView.prepareMenuItem$lambda$0(MenuView.kt:174)
at com.reactnativemenu.MenuView.$r8$lambda$zm-y_PJLhF-4MEW-E0Gpwcuw7es(Unknown Source:0)
at com.reactnativemenu.MenuView$$ExternalSyntheticLambda2.onMenuItemClick(Unknown Source:4)
at com.android.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:148)
at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:935)
at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:925)
at com.android.internal.view.menu.MenuPopup.onItemClick(MenuPopup.java:128)
at android.widget.AdapterView.performItemClick(AdapterView.java:330)
at android.widget.AbsListView.performItemClick(AbsListView.java:1265)
at android.widget.AbsListView$PerformClick.run(AbsListView.java:3278)
at android.widget.AbsListView$3.run(AbsListView.java:4244)
at android.os.Handler.handleCallback(Handler.java:958)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loopOnce(Looper.java:205)
at android.os.Looper.loop(Looper.java:294)
at android.app.ActivityThread.main(ActivityThread.java:8177)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:552)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:971)
Overview
This is an example of how you should use
EventDispatcher
rather thanRCTEventEmitter
for event dispatching on Android (both old and new architecture).Test Plan
I haven't tested this yet.