Skip to content

Commit

Permalink
fix(android): count native listeners / correctly disable listener if …
Browse files Browse the repository at this point in the history
…count == 0 (#569)
  • Loading branch information
Legion2 committed Jan 26, 2022
1 parent 35c68c8 commit 5ae16f6
Showing 1 changed file with 5 additions and 3 deletions.
Expand Up @@ -21,6 +21,8 @@ public class NetInfoModule extends ReactContextBaseJavaModule implements AmazonF
private final ConnectivityReceiver mConnectivityReceiver;
private final AmazonFireDeviceConnectivityPoller mAmazonConnectivityChecker;

private int numberOfListeners = 0;

public NetInfoModule(ReactApplicationContext reactContext) {
super(reactContext);
// Create the connectivity receiver based on the API level we are running on
Expand Down Expand Up @@ -63,14 +65,14 @@ public void onAmazonFireDeviceConnectivityChanged(boolean isConnected) {

@ReactMethod
public void addListener(String eventName) {
// Keep: Required for RN built in Event Emitter Calls.
numberOfListeners++;
mConnectivityReceiver.hasListener = true;
}

@ReactMethod
public void removeListeners(Integer count) {
// Keep: Required for RN built in Event Emitter Calls.
if (count == 0) {
numberOfListeners -= count;
if (numberOfListeners == 0) {
mConnectivityReceiver.hasListener = false;
}
}
Expand Down

0 comments on commit 5ae16f6

Please sign in to comment.