Add nfc state events

This commit is contained in:
Roman Volosovskyi 2020-03-05 13:57:42 +02:00
parent 8fb12850d7
commit 38ca8597e2
No known key found for this signature in database
GPG Key ID: 0238A4B5ECEE70DE
2 changed files with 7 additions and 1 deletions

View File

@ -110,9 +110,13 @@ public class SmartCard extends BroadcastReceiver implements CardListener {
boolean on = false;
switch (state) {
case NfcAdapter.STATE_ON:
eventEmitter.emit("keyCardOnNFCEnabled", null);
log("NFC ON");
break;
case NfcAdapter.STATE_OFF:
eventEmitter.emit("keyCardOnNFCDisabled", null);
log("NFC OFF");
break;
default:
log("other");
}

View File

@ -11,10 +11,12 @@ import Keycard from "react-native-status-keycard";
```javascript
import { DeviceEventEmitter } from 'react-native';
// Listen to connect/disconnect events
// Listen to connect/disconnect and nfc events
componentDidMount () {
DeviceEventEmitter.addListener("keyCardOnConnected", () => console.log("keycard connected"));
DeviceEventEmitter.addListener("keyCardOnDisconnected", () => console.log("keycard disconnected"));
DeviceEventEmitter.addListener("keyCardOnNFCEnabled", () => console.log("nfc enabled"));
DeviceEventEmitter.addListener("keyCardOnNFCDisabled", () => console.log("nfc disabled"));
}
```