Skip to content

Commit 7523c04

Browse files
Vetle444Vetle Finstadclaude
authored
Refactor barcode scanner; fix detection not resuming after pause (#870)
Co-authored-by: Vetle Finstad <finstad@Vetles-MacBook-Pro-2.local> Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
1 parent 868f457 commit 7523c04

39 files changed

Lines changed: 889 additions & 755 deletions

CHANGELOG.md

Lines changed: 251 additions & 246 deletions
Large diffs are not rendered by default.

src/app/Components/ComponentsSamples/BarcodeScanning/BarcodeCounterSample.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@
1010
<ToolbarItem IconImageSource="{dui:Icons close_line}"
1111
Clicked="Close" />
1212
</dui:ContentPage.ToolbarItems>
13-
<dui:CameraPreview x:Name="CameraPreview" IsInFullscreen="False"/>
13+
<dui:CameraPreview x:Name="CameraPreview"/>
1414
</dui:ContentPage>

src/app/Components/ComponentsSamples/BarcodeScanning/BarcodeCounterSample.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public BarcodeCounterSample()
1818
{
1919
Preview = CameraPreview,
2020
OnCameraFailed = CameraFailed,
21-
ScanRectangle = new BarcodeScanRectangleOptions
21+
Strategy = new ScanRectangleBarcodeScanStrategy
2222
{
2323
WidthFraction = 0.8f,
2424
HeightFraction = 0.3f

src/app/Components/ComponentsSamples/BarcodeScanning/BarcodeOverlaySample.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@
1010
<ToolbarItem IconImageSource="{dui:Icons close_line}"
1111
Clicked="Close" />
1212
</dui:ContentPage.ToolbarItems>
13-
<dui:CameraPreview x:Name="CameraPreview" IsInFullscreen="False"/>
13+
<dui:CameraPreview x:Name="CameraPreview"/>
1414
</dui:ContentPage>

src/app/Components/ComponentsSamples/BarcodeScanning/BarcodeOverlaySample.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ await m_barcodeScanner.Start(new BarcodeScannerStartOptions
2727
Preview = CameraPreview,
2828
OnCameraFailed = CameraFailed,
2929
OnBarcodeAcceptedAsync = HandleBarcodeAcceptedAsync,
30-
ScanRectangle = new BarcodeScanRectangleOptions
30+
Strategy = new ScanRectangleBarcodeScanStrategy
3131
{
3232
WidthFraction = 0.8f,
3333
HeightFraction = 0.3f

src/app/Components/ComponentsSamples/BarcodeScanning/BarcodeScanningSample.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@
1313
Clicked="ShowTip">
1414
</ToolbarItem>
1515
</dui:ContentPage.ToolbarItems>
16-
<dui:CameraPreview x:Name="CameraPreview" IsInFullscreen="False"/>
16+
<dui:CameraPreview x:Name="CameraPreview"/>
1717
</dui:ContentPage>

src/app/Components/ComponentsSamples/BarcodeScanning/BarcodeTooltipSample.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@
1010
<ToolbarItem IconImageSource="{dui:Icons close_line}"
1111
Clicked="Close" />
1212
</dui:ContentPage.ToolbarItems>
13-
<dui:CameraPreview x:Name="CameraPreview" IsInFullscreen="False"/>
13+
<dui:CameraPreview x:Name="CameraPreview"/>
1414
</dui:ContentPage>

src/app/Components/ComponentsSamples/BarcodeScanning/BarcodeTooltipSample.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ await m_barcodeScanner.Start(new BarcodeScannerStartOptions
2626
Preview = CameraPreview,
2727
OnCameraFailed = CameraFailed,
2828
OnBarcodeAcceptedAsync = HandleBarcodeAcceptedAsync,
29-
ScanRectangle = new BarcodeScanRectangleOptions()
29+
Strategy = new ScanRectangleBarcodeScanStrategy()
3030
});
3131

3232
m_barcodeScanner.SetTooltipView(new Label
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
3+
<dui:ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
4+
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
5+
xmlns:dui="http://dips.com/mobile.ui"
6+
x:Class="Playground.EirikSamples.BarcodeScanResumeRepro"
7+
Title="Barcode Resume Repro (#1415)">
8+
9+
<dui:CameraPreview x:Name="CameraPreview" />
10+
</dui:ContentPage>
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
using DIPS.Mobile.UI.API.Camera;
2+
using DIPS.Mobile.UI.API.Camera.BarcodeScanning;
3+
using DIPS.Mobile.UI.Components.BottomSheets;
4+
5+
namespace Playground.EirikSamples;
6+
7+
/// <summary>
8+
/// Reproduction for Arena.Mobile#1415:
9+
/// After scanning a barcode and discarding the result (closing the bottom sheet),
10+
/// the camera is visible but barcode detection no longer works.
11+
///
12+
/// Steps:
13+
/// 1. Open this page
14+
/// 2. Scan any barcode/QR code
15+
/// 3. Close the bottom sheet (discard result)
16+
/// 4. Try scanning again — observe that detection does not resume
17+
/// </summary>
18+
public partial class BarcodeScanResumeRepro
19+
{
20+
private readonly BarcodeScanner m_barcodeScanner;
21+
22+
public BarcodeScanResumeRepro()
23+
{
24+
InitializeComponent();
25+
m_barcodeScanner = new BarcodeScanner();
26+
}
27+
28+
protected override void OnAppearing()
29+
{
30+
base.OnAppearing();
31+
_ = StartScanning();
32+
}
33+
34+
protected override void OnDisappearing()
35+
{
36+
m_barcodeScanner.StopAndDispose();
37+
base.OnDisappearing();
38+
}
39+
40+
private async Task StartScanning()
41+
{
42+
try
43+
{
44+
await m_barcodeScanner.Start(new BarcodeScannerStartOptions
45+
{
46+
Preview = CameraPreview,
47+
OnCameraFailed = e => DisplayAlert("Camera failed", e.Message, "OK"),
48+
OnBarcodeAcceptedAsync = OnBarcodeAccepted,
49+
Strategy = new ScanRectangleBarcodeScanStrategy
50+
{
51+
WidthFraction = 0.8f,
52+
HeightFraction = 0.3f
53+
}
54+
});
55+
}
56+
catch (Exception ex)
57+
{
58+
Console.WriteLine($"[BarcodeScanResumeRepro] Start failed: {ex}");
59+
}
60+
}
61+
62+
private Task OnBarcodeAccepted(BarcodeScanResult result)
63+
{
64+
m_barcodeScanner.PauseScanning(resetOverlay: false);
65+
66+
var sheet = new BottomSheet { Title = "Scan Result" };
67+
sheet.Content = new VerticalStackLayout
68+
{
69+
Padding = 16,
70+
Children =
71+
{
72+
new Label { Text = $"Barcode: {result.Barcode.RawValue}", Margin = new Thickness(0, 0, 0, 8) },
73+
new Label { Text = $"Format: {result.Barcode.Format}" }
74+
}
75+
};
76+
77+
sheet.Closed += (_, _) =>
78+
{
79+
Console.WriteLine("[BarcodeScanResumeRepro] Sheet closed, calling ResumeScanning()");
80+
m_barcodeScanner.ResumeScanning();
81+
};
82+
83+
sheet.Open();
84+
return Task.CompletedTask;
85+
}
86+
}

0 commit comments

Comments
 (0)