golto4
golto4

Reputation: 43

Zxing barcode scanner continious scanning problem

I'm using Zxing barcode scanner and Rg Pop up pages in Xamarin forms. The whole idea is that when the camera catches a barcode it displays a pop up. The problem is that I want to wait for the user to close the pop up before it scans again. Now if I keep the camera towards a barcode it keeps showing multiple alerts.

public async void Scan(Result result)
        {
            //random linq to get product
            if (product != null)
            {
                await PopupNavigation.PushAsync(new DisplayDialog(product));
            }          
        }

Method for when user closes the window

private async void Button_OnClicked(object sender, EventArgs e)
        {
            await PopupNavigation.RemovePageAsync(this);
        }

I tried using a flag to stop the scan and setting isScanning or isAnalyzing to false but it didnt work. Any ideas? Thank you!

Upvotes: 2

Views: 815

Answers (1)

Jason
Jason

Reputation: 89117

use a bool to control the flow

bool popup = false;

public async void Scan(Result result)
    {
        if (popup) return;

        //random linq to get product
        if (product != null)
        {
            popup = true;
            await PopupNavigation.PushAsync(new DisplayDialog(product));
        }          
    }

then whenever your popup is dismissed, reset the popup flag to false

Upvotes: 1

Related Questions