1+
12package com .appsflyer .reactnative ;
23
34
5758
5859import static com .appsflyer .reactnative .RNAppsFlyerConstants .*;
5960import static com .appsflyer .reactnative .RNAppsFlyerConstants .afOnDeepLinking ;
60-
61+ import java . util . concurrent . atomic . AtomicBoolean ;
6162public 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