Skip to content

Commit

Permalink
use ArrayList to instead WritableArray to fix crash issues (#166)
Browse files Browse the repository at this point in the history
  • Loading branch information
tr3v3r authored Aug 6, 2024
1 parent 59a116f commit 22a59a2
Showing 1 changed file with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,22 @@

import com.reactnativeescposprinter.EposStringHelper;

import java.util.ArrayList;



@ReactModule(name = EscPosPrinterDiscoveryModule.NAME)
public class EscPosPrinterDiscoveryModule extends ReactContextBaseJavaModule implements ActivityEventListener {

private Context mContext;
private WritableArray mPrinterList = null;
private ArrayList<WritableMap> mPrinterList = null;
private final ReactApplicationContext reactContext;

public static final String NAME = "EscPosPrinterDiscovery";

public EscPosPrinterDiscoveryModule(ReactApplicationContext reactContext) {
super(reactContext);
mPrinterList = new ArrayList<WritableMap>();
this.reactContext = reactContext;
mContext = reactContext;
reactContext.addActivityEventListener(this);
Expand Down Expand Up @@ -155,7 +158,7 @@ private void sendEvent(ReactApplicationContext reactContext, String eventName, @
@ReactMethod
private void startDiscovery(final ReadableMap paramsMap, Promise promise) {
FilterOption mFilterOption = getFilterOptionsFromParams(paramsMap);
mPrinterList = Arguments.createArray();
mPrinterList.clear();

try {
Discovery.start(mContext, mFilterOption, mDiscoveryListener);
Expand Down Expand Up @@ -228,9 +231,9 @@ public synchronized void run() {
printerData.putString("macAddress", deviceInfo.getMacAddress());
printerData.putString("bdAddress", deviceInfo.getBdAddress());

mPrinterList.pushMap(printerData);
mPrinterList.add(printerData);

sendEvent(reactContext, "onDiscovery", mPrinterList);
sendEvent(reactContext, "onDiscovery", Arguments.fromList(mPrinterList));
}
});
}
Expand Down

0 comments on commit 22a59a2

Please sign in to comment.