Redth / ZXing.Net.Maui

Barcode Scanning for MAUI?
MIT License
451 stars 148 forks source link

HeightRequest will be ignored #191

Open GFI-acadon opened 1 month ago

GFI-acadon commented 1 month ago

We use CameraBarcodeReaderView like so:

<zxing:CameraBarcodeReaderView x:Name="ScanView"
                        MaximumHeightRequest="{Binding ScannerViewHeightRequest, Source={Reference SearchView}}"
                        HeightRequest="{Binding ScannerViewHeightRequest, Source={Reference SearchView}}"
                        IsDetecting="{Binding IsDetecting, Source={Reference SearchView}}"
                        IsTorchOn="{Binding IsTorchOn, Source={Reference SearchView}, FallbackValue=true}"
                        CameraLocation="Rear"
                        BarcodesDetected="ScanView_OnBarcodesDetected"
                        SizeChanged="ScanView_SizeChanged"/>

When the page is opened, the view size is respected for a brief moment, but then it jumps to 640x480. I suspect that I found the code in:

namespace ZXing.Net.Maui
{
    internal partial class CameraManager
...
                imageAnalyzer = new ImageAnalysis.Builder()
                    .SetDefaultResolution(new Android.Util.Size(**640, 480**))
                    .SetBackpressureStrategy(ImageAnalysis.StrategyKeepOnlyLatest)
                    .Build();

A possible solution could be:

        public NativePlatformCameraPreviewView CreateNativeView()
        {
            previewView = new PreviewView(Context.Context);
            **previewView.SetScaleType(PreviewView.ScaleType.FitCenter); <-- added**
            cameraExecutor = Executors.NewSingleThreadExecutor();

            return previewView;
        }

However, the size remains the same, and we get black areas on the sides (which is acceptable for now).

czuck commented 1 month ago

Having a similar issue. In the Forms version the BarcodeReader was displayed in the upper half of my view and the previous results was in the bottom half. With the MAUI version the reader takes up about 5/7 of the view on Android and I can't resize it. The zxing CameraView has the same sizing issue on Android. I can resize the barcode reader on iOS, and I can resize the CommunityToolkit Camera View on Android.

czuck commented 1 month ago

My workaround is to set the ZIndex of the CameraBarCodeReaderView to 0, then I can see the other elements on the page.