@yudiel/react-qr-scanner
Advanced tools
Comparing version 1.2.2 to 1.2.3
@@ -19,3 +19,4 @@ import React from 'react'; | ||
hints?: Map<DecodeHintType, any>; | ||
stopDecoding?: boolean; | ||
} | ||
export declare const QrScanner: (props: QrScannerProps) => React.JSX.Element; |
@@ -11,2 +11,3 @@ /// <reference types="react" /> | ||
hints?: Map<DecodeHintType, any>; | ||
stopDecoding?: boolean; | ||
} | ||
@@ -16,3 +17,3 @@ export declare const useQrScanner: (props: IUseQrScannerProps) => { | ||
start: () => Promise<void>; | ||
stop: () => void; | ||
stop: boolean | undefined; | ||
}; |
@@ -19,3 +19,4 @@ import React from 'react'; | ||
hints?: Map<DecodeHintType, any>; | ||
stopDecoding?: boolean; | ||
} | ||
export declare const QrScanner: (props: QrScannerProps) => React.JSX.Element; |
@@ -11,2 +11,3 @@ /// <reference types="react" /> | ||
hints?: Map<DecodeHintType, any>; | ||
stopDecoding?: boolean; | ||
} | ||
@@ -16,3 +17,3 @@ export declare const useQrScanner: (props: IUseQrScannerProps) => { | ||
start: () => Promise<void>; | ||
stop: () => void; | ||
stop: boolean | undefined; | ||
}; |
@@ -21,2 +21,3 @@ import React, { CSSProperties, ReactElement } from 'react'; | ||
hints?: Map<DecodeHintType, any>; | ||
stopDecoding?: boolean; | ||
} | ||
@@ -23,0 +24,0 @@ declare const QrScanner: (props: QrScannerProps) => React.JSX.Element; |
{ | ||
"name": "@yudiel/react-qr-scanner", | ||
"version": "1.2.2", | ||
"version": "1.2.3", | ||
"description": "A library to scan qr codes in react.", | ||
@@ -5,0 +5,0 @@ "author": "Yudiel Curbelo", |
@@ -15,6 +15,7 @@ import { useEffect, useRef, useCallback, useState, useMemo } from 'react'; | ||
hints?: Map<DecodeHintType, any>; | ||
stopDecoding?: boolean; | ||
} | ||
export const useQrScanner = (props: IUseQrScannerProps) => { | ||
const { onResult, onError, scanDelay, hints, deviceId } = props; | ||
const { onResult, onError, scanDelay, hints, deviceId, stopDecoding } = props; | ||
@@ -35,3 +36,11 @@ const isMounted = useRef(false); | ||
const startDecoding = useCallback(async () => { | ||
const readerReset = useCallback(() => { | ||
reader.reset(); | ||
}, [reader]); | ||
const readerStop = useCallback(() => { | ||
reader.stopAsyncDecode(); | ||
}, [reader]); | ||
const readerStart = useCallback(async () => { | ||
if (!videoRef.current) return; | ||
@@ -55,14 +64,15 @@ | ||
const stopDecoding = useCallback(() => { | ||
reader.reset(); | ||
}, [reader]); | ||
useEffect(() => { | ||
isMounted.current = true; | ||
if (stopDecoding) { | ||
readerStop(); | ||
return; | ||
} | ||
(async () => { | ||
await startDecoding(); | ||
await readerStart(); | ||
if (!isMounted.current) { | ||
stopDecoding(); | ||
readerReset(); | ||
} | ||
@@ -73,6 +83,6 @@ })(); | ||
isMounted.current = false; | ||
stopDecoding(); | ||
readerReset(); | ||
}; | ||
}, [startDecoding, stopDecoding]); | ||
}, [readerStart, readerReset, stopDecoding]); | ||
useEffect(() => { | ||
@@ -94,3 +104,3 @@ const isEqual = deepEqual(props.constraints, constraints); | ||
return { ref: videoRef, start: startDecoding, stop: stopDecoding }; | ||
return { ref: videoRef, start: readerStart, stop: stopDecoding }; | ||
}; |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
4842544
3715