Esri / arcgis-maps-sdk-dotnet-toolkit

Toolkit for ArcGIS Maps SDK for .NET
https://esri.github.io/arcgis-maps-sdk-dotnet-toolkit/
Apache License 2.0
211 stars 121 forks source link

Adds support for the barcode input field #583

Closed dotMorten closed 2 months ago

dotMorten commented 2 months ago

Allows rendering the new BarcodeScannerInputField. This is just the text field, but with a QR code icon button users can click. At this point of implementation, no default action happens clicking this, but users can react to the BarcodeButtonClicked event on the FeatureForm and use for instance ZXing to launch a barcode scanner.

    private async void FeatureFormView_BarcodeButtonClicked(object sender, BarcodeButtonClickedEventArgs e)
    {
        try {
            e.FormElement.UpdateValue(await GetBarcodeScan());
        } catch {}
    }

Here's an example using ZXing in .NET MAUI (see configuration steps for how to use zxing):

        private async void BarcodeButtonClicked(object sender, Esri.ArcGISRuntime.Toolkit.Maui.BarcodeButtonClickedEventArgs e)
        {
            ZXing.Net.Maui.Controls.CameraBarcodeReaderView view = new ZXing.Net.Maui.Controls.CameraBarcodeReaderView();
            TaskCompletionSource<string?> tcs = new TaskCompletionSource<string?>();
            view.BarcodesDetected += (s, e) =>
            {
                tcs.TrySetResult(e.Results.FirstOrDefault()?.Value);
                _ = Navigation.PopModalAsync();
            };
            ContentPage p = new ContentPage() { Content = view };
            await Navigation.PushModalAsync(p);
            p.NavigatedFrom += (s, e) => tcs.TrySetResult(null);
            var barcode = await tcs.Task;
            if(!string.IsNullOrEmpty(barcode))
            {
                e.FormElement.UpdateValue(barcode);
            }
       }