question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Android] No possible to handle JavaScript addListener event on native side

See original GitHub issue

I’m looking this code: https://github.com/facebook/react-native/blob/master/ReactAndroid/src/main/java/com/facebook/react/uimanager/events/EventDispatcher.java#L144

Correct me if I’m wrong but there is not clean solution how to handle JavaScript call to addListener("event") method from NativeEventEmitter.js on native - Java side.

If I have on native side Java listeners it’s need to add/remove them according to add/remove on JavaScript side.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
sytolkcommented, Jul 10, 2017

Yes I can call native method like @ReactMethod eventListeningStartedOnJS() but I don’t think this is cleanest solution. For iOS we can extend RCTEventEmitter and handle this:

/// This method will be called when the first event listener is added.
- (void)startObserving {}

/// This method will be called when the last event listener is removed.
- (void)stopObserving {}

Can we have the same for Android?

0reactions
hramoscommented, Sep 21, 2017

Hi there! This issue is being closed because it has been inactive for a while. Maybe the issue has been fixed in a recent release, or perhaps it is not affecting a lot of people. Either way, we’re automatically closing issues after a period of inactivity. Please do not take it personally!

If you think this issue should definitely remain open, please let us know. The following information is helpful when it comes to determining if the issue should be re-opened:

  • Does the issue still reproduce on the latest release candidate? Post a comment with the version you tested.
  • If so, is there any information missing from the bug report? Post a comment with all the information required by the issue template.
  • Is there a pull request that addresses this issue? Post a comment with the PR number so we can follow up.

If you would like to work on a patch to fix the issue, contributions are very welcome! Read through the contribution guide, and feel free to hop into #react-native if you need help planning your contribution.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to know that a JS event listener is registered on the ...
addEventListener requires an asynchronous call over the bridge from JS to native, so it's possible that MyModule starts emitting events before ...
Read more >
Sending Events to JavaScript from Your Native ... - Callstack
Android. Sending events from your Java module to JavaScript is pretty simple. The easiest way to do this is to use RCTDeviceEventEmitter ...
Read more >
Sending Events to JavaScript from Your Native ... - Medium
Communication between native modules and JavaScript thread happens through an event bus or, to be more specific, the bridge.
Read more >
React Native Events in Gory Details: What Happens on the ...
A listenerStore object containing arrays of listeners, functions that will be called when the matching event type is dispatched. · An addListener ......
Read more >
Touch events - Web APIs - MDN Web Docs - Mozilla
When the user lifts a finger off the surface, a touchend event is sent. We handle this by calling the handleEnd() function below....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found