Skip to content

Commit 3c3e777

Browse files
authored
Update RNAppsFlyerModule.java
1 parent ed38333 commit 3c3e777

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

android/src/main/java/com/appsflyer/reactnative/RNAppsFlyerModule.java

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
package com.appsflyer.reactnative;
23

34

@@ -57,7 +58,7 @@
5758

5859
import static com.appsflyer.reactnative.RNAppsFlyerConstants.*;
5960
import static com.appsflyer.reactnative.RNAppsFlyerConstants.afOnDeepLinking;
60-
61+
import java.util.concurrent.atomic.AtomicBoolean;
6162
public class RNAppsFlyerModule extends ReactContextBaseJavaModule {
6263

6364
private ReactApplicationContext reactContext;
@@ -323,14 +324,19 @@ public void logEvent(
323324
Activity currentActivity = getCurrentActivity();
324325
if (currentActivity != null) {
325326
AppsFlyerLib.getInstance().logEvent(getCurrentActivity(), eventName, data, new AppsFlyerRequestListener() {
327+
final AtomicBoolean isCompleted = new AtomicBoolean(false);
326328
@Override
327329
public void onSuccess() {
328-
successCallback.invoke(SUCCESS);
330+
if (isCompleted.compareAndSet(false, true)) {
331+
successCallback.invoke(SUCCESS);
332+
}
329333
}
330334

331335
@Override
332336
public void onError(int i, @NonNull String s) {
333-
errorCallback.invoke(s);
337+
if (isCompleted.compareAndSet(false, true)) {
338+
errorCallback.invoke(String.valueOf(i), s);
339+
}
334340
}
335341
});
336342
}
@@ -355,14 +361,19 @@ public void logEventWithPromise(
355361
Activity currentActivity = getCurrentActivity();
356362
if (currentActivity != null) {
357363
AppsFlyerLib.getInstance().logEvent(getCurrentActivity(), eventName, data, new AppsFlyerRequestListener() {
364+
final AtomicBoolean isCompleted = new AtomicBoolean(false);
358365
@Override
359366
public void onSuccess() {
360-
promise.resolve(SUCCESS);
367+
if (isCompleted.compareAndSet(false, true)) {
368+
promise.resolve(SUCCESS);
369+
}
361370
}
362371

363372
@Override
364373
public void onError(int i, @NonNull String s) {
365-
promise.reject(s);
374+
if (isCompleted.compareAndSet(false, true)) {
375+
promise.reject(String.valueOf(i), s);
376+
}
366377
}
367378
});
368379
}
@@ -1018,4 +1029,4 @@ public void addListener(String eventName) {
10181029
public void removeListeners(Integer count) {
10191030
// Keep: Required for RN built in Event Emitter Calls.
10201031
}
1021-
}
1032+
}

0 commit comments

Comments
 (0)