Skip to content

Commit

Permalink
chore: style amends and add a validation
Browse files Browse the repository at this point in the history
  • Loading branch information
tahmidrahman-dsi committed Nov 20, 2024
1 parent bda1f8f commit 952dbee
Showing 1 changed file with 21 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ const QRReader = styled.div`
}
`
const Video = styled.video`
width: 100%;
height: 100%;
width: 518px;
height: 518px;
object-fit: cover;
`

Expand All @@ -47,6 +47,14 @@ const QRFrame = styled.img`
top: 50%;
transform: translateX(-50%) translateY(-50%);
`
const withValidation = (callback: (data: any) => void) => {
return (data: any) => {
if (Boolean(data)) {
callback(data)
}
}
}

const Scanner2 = (props: ScannerProps) => {
const scanner = useRef<QRScanner>()
const videoElement = useRef<HTMLVideoElement>(null)
Expand All @@ -61,13 +69,17 @@ const Scanner2 = (props: ScannerProps) => {
useEffect(() => {
const currentVideoElement = videoElement?.current
if (currentVideoElement && !scanner.current) {
scanner.current = new QRScanner(currentVideoElement, onScanSuccess, {
onDecodeError: onScanFail,
preferredCamera: 'environment',
highlightCodeOutline: true,
highlightScanRegion: true,
overlay: qrBoxElement?.current || undefined
})
scanner.current = new QRScanner(
currentVideoElement,
withValidation(onScanSuccess),
{
onDecodeError: onScanFail,
preferredCamera: 'environment',
highlightCodeOutline: true,
highlightScanRegion: true,
overlay: qrBoxElement?.current || undefined
}
)

scanner?.current
?.start()
Expand Down

0 comments on commit 952dbee

Please sign in to comment.