React-native: feature: can merge NativeAppEventEmitter and DeviceEventEmitter?

Created on 3 May 2016  路  12Comments  路  Source: facebook/react-native

NativeAppEventEmitter and DeviceEventEmitter has similar (or same?) API, how about merge them into NativeEventEmitter?

Locked Discussion

Most helpful comment

Is there really any more difference than one is for Android and the other for iOS? I couldn't find any docs mentioning one vs the other, but I have never been able to use NativeAppEventEmitter on Android, and even the documentation on creating native modules uses DeviceEventEmitter on Android and NativeAppEventEmitter on iOS.

All 12 comments

Removed issue template for clarity.

I believe it's a perf optimisation and also a good way to separate device-specific events like appDidEnterBackground with the app-specific events (e.g. your custom events you may call from your module).

Back in the day there used to be some docs that got removed: https://github.com/facebook/react-native/commit/9a2e7a852a439e2cd919aa7cef58021bc3fcda53

appEmitter - Send an application-specific event that does not relate to a specific view

and

deviceEmitter - Send a device or iOS event that does not relate to a specific view, e.g.rotation, location, keyboard show/hide, background/awake,

Is there really any more difference than one is for Android and the other for iOS? I couldn't find any docs mentioning one vs the other, but I have never been able to use NativeAppEventEmitter on Android, and even the documentation on creating native modules uses DeviceEventEmitter on Android and NativeAppEventEmitter on iOS.

Is there really any more difference than one is for Android and the other for iOS?

Both are available on both platforms. You can check how to use NativeAppEventEmitter on Android here

I am going to close this one since there's some work to make an emitter scoped to native module, as per Nick commit here: https://github.com/facebook/react-native/commit/9ee1f37bade91d7db490cb3cb702104f268654ae where the OP question is answered.

I think that at least the documentation should be updated to reflect that they are not platform-specific, since the iOS and Android guides do differ in what module it uses in the guide.

I agree that the documentation is confusing here. Worth updating it. I would love to do it myself I was clear enough about this important feature but I am not yet.

I am also confusiing here.Please update the documentation about them.

I am happy to answer any questions you might have - I don't have time myself to contribute to the documentation right now, but I am happy to provide you with some extra info :)

Thank you , grabbu. I found the doucmentation here https://facebook.github.io/react-native/docs/native-modules-ios.html. I tried all Emitter.The conclusion is that DeviceEventEmitter and NativeAppEventEmitter only be used in android, NativeEventEmitter only be used in ios.

Please refer to my original comment where I outlined the differences. Both are available on both platforms.

DeviceEventEmitter for android communicating with native.

NativeEventEmitter for iOS communicating with native.

NativeAppEventEmitter was deprecated.

Is it right?

And is there any react-native event module (or js module) for communicating between react components? like listener or subscriber?

Is is possible using Event interface in react-native?

Or can component be the EventTarget?

EventTarget is an interface implemented by objects that can receive events and may have listeners for them.

Element, document, and window are the most common event targets, but other objects can be event targets too, for example XMLHttpRequest, AudioNode, AudioContext, and others.

Many event targets (including elements, documents, and windows) also support setting event handlers via on... properties and attributes.

I am using self designed NotificationCenter for sending and receiving messages between components.

Is it recommended by official?

Was this page helpful?
0 / 5 - 0 ratings