Skip to content

Commit

Permalink
align android and ios behaviour regarding startNFC/stopNFC
Browse files Browse the repository at this point in the history
  • Loading branch information
bitgamma committed Oct 1, 2024
1 parent 7da38ff commit b14e9f0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -515,17 +515,19 @@ public void run() {
}).start();
}

// These three methods below are a nop on Android since NFC is always listening and we have a custom UI. They are needed in iOS to show the NFC dialog
@ReactMethod
public void startNFC(String prompt, final Promise promise) {
smartCard.startNFC();
promise.resolve(true);
}

@ReactMethod
public void stopNFC(String error, final Promise promise) {
smartCard.stopNFC();
promise.resolve(true);
}

// Only used on iOS
@ReactMethod
public void setNFCMessage(String message, final Promise promise) {
promise.resolve(true);
Expand Down
23 changes: 21 additions & 2 deletions android/src/main/java/im/status/ethereum/keycard/SmartCard.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public class SmartCard extends BroadcastReceiver implements CardListener {
private EventEmitter eventEmitter;
private static final String TAG = "SmartCard";
private Boolean started = false;
private Boolean listening = false;
private HashMap<String, String> pairings;

private static final String MASTER_PATH = "m";
Expand Down Expand Up @@ -102,15 +103,33 @@ public void stop(Activity activity) {
}
}

public void startNFC() {
this.listening = true;
if (this.cardChannel != null) {
eventEmitter.emit("keyCardOnConnected", null);
}
}

public void stopNFC() {
this.listening = false;
}

@Override
public void onConnected(final CardChannel channel) {
this.cardChannel = channel;
eventEmitter.emit("keyCardOnConnected", null);

if (this.listening) {
eventEmitter.emit("keyCardOnConnected", null);
}
}

@Override
public void onDisconnected() {
eventEmitter.emit("keyCardOnDisconnected", null);
this.cardChannel = null;

if (this.listening) {
eventEmitter.emit("keyCardOnDisconnected", null);
}
}

@Override
Expand Down

0 comments on commit b14e9f0

Please sign in to comment.