Skip to content
This repository has been archived by the owner on Dec 1, 2023. It is now read-only.

Commit

Permalink
Avoid double insertions on Android
Browse files Browse the repository at this point in the history
  • Loading branch information
zoontek committed Mar 14, 2020
1 parent 3c87c4b commit fbd0768
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions android/src/main/java/com/zoontek/rndevmenu/RNDevMenuModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,16 @@
import com.facebook.react.devsupport.interfaces.DevSupportManager;
import com.facebook.react.modules.core.DeviceEventManagerModule.RCTDeviceEventEmitter;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Nullable;

public class RNDevMenuModule extends ReactContextBaseJavaModule {

@Nullable
private List<String> mNames;

public RNDevMenuModule(ReactApplicationContext reactContext) {
super(reactContext);
}
Expand All @@ -22,6 +30,13 @@ public String getName() {

@ReactMethod
public void addItem(final String name, Promise promise) {
if (mNames == null) {
mNames = new ArrayList<>();
}
if (mNames.contains(name)) {
promise.resolve(null);
}

try {
ReactApplication application = (ReactApplication)getReactApplicationContext()
.getCurrentActivity()
Expand All @@ -40,6 +55,7 @@ public void onOptionSelected() {
}
});

mNames.add(name);
promise.resolve(null);
} catch (Exception e) {
promise.reject(e);
Expand Down

0 comments on commit fbd0768

Please sign in to comment.