Skip to content

Commit

Permalink
Update useNFC
Browse files Browse the repository at this point in the history
  • Loading branch information
lucemans committed Oct 31, 2024
1 parent c6564e0 commit f74d588
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/hooks/useNFC.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,31 @@
import { useCallback, useEffect, useState } from 'react';
import { is_fully } from '../utils/is_fully';

export const useNFC = (config?:
{ onNdef: (serial: string, message: string, data: string) => void, onNfcTagDiscovered: (serial: string, type: string, message: string, data: string) => void, onNfcTagRemoved: (serial: string) => void }) => {
if (!is_fully()) {
return;
const preflight = () => {
if (!is_fully) {
alert('Fully not available');
throw new Error('Fully not available');
}
};

export const useNFC = (config?:
{ onNdef?: (serial: string, message: string, data: string) => void, onNfcTagDiscovered?: (serial: string, type: string, message: string, data: string) => void, onNfcTagRemoved?: (serial: string) => void }) => {
const [isScanning, setIsScanning] = useState(false);

const start = useCallback(() => {
preflight();
fully.nfcScanStart();
setIsScanning(true);
}, []);

const stop = useCallback(() => {
preflight();
fully.nfcScanStop();
setIsScanning(false);
}, []);

useEffect(() => {
preflight();
// @ts-ignore
window.onNdefDiscovered = (serial: string, message: string, data: string) => {
if (config?.onNdef) {
Expand Down

0 comments on commit f74d588

Please sign in to comment.