This package is a wrapper for react-native-nfc-manager, which streamlines and enhances common NFC read and write tasks with additional UI enhancements.
A React Native package that simplifies writing and reading data to and from NFC tags using react-native-nfc-manager. This package also provides an optional scan modal component for Android devices to enhance the user experience during NFC scanning.
- NFC Write: Write a list of strings to an NFC tag.
- NFC Read: Read a list of strings from an NFC tag.
- Install the package using npm or yarn:
npm install physikey-kit-react-native
# or
yarn add physikey-kit-react-native
- Install the peer dependencies react-native-nfc-manager:
npm install react-native-nfc-manager react-native-gzip
# or
yarn add react-native-nfc-manager react-native-gzip
- Follow the setup instructions for react-native-nfc-manager, including enabling NFC permissions on Android, as described in its documentation.
Use writeToCard to write an array of strings to an NFC tag. The function returns a promise that resolves to an object containing the status (success) and a message.
import { writeToCard } from 'physikey-kit-react-native';
const textList = ['Hello', 'World'];
const writeTextToCard = async () => {
try {
const result = await writeToCard(textList);
if (result.success) {
console.log('Write successful:', result.message);
} else {
console.log('Write failed:', result.message);
}
} catch (error) {
console.error('An error occurred:', error.message);
}
}
writeTextToCard();
Use readFromCard to read data from an NFC tag. The function returns a promise that resolves to an object containing the success status and the read contents as a list of strings (or an error message if unsuccessful).
import { readFromCard } from 'physikey-kit-react-native';
const readTextFromCard = async () => {
try {
const result = await readFromCard();
if (result.success) {
console.log('Read successful:', result.message);
} else {
console.log('Read failed:', result.message);
}
} catch (error) {
console.error('An error occurred:', error.message);
}
};
readTextFromCard();
This project is licensed under the ISC License.