Exemplo n.º 1
0
        public static void ScanContinuously(
            string message,
            QRCodeScanned onQrCodeScannedFunction,
            TaskCompletionSource <bool> taskCompletionSource,
            string closeButtonTitle,
            bool tryInverted)
        {
            var scanner     = new QrCodeScanner();
            var overlayView = ScanQrOverlayView.Create(scanner);

            scanner.CustomOverlay = overlayView;
            overlayView.SetCancelButtonText(closeButtonTitle);
            overlayView.SetDescriptionText(message);
            var position = 0;

            var isScanningContinouslyExecuting = false;

            scanner.ScanContinuously(new MobileBarcodeScanningOptions()
            {
                DelayBetweenContinuousScans = 3000,
                TryInverted = tryInverted
            }, async result =>
            {
                if (isScanningContinouslyExecuting)
                {
                    return;
                }
                isScanningContinouslyExecuting = true;

                var scanQrUpdate = await onQrCodeScannedFunction.Invoke(position, result.Text);

                if (scanQrUpdate == null)
                {
                    return;
                }

                if (scanQrUpdate.WillCancel)
                {
                    taskCompletionSource.SetResult(true);
                    taskCompletionSource = null;
                    scanner.Cancel();
                    return;
                }

                overlayView.SetDescriptionText(scanQrUpdate.UpdateMessage);
                position++;
                isScanningContinouslyExecuting = false;
            });
        }
Exemplo n.º 2
0
 partial void OnCancelButton(UIButton sender)
 {
     _scanner.Cancel();
 }