react-native-nfc-manager 3.17.1 → 3.17.3

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 (latest release is `v3.16.3`).
18
- - `v4` supports new architecture (still in beta, latest release is `v4.0.0-beta.4`) .
17
+ - `v3` only supports legacy architecture (`v3.x.y`).
18
+ - `v4` supports new architecture (`v4.0.0-beta.x`).
19
19
 
20
20
  ## Table of Contents
21
21
 
@@ -45,7 +45,6 @@ class NfcManager extends ReactContextBaseJavaModule implements ActivityEventList
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 Context 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 ReactContextBaseJavaModule implements ActivityEventList
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");
@@ -1010,12 +1008,13 @@ class NfcManager extends ReactContextBaseJavaModule implements ActivityEventList
1010
1008
 
1011
1009
  @ReactMethod
1012
1010
  public void start(Callback callback) {
1011
+ var context = getReactApplicationContext();
1013
1012
  NfcAdapter nfcAdapter = NfcAdapter.getDefaultAdapter(context);
1014
1013
  if (nfcAdapter != null) {
1015
1014
  Log.d(LOG_TAG, "start");
1016
1015
 
1017
1016
  IntentFilter filter = new IntentFilter(NfcAdapter.ACTION_ADAPTER_STATE_CHANGED);
1018
- Activity currentActivity = getCurrentActivity();
1017
+ Activity currentActivity = context.getCurrentActivity();
1019
1018
  if (currentActivity == null) {
1020
1019
  callback.invoke(ERR_GET_ACTIVITY_FAIL);
1021
1020
  return;
@@ -1035,7 +1034,7 @@ class NfcManager extends ReactContextBaseJavaModule implements ActivityEventList
1035
1034
  @ReactMethod
1036
1035
  public void isSupported(String tech, Callback callback){
1037
1036
  Log.d(LOG_TAG, "isSupported");
1038
- Activity currentActivity = getCurrentActivity();
1037
+ Activity currentActivity = getReactApplicationContext().getCurrentActivity();
1039
1038
  if (currentActivity == null) {
1040
1039
  callback.invoke(ERR_GET_ACTIVITY_FAIL);
1041
1040
  return;
@@ -1062,7 +1061,7 @@ class NfcManager extends ReactContextBaseJavaModule implements ActivityEventList
1062
1061
  @ReactMethod
1063
1062
  public void isEnabled(Callback callback) {
1064
1063
  Log.d(LOG_TAG, "isEnabled");
1065
- NfcAdapter nfcAdapter = NfcAdapter.getDefaultAdapter(context);
1064
+ NfcAdapter nfcAdapter = NfcAdapter.getDefaultAdapter(getReactApplicationContext());
1066
1065
  if (nfcAdapter != null) {
1067
1066
  callback.invoke(null, nfcAdapter.isEnabled());
1068
1067
  } else {
@@ -1073,7 +1072,7 @@ class NfcManager extends ReactContextBaseJavaModule implements ActivityEventList
1073
1072
  @ReactMethod
1074
1073
  public void goToNfcSetting(Callback callback) {
1075
1074
  Log.d(LOG_TAG, "goToNfcSetting");
1076
- Activity currentActivity = getCurrentActivity();
1075
+ Activity currentActivity = getReactApplicationContext().getCurrentActivity();
1077
1076
  if (currentActivity == null) {
1078
1077
  callback.invoke(ERR_GET_ACTIVITY_FAIL);
1079
1078
  return;
@@ -1089,7 +1088,7 @@ class NfcManager extends ReactContextBaseJavaModule implements ActivityEventList
1089
1088
 
1090
1089
  @ReactMethod
1091
1090
  public void getLaunchTagEvent(Callback callback) {
1092
- Activity currentActivity = getCurrentActivity();
1091
+ Activity currentActivity = getReactApplicationContext().getCurrentActivity();
1093
1092
  if (currentActivity == null) {
1094
1093
  callback.invoke(ERR_GET_ACTIVITY_FAIL);
1095
1094
  return;
@@ -1197,8 +1196,9 @@ class NfcManager extends ReactContextBaseJavaModule implements ActivityEventList
1197
1196
 
1198
1197
  private void enableDisableForegroundDispatch(boolean enable) {
1199
1198
  Log.i(LOG_TAG, "enableForegroundDispatch, enable = " + enable);
1199
+ var context = getReactApplicationContext();
1200
1200
  NfcAdapter nfcAdapter = NfcAdapter.getDefaultAdapter(context);
1201
- Activity currentActivity = getCurrentActivity();
1201
+ Activity currentActivity = context.getCurrentActivity();
1202
1202
  final NfcManager manager = this;
1203
1203
  if (nfcAdapter != null && currentActivity != null && !currentActivity.isFinishing()) {
1204
1204
  try {
@@ -1255,7 +1255,7 @@ class NfcManager extends ReactContextBaseJavaModule implements ActivityEventList
1255
1255
  }
1256
1256
 
1257
1257
  private PendingIntent getPendingIntent() {
1258
- Activity activity = getCurrentActivity();
1258
+ Activity activity = getReactApplicationContext().getCurrentActivity();
1259
1259
  assert activity != null;
1260
1260
  Intent intent = new Intent(activity, activity.getClass());
1261
1261
  intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
@@ -1288,7 +1288,7 @@ class NfcManager extends ReactContextBaseJavaModule implements ActivityEventList
1288
1288
  Log.d(LOG_TAG, "onReceive " + intent);
1289
1289
  final String action = intent.getAction();
1290
1290
 
1291
- if (action.equals(NfcAdapter.ACTION_ADAPTER_STATE_CHANGED)) {
1291
+ if (action != null && action.equals(NfcAdapter.ACTION_ADAPTER_STATE_CHANGED)) {
1292
1292
  final int state = intent.getIntExtra(NfcAdapter.EXTRA_ADAPTER_STATE,
1293
1293
  NfcAdapter.STATE_OFF);
1294
1294
  String stateStr = "unknown";
package/index.d.ts CHANGED
@@ -396,7 +396,7 @@ declare module 'react-native-nfc-manager' {
396
396
  isType(record: NdefRecord, tnf: TNF, type: string): boolean;
397
397
  stringify(data: number[], separator: string): string;
398
398
  encodeMessage(records: NdefRecord[]): number[];
399
- decodeMessage(bytes: number[]): NdefRecord[];
399
+ decodeMessage(bytes: number[] | Uint8Array): NdefRecord[];
400
400
  textRecord(text: string, lang?: ISOLangCode, encoding?: any): NdefRecord;
401
401
  uriRecord(uri: URI, id?: any): NdefRecord;
402
402
  wifiSimpleRecord(credentials: WifiSimpleCredentials, id?: any): NdefRecord;
@@ -29,6 +29,7 @@ RCT_EXPORT_METHOD(sendFelicaCommand:(NSArray *)bytes callback: (nonnull RCTRespo
29
29
  return;
30
30
  } else {
31
31
  callback(@[@"not a felica tag", [NSNull null]]);
32
+ return;
32
33
  }
33
34
  }
34
35
  callback(@[@"Not connected", [NSNull null]]);
@@ -28,6 +28,7 @@ RCT_EXPORT_METHOD(sendCommandAPDUBytes:(NSArray *)bytes callback: (nonnull RCTRe
28
28
  return;
29
29
  } else {
30
30
  callback(@[@"not an iso7816 tag", [NSNull null]]);
31
+ return;
31
32
  }
32
33
  }
33
34
  callback(@[@"Not connected", [NSNull null]]);
@@ -69,6 +70,7 @@ RCT_EXPORT_METHOD(sendCommandAPDU:(NSDictionary *)apduData callback: (nonnull RC
69
70
  return;
70
71
  } else {
71
72
  callback(@[@"not an iso7816 tag", [NSNull null]]);
73
+ return;
72
74
  }
73
75
  }
74
76
  callback(@[@"Not connected", [NSNull null]]);
@@ -29,6 +29,7 @@ RCT_EXPORT_METHOD(sendMifareCommand:(NSArray *)bytes callback: (nonnull RCTRespo
29
29
  return;
30
30
  } else {
31
31
  callback(@[@"not a mifare tag", [NSNull null]]);
32
+ return;
32
33
  }
33
34
  }
34
35
  callback(@[@"Not connected", [NSNull null]]);
package/ndef-lib/ndef.js CHANGED
@@ -126,15 +126,14 @@ function decodeNdefMessage(ndefBytes) {
126
126
 
127
127
  // ndefBytes can be an array of bytes e.g. [0x03, 0x31, 0xd1] or a Buffer
128
128
  let bytes;
129
- if (ndefBytes instanceof Array) {
130
- bytes = ndefBytes.slice(0);
129
+ if (Array.isArray(ndefBytes) || ndefBytes instanceof Uint8Array) {
130
+ bytes = Array.from(ndefBytes);
131
131
  } else {
132
132
  throw new Error(
133
- 'ndef.decodeMessage requires a Buffer or an Array of bytes',
133
+ 'ndef.decodeMessage requires a Buffer, Uint8Array, or an Array of bytes',
134
134
  );
135
135
  }
136
136
 
137
- bytes = bytes.slice(0); // clone since parsing is destructive
138
137
  let ndef_message = [],
139
138
  tnf_byte,
140
139
  header,
package/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "react-native-nfc-manager",
3
- "version": "3.17.1",
3
+ "version": "3.17.3",
4
4
  "description": "A NFC module for react native.",
5
5
  "main": "src/index.js",
6
6
  "repository": {
7
7
  "type": "git",
8
- "url": "https://github.com/whitedogg13/react-native-nfc-manager.git"
8
+ "url": "https://github.com/revtel/react-native-nfc-manager.git"
9
9
  },
10
10
  "bugs": {
11
- "url": "https://github.com/whitedogg13/react-native-nfc-manager/issues"
11
+ "url": "https://github.com/revtel/react-native-nfc-manager/issues"
12
12
  },
13
13
  "keywords": [
14
14
  "react-native",
@@ -74,6 +74,8 @@
74
74
  "lint": "eslint .",
75
75
  "lint:fix": "eslint --fix .",
76
76
  "test": "jest -i",
77
- "release": "dotenv -- release-it --"
77
+ "release": "dotenv -- release-it --",
78
+ "typecheck": "tsc --noEmit -p tsconfig.typecheck.json",
79
+ "test:publishing": "node --test scripts/trusted-publishing.test.cjs"
78
80
  }
79
81
  }