|
| 1 | +using DIPS.Mobile.UI.API.Camera; |
| 2 | +using DIPS.Mobile.UI.API.Camera.BarcodeScanning; |
| 3 | +using Colors = Microsoft.Maui.Graphics.Colors; |
| 4 | + |
| 5 | +namespace Playground.VetleSamples; |
| 6 | + |
| 7 | +/// <summary> |
| 8 | +/// Repro: Android's GraphicsView overlay spans the entire top and bottom toolbar. |
| 9 | +/// Open this page modally with a NavigationPage wrapper and observe the overlay |
| 10 | +/// extending behind the navigation bar and bottom safe area on Android. |
| 11 | +/// </summary> |
| 12 | +public partial class BarcodeOverlayToolbarRepro |
| 13 | +{ |
| 14 | + private readonly BarcodeScanner m_barcodeScanner; |
| 15 | + |
| 16 | + public BarcodeOverlayToolbarRepro() |
| 17 | + { |
| 18 | + InitializeComponent(); |
| 19 | + m_barcodeScanner = new BarcodeScanner(); |
| 20 | + } |
| 21 | + |
| 22 | + private async Task Start() |
| 23 | + { |
| 24 | + try |
| 25 | + { |
| 26 | + await m_barcodeScanner.Start(new BarcodeScannerStartOptions |
| 27 | + { |
| 28 | + Preview = CameraPreview, |
| 29 | + OnCameraFailed = CameraFailed, |
| 30 | + OnBarcodeAcceptedAsync = HandleBarcodeAcceptedAsync, |
| 31 | + Strategy = new ScanRectangleBarcodeScanStrategy |
| 32 | + { |
| 33 | + WidthFraction = 0.8f, |
| 34 | + HeightFraction = 0.3f |
| 35 | + } |
| 36 | + }); |
| 37 | + |
| 38 | + CameraPreview.AddTopToolbarView(new BoxView |
| 39 | + { |
| 40 | + Color = Colors.White, |
| 41 | + HeightRequest = 50, |
| 42 | + WidthRequest = 200, |
| 43 | + HorizontalOptions = LayoutOptions.Center |
| 44 | + }); |
| 45 | + CameraPreview.AddBottomToolbarView(CreateCloseButton()); |
| 46 | + } |
| 47 | + catch (Exception exception) |
| 48 | + { |
| 49 | + Console.WriteLine(exception); |
| 50 | + } |
| 51 | + } |
| 52 | + |
| 53 | + private void CameraFailed(CameraException e) |
| 54 | + { |
| 55 | + Console.WriteLine($"Camera failed: {e.Message}"); |
| 56 | + } |
| 57 | + |
| 58 | + private Task HandleBarcodeAcceptedAsync(BarcodeScanResult barcodeScanResult) |
| 59 | + { |
| 60 | + return Task.CompletedTask; |
| 61 | + } |
| 62 | + |
| 63 | + protected override void OnAppearing() |
| 64 | + { |
| 65 | + _ = Start(); |
| 66 | + base.OnAppearing(); |
| 67 | + } |
| 68 | + |
| 69 | + private void Close() |
| 70 | + { |
| 71 | + m_barcodeScanner.StopAndDispose(); |
| 72 | + Shell.Current.Navigation.PopModalAsync(); |
| 73 | + } |
| 74 | + |
| 75 | + private void Close(object? sender, EventArgs e) => Close(); |
| 76 | + |
| 77 | + private Button CreateCloseButton() |
| 78 | + { |
| 79 | + var button = new Button |
| 80 | + { |
| 81 | + Text = "Close", |
| 82 | + TextColor = Colors.White, |
| 83 | + BackgroundColor = Colors.Transparent, |
| 84 | + HorizontalOptions = LayoutOptions.Center |
| 85 | + }; |
| 86 | + button.Clicked += (_, _) => Close(); |
| 87 | + return button; |
| 88 | + } |
| 89 | +} |
0 commit comments