react-native-nfc-manager 4.0.0-beta.10 → 4.0.0-beta.11
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.
|
@@ -7,6 +7,7 @@ import android.nfc.NdefMessage;
|
|
|
7
7
|
import android.nfc.Tag;
|
|
8
8
|
import android.nfc.tech.Ndef;
|
|
9
9
|
import android.nfc.tech.NdefFormatable;
|
|
10
|
+
import android.nfc.tech.TagTechnology;
|
|
10
11
|
import android.os.Parcelable;
|
|
11
12
|
import android.util.Log;
|
|
12
13
|
|
|
@@ -16,6 +17,7 @@ import com.facebook.react.bridge.ReadableArray;
|
|
|
16
17
|
import com.facebook.react.bridge.ReadableMap;
|
|
17
18
|
import com.facebook.react.bridge.WritableMap;
|
|
18
19
|
|
|
20
|
+
import org.json.JSONArray;
|
|
19
21
|
import org.json.JSONException;
|
|
20
22
|
import org.json.JSONObject;
|
|
21
23
|
|
|
@@ -81,8 +83,19 @@ class NdefHandler {
|
|
|
81
83
|
}
|
|
82
84
|
|
|
83
85
|
try {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
+
TagTechnology techHandle = techRequest.getTechHandle();
|
|
87
|
+
if (!(techHandle instanceof Ndef)) {
|
|
88
|
+
callback.invoke(ERR_API_NOT_SUPPORT);
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
Ndef ndef = (Ndef) techHandle;
|
|
93
|
+
if (!ndef.isConnected()) {
|
|
94
|
+
callback.invoke(ERR_NO_TECH_REQ);
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
WritableMap parsed = ndefToReact(ndef, ndef.getNdefMessage());
|
|
86
99
|
callback.invoke(null, parsed);
|
|
87
100
|
} catch (Exception ex) {
|
|
88
101
|
Log.d(LOG_TAG, ex.toString());
|
|
@@ -316,6 +329,17 @@ class NdefHandler {
|
|
|
316
329
|
}
|
|
317
330
|
}
|
|
318
331
|
|
|
332
|
+
static WritableMap ndefToReact(Ndef ndef, NdefMessage message) {
|
|
333
|
+
try {
|
|
334
|
+
JSONObject json = Util.ndefToJSON(ndef);
|
|
335
|
+
json.put("ndefMessage", message == null ? new JSONArray() : Util.messageToJSON(message));
|
|
336
|
+
return Util.jsonToReact(json);
|
|
337
|
+
} catch (JSONException ex) {
|
|
338
|
+
Log.e(LOG_TAG, "Failed to convert ndef into json", ex);
|
|
339
|
+
return null;
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
|
|
319
343
|
static WritableMap ndefToReact(Tag tag, Parcelable[] messages) {
|
|
320
344
|
try {
|
|
321
345
|
Ndef ndef = tag != null ? Ndef.get(tag) : null;
|
package/dist/ndef-lib/util.js
CHANGED
|
@@ -23,8 +23,16 @@ function _utf8ArrayToStr(data) {
|
|
|
23
23
|
}
|
|
24
24
|
ch = (ch << 6) | (chx & 0x3f);
|
|
25
25
|
}
|
|
26
|
+
// A four-byte sequence can decode above the Unicode maximum, which is
|
|
27
|
+
// not a valid code point. Reject it like the other malformed cases
|
|
28
|
+
// rather than letting String.fromCodePoint throw a RangeError.
|
|
29
|
+
if (ch > 0x10ffff) {
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
26
32
|
}
|
|
27
|
-
|
|
33
|
+
// fromCharCode truncates to 16 bits, which silently corrupts anything
|
|
34
|
+
// outside the BMP: U+1F4A9 would come back as U+F4A9.
|
|
35
|
+
str += String.fromCodePoint(ch);
|
|
28
36
|
}
|
|
29
37
|
return str;
|
|
30
38
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"util.js","sourceRoot":"","sources":["../../ndef-lib/util.ts"],"names":[],"mappings":";AAAA,eAAe;AACf,6BAA6B;AAC7B,EAAE;;AAKF,4GAA4G;AAC5G,SAAS,eAAe,CAAC,IAAe;IACtC,MAAM,YAAY,GAAG,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,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,CAAC;SAC7B;QACD,gBAAgB,IAAI,SAAS,CAAC;KAC/B;IACD,OAAO,gBAAgB,CAAC;AAC1B,CAAC;AAED,mBAAmB;AACnB,SAAS,KAAK,CAAC,CAAS;IACtB,IAAI,GAAG,CAAC;IAER,IAAI,CAAC,GAAG,CAAC,EAAE;QACT,CAAC,IAAI,GAAG,CAAC;KACV;IACD,GAAG,GAAG,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;IAErB,eAAe;IACf,IAAI,GAAG,CAAC,MAAM,KAAK,CAAC,EAAE;QACpB,GAAG,GAAG,GAAG,GAAG,GAAG,CAAC;KACjB;IACD,OAAO,GAAG,CAAC;AACb,CAAC;AAED,SAAS,WAAW,CAAC,CAAS;IAC5B,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,IAAI,IAAI,EAAE;QAC1B,OAAO,MAAM,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;KAC/B;SAAM;QACL,OAAO,GAAG,CAAC;KACZ;AACH,CAAC;AAED,MAAM,CAAC,OAAO,GAAG;IACf,aAAa,EAAE,aAAa;IAC5B,aAAa,EAAE,aAAa;IAC5B,gBAAgB,EAAE,gBAAgB;IAClC,KAAK,EAAE,KAAK;IACZ,WAAW,EAAE,WAAW;CACzB,CAAC"}
|
package/ndef-lib/util.ts
CHANGED
|
@@ -28,9 +28,18 @@ function _utf8ArrayToStr(data: ByteArray): string | null {
|
|
|
28
28
|
|
|
29
29
|
ch = (ch << 6) | (chx & 0x3f);
|
|
30
30
|
}
|
|
31
|
+
|
|
32
|
+
// A four-byte sequence can decode above the Unicode maximum, which is
|
|
33
|
+
// not a valid code point. Reject it like the other malformed cases
|
|
34
|
+
// rather than letting String.fromCodePoint throw a RangeError.
|
|
35
|
+
if (ch > 0x10ffff) {
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
31
38
|
}
|
|
32
39
|
|
|
33
|
-
|
|
40
|
+
// fromCharCode truncates to 16 bits, which silently corrupts anything
|
|
41
|
+
// outside the BMP: U+1F4A9 would come back as U+F4A9.
|
|
42
|
+
str += String.fromCodePoint(ch);
|
|
34
43
|
}
|
|
35
44
|
|
|
36
45
|
return str;
|
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.11",
|
|
4
4
|
"description": "A NFC module for react native.",
|
|
5
5
|
"main": "dist/src/index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -39,17 +39,6 @@
|
|
|
39
39
|
"<rootDir>/example/"
|
|
40
40
|
]
|
|
41
41
|
},
|
|
42
|
-
"babel": {
|
|
43
|
-
"presets": [
|
|
44
|
-
"@babel/preset-env",
|
|
45
|
-
"@babel/preset-react",
|
|
46
|
-
"@babel/preset-typescript"
|
|
47
|
-
],
|
|
48
|
-
"plugins": [
|
|
49
|
-
"@babel/plugin-proposal-class-properties",
|
|
50
|
-
"@babel/plugin-transform-runtime"
|
|
51
|
-
]
|
|
52
|
-
},
|
|
53
42
|
"devDependencies": {
|
|
54
43
|
"@babel/core": "^7.12.10",
|
|
55
44
|
"@babel/plugin-proposal-class-properties": "^7.12.1",
|