Skip to content

Commit

Permalink
Add overlay qr scanner
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitry-bym committed Dec 4, 2023
1 parent 3ccd3a1 commit e3ee361
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
[Parameter]
public EventCallback WhenInitialized { get; set; }

[Parameter]
public ElementReference Overlay { get; set; }

private IJSObjectReference? _qrScanner;

private ElementReference _videoTagReference;
Expand All @@ -24,7 +27,7 @@
{
if (firstRender)
{
_qrScanner = await QrScannerInterop.CreateQrScannerInstance(_videoTagReference, OnResult.InvokeAsync);
_qrScanner = await QrScannerInterop.CreateQrScannerInstance(_videoTagReference, Overlay, OnResult.InvokeAsync);
await WhenInitialized.InvokeAsync();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ internal class QrScannerJsInterop : BaseJsInterop
public QrScannerJsInterop(IJSRuntime jsRuntime) : base(jsRuntime, QrScannerInteropPath)
{ }

public async ValueTask<IJSObjectReference> CreateQrScannerInstance(ElementReference videoElementReference, Func<string, Task> onSuccessScanning)
public async ValueTask<IJSObjectReference> CreateQrScannerInstance(ElementReference videoElementReference, ElementReference overlayReference, Func<string, Task> onSuccessScanning)
{
var module = await EnsureModuleImported();
var handler = JsHandlerFactory.AsyncCallbackHandler(onSuccessScanning);
return await module.InvokeAsync<IJSObjectReference>("createQrScanner", videoElementReference, handler);
return await module.InvokeAsync<IJSObjectReference>("createQrScanner", videoElementReference, overlayReference, handler);
}

public async ValueTask StartScanning(IJSObjectReference qrScannerReference)
Expand Down
8 changes: 6 additions & 2 deletions src/GenOne.Blazor.QrScanner/src/wwwroot/qr-scanner-interop.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import "./qr-scanner-worker.min.js"
import QrScanner from "./qr-scanner.min.js"

export function createQrScanner(videoElem, successfulScanHandler) {
export function createQrScanner(videoElem, overlay, successfulScanHandler) {
var scanner = new QrScanner(
videoElem,
result => callback(successfulScanHandler, result),
{ returnDetailedScanResult: true, highlightScanRegion: true }
{
returnDetailedScanResult: true,
highlightScanRegion: true,
overlay = overlay || undefined
}
);

scanner.setInversionMode('both');
Expand Down

0 comments on commit e3ee361

Please sign in to comment.