Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use ArrayList to instead WritableArray to fix crash issues #166

Merged
merged 1 commit into from
Aug 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading