react-native-nfc-manager 4.0.0-beta.5 → 4.0.0-beta.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
|
@@ -14,8 +14,8 @@ Made with ❤️ by [whitedogg13](https://github.com/whitedogg13) and [revteltec
|
|
|
14
14
|
|
|
15
15
|
## Version Notes
|
|
16
16
|
|
|
17
|
-
- `v3` only supports legacy architecture (
|
|
18
|
-
- `v4` supports new architecture (still in beta,
|
|
17
|
+
- `v3` only supports legacy architecture (`v3.x.y`).
|
|
18
|
+
- `v4` supports new architecture (still in beta, `v4.0.0-beta.x`) .
|
|
19
19
|
|
|
20
20
|
## Table of Contents
|
|
21
21
|
|
|
@@ -45,7 +45,6 @@ class NfcManager extends NativeNfcManagerSpec implements ActivityEventListener,
|
|
|
45
45
|
private static final String LOG_TAG = "ReactNativeNfcManager";
|
|
46
46
|
private final List<IntentFilter> intentFilters = new ArrayList<>();
|
|
47
47
|
private final ArrayList<String[]> techLists = new ArrayList<>();
|
|
48
|
-
private final ReactApplicationContext context;
|
|
49
48
|
private Boolean isForegroundEnabled = false;
|
|
50
49
|
private Boolean isResumed = false;
|
|
51
50
|
private WriteNdefRequest writeNdefRequest = null;
|
|
@@ -82,7 +81,6 @@ class NfcManager extends NativeNfcManagerSpec implements ActivityEventListener,
|
|
|
82
81
|
|
|
83
82
|
public NfcManager(ReactApplicationContext reactContext) {
|
|
84
83
|
super(reactContext);
|
|
85
|
-
context = reactContext;
|
|
86
84
|
reactContext.addActivityEventListener(this);
|
|
87
85
|
reactContext.addLifecycleEventListener(this);
|
|
88
86
|
Log.d(LOG_TAG, "NfcManager created");
|
|
@@ -788,6 +786,59 @@ class NfcManager extends NativeNfcManagerSpec implements ActivityEventListener,
|
|
|
788
786
|
}
|
|
789
787
|
}
|
|
790
788
|
|
|
789
|
+
@ReactMethod
|
|
790
|
+
public void getTimeout(Callback callback) {
|
|
791
|
+
synchronized (this) {
|
|
792
|
+
if (techRequest != null) {
|
|
793
|
+
try {
|
|
794
|
+
String tech = techRequest.getTechType();
|
|
795
|
+
TagTechnology baseTechHandle = techRequest.getTechHandle();
|
|
796
|
+
// TagTechnology is the base class for each tech (ex, NfcA, NfcB, IsoDep ...)
|
|
797
|
+
// but it doesn't provide transceive in its interface, so we need to explicitly cast it
|
|
798
|
+
switch (tech) {
|
|
799
|
+
case "NfcA": {
|
|
800
|
+
NfcA techHandle = (NfcA) baseTechHandle;
|
|
801
|
+
int timeout = techHandle.getTimeout();
|
|
802
|
+
callback.invoke(null, timeout);
|
|
803
|
+
return;
|
|
804
|
+
}
|
|
805
|
+
case "NfcF": {
|
|
806
|
+
NfcF techHandle = (NfcF) baseTechHandle;
|
|
807
|
+
int timeout = techHandle.getTimeout();
|
|
808
|
+
callback.invoke(null, timeout);
|
|
809
|
+
return;
|
|
810
|
+
}
|
|
811
|
+
case "IsoDep": {
|
|
812
|
+
IsoDep techHandle = (IsoDep) baseTechHandle;
|
|
813
|
+
int timeout = techHandle.getTimeout();
|
|
814
|
+
callback.invoke(null, timeout);
|
|
815
|
+
return;
|
|
816
|
+
}
|
|
817
|
+
case "MifareClassic": {
|
|
818
|
+
MifareClassic techHandle = (MifareClassic) baseTechHandle;
|
|
819
|
+
int timeout = techHandle.getTimeout();
|
|
820
|
+
callback.invoke(null, timeout);
|
|
821
|
+
return;
|
|
822
|
+
}
|
|
823
|
+
case "MifareUltralight": {
|
|
824
|
+
MifareUltralight techHandle = (MifareUltralight) baseTechHandle;
|
|
825
|
+
int timeout = techHandle.getTimeout();
|
|
826
|
+
callback.invoke(null, timeout);
|
|
827
|
+
return;
|
|
828
|
+
}
|
|
829
|
+
}
|
|
830
|
+
Log.d(LOG_TAG, "getTimeout not supported");
|
|
831
|
+
callback.invoke(ERR_API_NOT_SUPPORT);
|
|
832
|
+
} catch (Exception ex) {
|
|
833
|
+
Log.d(LOG_TAG, ex.toString());
|
|
834
|
+
callback.invoke(ex.toString());
|
|
835
|
+
}
|
|
836
|
+
} else {
|
|
837
|
+
callback.invoke(ERR_NO_TECH_REQ);
|
|
838
|
+
}
|
|
839
|
+
}
|
|
840
|
+
}
|
|
841
|
+
|
|
791
842
|
@ReactMethod
|
|
792
843
|
public void connect(ReadableArray techs, Callback callback){
|
|
793
844
|
synchronized(this) {
|
|
@@ -1002,6 +1053,7 @@ class NfcManager extends NativeNfcManagerSpec implements ActivityEventListener,
|
|
|
1002
1053
|
|
|
1003
1054
|
@ReactMethod
|
|
1004
1055
|
public void start(Callback callback) {
|
|
1056
|
+
var context = getReactApplicationContext();
|
|
1005
1057
|
NfcAdapter nfcAdapter = NfcAdapter.getDefaultAdapter(context);
|
|
1006
1058
|
if (nfcAdapter != null) {
|
|
1007
1059
|
Log.d(LOG_TAG, "start");
|
|
@@ -1027,7 +1079,7 @@ class NfcManager extends NativeNfcManagerSpec implements ActivityEventListener,
|
|
|
1027
1079
|
@ReactMethod
|
|
1028
1080
|
public void isSupported(String tech, Callback callback){
|
|
1029
1081
|
Log.d(LOG_TAG, "isSupported");
|
|
1030
|
-
Activity currentActivity =
|
|
1082
|
+
Activity currentActivity = getReactApplicationContext().getCurrentActivity();
|
|
1031
1083
|
if (currentActivity == null) {
|
|
1032
1084
|
callback.invoke(ERR_GET_ACTIVITY_FAIL);
|
|
1033
1085
|
return;
|
|
@@ -1054,7 +1106,7 @@ class NfcManager extends NativeNfcManagerSpec implements ActivityEventListener,
|
|
|
1054
1106
|
@ReactMethod
|
|
1055
1107
|
public void isEnabled(Callback callback) {
|
|
1056
1108
|
Log.d(LOG_TAG, "isEnabled");
|
|
1057
|
-
NfcAdapter nfcAdapter = NfcAdapter.getDefaultAdapter(
|
|
1109
|
+
NfcAdapter nfcAdapter = NfcAdapter.getDefaultAdapter(getReactApplicationContext());
|
|
1058
1110
|
if (nfcAdapter != null) {
|
|
1059
1111
|
callback.invoke(null, nfcAdapter.isEnabled());
|
|
1060
1112
|
} else {
|
|
@@ -1065,7 +1117,7 @@ class NfcManager extends NativeNfcManagerSpec implements ActivityEventListener,
|
|
|
1065
1117
|
@ReactMethod
|
|
1066
1118
|
public void goToNfcSetting(Callback callback) {
|
|
1067
1119
|
Log.d(LOG_TAG, "goToNfcSetting");
|
|
1068
|
-
Activity currentActivity =
|
|
1120
|
+
Activity currentActivity = getReactApplicationContext().getCurrentActivity();
|
|
1069
1121
|
if (currentActivity == null) {
|
|
1070
1122
|
callback.invoke(ERR_GET_ACTIVITY_FAIL);
|
|
1071
1123
|
return;
|
|
@@ -1081,7 +1133,7 @@ class NfcManager extends NativeNfcManagerSpec implements ActivityEventListener,
|
|
|
1081
1133
|
|
|
1082
1134
|
@ReactMethod
|
|
1083
1135
|
public void getLaunchTagEvent(Callback callback) {
|
|
1084
|
-
Activity currentActivity =
|
|
1136
|
+
Activity currentActivity = getReactApplicationContext().getCurrentActivity();
|
|
1085
1137
|
if (currentActivity == null) {
|
|
1086
1138
|
callback.invoke(ERR_GET_ACTIVITY_FAIL);
|
|
1087
1139
|
return;
|
|
@@ -1296,6 +1348,7 @@ class NfcManager extends NativeNfcManagerSpec implements ActivityEventListener,
|
|
|
1296
1348
|
|
|
1297
1349
|
private void enableDisableForegroundDispatch(boolean enable) {
|
|
1298
1350
|
Log.i(LOG_TAG, "enableForegroundDispatch, enable = " + enable);
|
|
1351
|
+
var context = getReactApplicationContext();
|
|
1299
1352
|
NfcAdapter nfcAdapter = NfcAdapter.getDefaultAdapter(context);
|
|
1300
1353
|
Activity currentActivity = context.getCurrentActivity();
|
|
1301
1354
|
final NfcManager manager = this;
|
|
@@ -1354,7 +1407,7 @@ class NfcManager extends NativeNfcManagerSpec implements ActivityEventListener,
|
|
|
1354
1407
|
}
|
|
1355
1408
|
|
|
1356
1409
|
private PendingIntent getPendingIntent() {
|
|
1357
|
-
Activity activity =
|
|
1410
|
+
Activity activity = getReactApplicationContext().getCurrentActivity();
|
|
1358
1411
|
assert activity != null;
|
|
1359
1412
|
Intent intent = new Intent(activity, activity.getClass());
|
|
1360
1413
|
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
|
@@ -1387,7 +1440,7 @@ class NfcManager extends NativeNfcManagerSpec implements ActivityEventListener,
|
|
|
1387
1440
|
Log.d(LOG_TAG, "onReceive " + intent);
|
|
1388
1441
|
final String action = intent.getAction();
|
|
1389
1442
|
|
|
1390
|
-
if (action.equals(NfcAdapter.ACTION_ADAPTER_STATE_CHANGED)) {
|
|
1443
|
+
if (action != null && action.equals(NfcAdapter.ACTION_ADAPTER_STATE_CHANGED)) {
|
|
1391
1444
|
final int state = intent.getIntExtra(NfcAdapter.EXTRA_ADAPTER_STATE,
|
|
1392
1445
|
NfcAdapter.STATE_OFF);
|
|
1393
1446
|
String stateStr = "unknown";
|
package/index.d.ts
CHANGED
|
@@ -284,6 +284,7 @@ declare module 'react-native-nfc-manager' {
|
|
|
284
284
|
transceive(bytes: number[]): Promise<number[]>;
|
|
285
285
|
getMaxTransceiveLength(): Promise<number>;
|
|
286
286
|
setTimeout(timeout: number): Promise<void>;
|
|
287
|
+
getTimeout(): Promise<number|void>;
|
|
287
288
|
connect: (techs: NfcTech[]) => Promise<void>;
|
|
288
289
|
close: () => Promise<void>;
|
|
289
290
|
mifareClassicHandlerAndroid: MifareClassicHandlerAndroid;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-nfc-manager",
|
|
3
|
-
"version": "4.0.0-beta.
|
|
3
|
+
"version": "4.0.0-beta.7",
|
|
4
4
|
"description": "A NFC module for react native.",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"repository": {
|
|
@@ -64,7 +64,7 @@
|
|
|
64
64
|
"typescript": "^4.1.3"
|
|
65
65
|
},
|
|
66
66
|
"peerDependencies": {
|
|
67
|
-
"@expo/config-plugins": "
|
|
67
|
+
"@expo/config-plugins": "*"
|
|
68
68
|
},
|
|
69
69
|
"peerDependenciesMeta": {
|
|
70
70
|
"@expo/config-plugins": {
|
|
@@ -57,6 +57,7 @@ export interface Spec extends TurboModule {
|
|
|
57
57
|
goToNfcSetting(callback: (err?: string) => void): void;
|
|
58
58
|
getLaunchTagEvent(callback: (err?: string, tag?: Object) => void): void;
|
|
59
59
|
setTimeout(timeout: number, callback: (err?: string, tag?: Object) => void): void;
|
|
60
|
+
getTimeout(callback: (err?: string, timeout?: number) => void): void;
|
|
60
61
|
connect(techs: string[], callback: (err?: string) => void): void;
|
|
61
62
|
close(callback: (err?: string) => void): void;
|
|
62
63
|
transceive(bytes: number[], callback: (err?: string, bytes?: number[]) => void): void;
|
package/src/NfcManager.js
CHANGED
package/src/NfcManagerAndroid.js
CHANGED
|
@@ -84,6 +84,8 @@ class NfcManagerAndroid extends NfcManagerBase {
|
|
|
84
84
|
setTimeout = (timeout) =>
|
|
85
85
|
handleNativeException(callNative('setTimeout', [timeout]));
|
|
86
86
|
|
|
87
|
+
getTimeout = () => handleNativeException(callNative('getTimeout'));
|
|
88
|
+
|
|
87
89
|
connect = (techs) => handleNativeException(callNative('connect', [techs]));
|
|
88
90
|
|
|
89
91
|
close = () => handleNativeException(callNative('close'));
|