I have a scenario where I have a fragment inside an activity (extending AppCompatActivity). Now from this fragment I need to post an event that I can listen to in my react-native code
Fragment.class
public class MyFragment extends Fragment {
......
public void onBookingCompleted(boolean success) {
if (success) {
sendEventToReact(); // <--- function i used to send event to my react native code
}
}
private void sendEventToReact() {
ReactApplicationContext context = (ReactApplicationContext) getContext();
context.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
.emit("YouCustomEventName", null);
}
}
Now the problem is, I cannot convert my context
to ReactApplicationContext
I already had a look at this answer, but I want to know if there is any way I can post this event from a fragment inside an activity which is NOT
extending ReactActivity
Also is there a way where I can pass an event from my fragment to my native module which can further pass this to react-native?