@spencerls/react-native-nfc 1.0.4 → 1.0.6

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/dist/index.d.ts CHANGED
@@ -1,10 +1,103 @@
1
1
  import * as react_native_nfc_manager from 'react-native-nfc-manager';
2
2
  import { TagEvent, NfcTech, NdefRecord } from 'react-native-nfc-manager';
3
+ import * as react_jsx_runtime from 'react/jsx-runtime';
4
+ import { PropsWithChildren } from 'react';
5
+
6
+ declare const operations$2: {
7
+ transceive(data: number[]): Promise<number[]>;
8
+ };
9
+
10
+ declare const utils$2: {};
11
+
12
+ declare namespace index$2 {
13
+ export { operations$2 as operations, utils$2 as utils };
14
+ }
3
15
 
4
16
  type StrictTagEvent = TagEvent & {
5
17
  id: string;
6
18
  };
7
19
 
20
+ declare const operations$1: {
21
+ withVTag<T>(handler: (tag: StrictTagEvent) => Promise<T>): Promise<T>;
22
+ writeBlockNfcV(blockNumber: number, data: Uint8Array): Promise<void>;
23
+ readBlockNfcV(blockNumber: number): Promise<Uint8Array<ArrayBufferLike>>;
24
+ getSystemInfoNfcV(): Promise<any>;
25
+ };
26
+
27
+ declare const utils$1: {
28
+ readonly tech: NfcTech.NfcV | NfcTech[];
29
+ readonly Flags: {
30
+ readonly HIGH_DATA_RATE: 2;
31
+ readonly ADDRESSED: 32;
32
+ };
33
+ readonly Commands: {
34
+ readonly READ_SINGLE_BLOCK: 32;
35
+ readonly WRITE_SINGLE_BLOCK: 33;
36
+ readonly GET_SYSTEM_INFO: 43;
37
+ };
38
+ /**
39
+ * Combine multiple flag bits into one byte.
40
+ * Example: Flags.ADDRESSED | Flags.HIGH_DATA_RATE
41
+ */
42
+ readonly flags: (...bits: number[]) => number;
43
+ /**
44
+ * Convert tag.id hex string (MSB->LSB) into reversed byte array (LSB->MSB)
45
+ * ISO15693 requires reversed UID for addressed commands.
46
+ */
47
+ readonly reverseUid: (tagIdHex: string) => number[];
48
+ /**
49
+ * Build READ_SINGLE_BLOCK command.
50
+ * FLAGS: addressed + high data rate by default.
51
+ */
52
+ readonly buildReadBlock: (uidReversed: number[], blockNumber: number) => number[];
53
+ /**
54
+ * Build WRITE_SINGLE_BLOCK command.
55
+ * Note: data must match the block size (usually 4 or 8 bytes).
56
+ */
57
+ readonly buildWriteBlock: (uidReversed: number[], blockNumber: number, data: Uint8Array) => number[];
58
+ /**
59
+ * Build GET_SYSTEM_INFO command.
60
+ */
61
+ readonly buildGetSystemInfo: (uidReversed: number[]) => number[];
62
+ /**
63
+ * Parse a READ_SINGLE_BLOCK response.
64
+ * Response format:
65
+ * - byte[0] = status (0x00 = success)
66
+ * - byte[1..] = block payload bytes
67
+ */
68
+ readonly parseReadResponse: (resp: number[]) => Uint8Array;
69
+ /**
70
+ * Parse WRITE_SINGLE_BLOCK response.
71
+ * Successful write has resp[0] === 0x00.
72
+ */
73
+ readonly parseWriteResponse: (resp: number[]) => void;
74
+ /**
75
+ * Parse GET_SYSTEM_INFO response.
76
+ * Returns: UID, DSFID, AFI, numberOfBlocks, blockSize, manufacturer
77
+ */
78
+ readonly parseSystemInfo: (resp: number[]) => any;
79
+ /** Identify common manufacturers based on UID prefix */
80
+ readonly detectManufacturer: (uid: string) => string;
81
+ };
82
+
83
+ declare namespace index$1 {
84
+ export { operations$1 as operations, utils$1 as utils };
85
+ }
86
+
87
+ declare const operations: {
88
+ writeNdef(records: NdefRecord[]): Promise<void>;
89
+ writeTextNdef(text: string): Promise<void>;
90
+ writeUriNdef(uri: string): Promise<void>;
91
+ };
92
+
93
+ declare const utils: {};
94
+
95
+ declare const index_operations: typeof operations;
96
+ declare const index_utils: typeof utils;
97
+ declare namespace index {
98
+ export { index_operations as operations, index_utils as utils };
99
+ }
100
+
8
101
  type NfcMode = "idle" | "starting" | "active" | "stopping" | "technology";
9
102
 
10
103
  interface NfcState {
@@ -16,12 +109,20 @@ type NfcListener = (state: NfcState) => void;
16
109
  declare class NfcService {
17
110
  private state;
18
111
  private listeners;
112
+ private isProcessingTag;
113
+ private currentOnTag?;
114
+ private currentCooldownMs;
115
+ private lastUsedReaderFlags;
19
116
  constructor();
20
117
  private setState;
21
118
  getState(): NfcState;
22
119
  subscribe(fn: NfcListener): () => void;
23
- startReader(readerModeFlags: number, onTag?: (tag: TagEvent) => void): Promise<void>;
120
+ startReader(readerModeFlags: number, onTag?: (tag: TagEvent) => Promise<void> | void, options?: {
121
+ cooldownMs?: number;
122
+ }): Promise<void>;
24
123
  stopReader(): Promise<void>;
124
+ private _resetReaderState;
125
+ private _restartIosReader;
25
126
  withTechnology<T>(tech: NfcTech | NfcTech[], handler: () => Promise<T>): Promise<T>;
26
127
  }
27
128
  declare const nfcService: NfcService;
@@ -77,95 +178,28 @@ declare const nfc: {
77
178
  };
78
179
  };
79
180
 
80
- declare const operations$2: {
81
- transceive(data: number[]): Promise<number[]>;
82
- };
83
-
84
- declare const utils$2: {};
85
-
86
- declare namespace index$2 {
87
- export { operations$2 as operations, utils$2 as utils };
181
+ interface NfcContextValue {
182
+ state: NfcState;
183
+ service: typeof nfcService;
88
184
  }
185
+ declare function NfcProvider({ children }: PropsWithChildren): react_jsx_runtime.JSX.Element;
186
+ declare function useNfcContext(): NfcContextValue;
89
187
 
90
- declare const operations$1: {
91
- writeNdef(records: NdefRecord[]): Promise<void>;
92
- writeTextNdef(text: string): Promise<void>;
93
- writeUriNdef(uri: string): Promise<void>;
94
- };
95
-
96
- declare const utils$1: {};
188
+ declare function useNfc(onTag: (tagId: string) => void, options: {
189
+ cooldownMs?: number;
190
+ flags: number;
191
+ }): void;
97
192
 
98
- declare namespace index$1 {
99
- export { operations$1 as operations, utils$1 as utils };
100
- }
101
-
102
- declare const operations: {
103
- withVTag<T>(handler: (tag: StrictTagEvent) => Promise<T>): Promise<T>;
104
- writeBlockNfcV(blockNumber: number, data: Uint8Array): Promise<void>;
105
- readBlockNfcV(blockNumber: number): Promise<Uint8Array<ArrayBufferLike>>;
106
- getSystemInfoNfcV(): Promise<any>;
193
+ declare function useNfcReader(): {
194
+ start: (flags: number, onTag: (tag: TagEvent) => void, cooldownMs?: number) => void;
195
+ stop: () => void;
107
196
  };
108
197
 
109
- declare const utils: {
110
- readonly tech: NfcTech.NfcV | NfcTech[];
111
- readonly Flags: {
112
- readonly HIGH_DATA_RATE: 2;
113
- readonly ADDRESSED: 32;
114
- };
115
- readonly Commands: {
116
- readonly READ_SINGLE_BLOCK: 32;
117
- readonly WRITE_SINGLE_BLOCK: 33;
118
- readonly GET_SYSTEM_INFO: 43;
119
- };
120
- /**
121
- * Combine multiple flag bits into one byte.
122
- * Example: Flags.ADDRESSED | Flags.HIGH_DATA_RATE
123
- */
124
- readonly flags: (...bits: number[]) => number;
125
- /**
126
- * Convert tag.id hex string (MSB->LSB) into reversed byte array (LSB->MSB)
127
- * ISO15693 requires reversed UID for addressed commands.
128
- */
129
- readonly reverseUid: (tagIdHex: string) => number[];
130
- /**
131
- * Build READ_SINGLE_BLOCK command.
132
- * FLAGS: addressed + high data rate by default.
133
- */
134
- readonly buildReadBlock: (uidReversed: number[], blockNumber: number) => number[];
135
- /**
136
- * Build WRITE_SINGLE_BLOCK command.
137
- * Note: data must match the block size (usually 4 or 8 bytes).
138
- */
139
- readonly buildWriteBlock: (uidReversed: number[], blockNumber: number, data: Uint8Array) => number[];
140
- /**
141
- * Build GET_SYSTEM_INFO command.
142
- */
143
- readonly buildGetSystemInfo: (uidReversed: number[]) => number[];
144
- /**
145
- * Parse a READ_SINGLE_BLOCK response.
146
- * Response format:
147
- * - byte[0] = status (0x00 = success)
148
- * - byte[1..] = block payload bytes
149
- */
150
- readonly parseReadResponse: (resp: number[]) => Uint8Array;
151
- /**
152
- * Parse WRITE_SINGLE_BLOCK response.
153
- * Successful write has resp[0] === 0x00.
154
- */
155
- readonly parseWriteResponse: (resp: number[]) => void;
156
- /**
157
- * Parse GET_SYSTEM_INFO response.
158
- * Returns: UID, DSFID, AFI, numberOfBlocks, blockSize, manufacturer
159
- */
160
- readonly parseSystemInfo: (resp: number[]) => any;
161
- /** Identify common manufacturers based on UID prefix */
162
- readonly detectManufacturer: (uid: string) => string;
163
- };
198
+ declare function useNfcState(): NfcState;
164
199
 
165
- declare const index_operations: typeof operations;
166
- declare const index_utils: typeof utils;
167
- declare namespace index {
168
- export { index_operations as operations, index_utils as utils };
169
- }
200
+ declare function useNfcTechnology(): {
201
+ writeNdef: (records: NdefRecord[]) => Promise<void>;
202
+ runWithTech: (tech: NfcTech | NfcTech[], fn: () => Promise<void>) => Promise<void>;
203
+ };
170
204
 
171
- export { type NfcMode, type NfcState, index$1 as ndef, nfc, index$2 as nfcA, nfcService, index as nfcV };
205
+ export { type NfcMode, NfcProvider, type NfcState, nfc, index$2 as nfcA, index as nfcNdef, nfcService, index$1 as nfcV, useNfc, useNfcContext, useNfcReader, useNfcState, useNfcTechnology };