I am trying to figure out how my Javascript code can listen to my native modules events that are being emitted from my Swift code in my React Native app. I cannot seem to find any official documentation and anything I find after a Google search is either outdated or is written in Obj-C whereas my event is fired from my Swift code. I hope that makes sense and any help would be appreciated!
Thanks, Aiden
2
Answers
I don’t think you can emit an event in custom swift code and then catch it in your react native code. I might be wrong. maybe consider local storage or server-side storage?
It’s actually described in quite a detail here.
RCTEventEmitter
(can be same or different class) This is the class that will send events to JS. The events are sent usingsendEventWithName
functionHere’s a very rough sketch:
Step 1: catch Swift events
Step 2: send them to JS