Skip to content

Commit

Permalink
android added listeners counting react-native-netinfo#567
Browse files Browse the repository at this point in the history
  • Loading branch information
Legion2 committed Jan 26, 2022
1 parent 35c68c8 commit 1cdf0c8
Showing 1 changed file with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
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 1cdf0c8

Please sign in to comment.