Skip to content

Refactor barcode scanner; fix detection not resuming after pause#870

Open
Vetle444 wants to merge 5 commits into
mainfrom
vefi/barcodePauseBug
Open

Refactor barcode scanner; fix detection not resuming after pause#870
Vetle444 wants to merge 5 commits into
mainfrom
vefi/barcodePauseBug

Conversation

@Vetle444
Copy link
Copy Markdown
Contributor

@Vetle444 Vetle444 commented May 22, 2026

Description of Change

Refactors the barcode scanner's session lifecycle, detection pipeline, and configuration API. Fixes the bug where detection no longer resumed after the result bottom sheet was dismissed (Arena.Mobile#1415).

Fix

  • Scanner now reliably resumes detection after pause/resume. A session-scoped CancellationTokenSource replaces the previous m_isDisposed checks so a stale Start callback can no longer leave the scanner in an inactive state.
  • iOS: scanRunId is captured per detection instead of per session, so the platform delegate no longer drops detections after a resume.

Breaking changes

  • BarcodeScannerStartOptions: ScanRectangle (BarcodeScanRectangleOptions) and BarcodeDetectionTime are replaced by a single Strategy property of type BarcodeScanStrategy:
    • TimerBarcodeScanStrategy { DetectionTime } — timer-based confirmation, no overlay (default, 500 ms)
    • ScanRectangleBarcodeScanStrategy { WidthFraction, HeightFraction, BracketsTravelDuration, FormingDuration } — animated scan rectangle overlay
  • CameraPreview.IsInFullscreen: removed. The preview always applies safe-area padding on iOS.
Migration
// Before
new BarcodeScannerStartOptions
{
    BarcodeDetectionTime = 500,
    ScanRectangle = new BarcodeScanRectangleOptions
    {
        WidthFraction = 0.8f,
        HeightFraction = 0.3f,
    },
}

// After — overlay
new BarcodeScannerStartOptions
{
    Strategy = new ScanRectangleBarcodeScanStrategy
    {
        WidthFraction = 0.8f,
        HeightFraction = 0.3f,
    },
}

// After — no overlay
new BarcodeScannerStartOptions
{
    Strategy = new TimerBarcodeScanStrategy { DetectionTime = TimeSpan.FromMilliseconds(500) },
}

Refactor

  • Extracted barcode confirmation logic into IBarcodeConfirmationHandler with TimerBarcodeConfirmationHandler and OverlayBarcodeConfirmationHandler. The scanner dispatches polymorphically via the handler — no if/else or type-check fallback in InvokeBarcodeFound.
  • Extracted barcode observation collection into BarcodeDetectionAggregator.
  • Reorganised types into Detection/, Overlay/, and Progress/ subfolders.
  • Consolidated session-state checks into IsSessionActive / CanResumeSession helpers.
  • Removed duplicated m_startOptions fields from iOS and Android platform partials.
  • Removed unused Android files: CaptureSessionCallBack, CaptureStateCallback, QrCodeDrawable.

Playground

  • Added BarcodeScanResumeRepro page reproducing the resume bug.
  • Added a second entry that opens the same scanner inside a modal.

Todos

  • I have tested on an Android device.
  • I have tested on an iOS device.
  • I have supported accessibility

Vetle444 and others added 4 commits May 21, 2026 15:59
- Document the barcode scanner refactor, the breaking Strategy API change,
  and the removal of CameraPreview.IsInFullscreen
- Add a playground entry that opens BarcodeScanResumeRepro inside a modal
  to verify the pause/resume fix across navigation hosts

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Move barcode confirmation logic into IBarcodeConfirmationHandler with
TimerBarcodeConfirmationHandler and OverlayBarcodeConfirmationHandler.
The scanner dispatches polymorphically — no if/else or type-check
fallback in InvokeBarcodeFound.

Remove internal-only refactoring entry from changelog.
@Vetle444 Vetle444 marked this pull request as ready for review May 22, 2026 11:12
Copilot AI review requested due to automatic review settings May 22, 2026 11:12
@Vetle444 Vetle444 enabled auto-merge (squash) May 22, 2026 11:12
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Refactors the BarcodeScanner session lifecycle and detection/confirmation pipeline to fix the issue where scanning could fail to resume after a pause/resume cycle. The PR also introduces a new strategy-based configuration API (breaking change) and removes CameraPreview.IsInFullscreen (breaking change) while updating samples and wiki documentation accordingly.

Changes:

  • Fixes resume reliability by making the scanner session lifecycle cancellation-token based and by capturing scanRunId per detection on iOS.
  • Replaces BarcodeScannerStartOptions.ScanRectangle + BarcodeDetectionTime with BarcodeScannerStartOptions.Strategy : BarcodeScanStrategy, splitting confirmation logic into strategy-specific handlers.
  • Adds scan-count progress/completion support (progress counter + completion callback) and updates docs/samples; removes unused Android implementation files.

Reviewed changes

Copilot reviewed 30 out of 39 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
wiki/Media/Camera.md Updates documentation to use Strategy instead of ScanRectangle.
src/library/DIPS.Mobile.UI/API/Camera/Preview/CameraPreview.Properties.cs Removes IsInFullscreen property (breaking change).
src/library/DIPS.Mobile.UI/API/Camera/Preview/CameraPreview.cs Always applies iOS safe-area padding (no fullscreen toggle).
src/library/DIPS.Mobile.UI/API/Camera/BarcodeScanning/TimerBarcodeConfirmationHandler.cs Adds timer-based confirmation handler for TimerBarcodeScanStrategy.
src/library/DIPS.Mobile.UI/API/Camera/BarcodeScanning/Progress/BarcodeScanProgressView.cs Adds progress counter UI and animations.
src/library/DIPS.Mobile.UI/API/Camera/BarcodeScanning/Progress/BarcodeScanProgressController.cs Controls showing/updating/removing the progress counter view.
src/library/DIPS.Mobile.UI/API/Camera/BarcodeScanning/Progress/BarcodeScanProgress.cs Introduces progress state for required scan count.
src/library/DIPS.Mobile.UI/API/Camera/BarcodeScanning/Progress/BarcodeScanCompletionOptions.cs Public options for required count + completion callback.
src/library/DIPS.Mobile.UI/API/Camera/BarcodeScanning/OverlayBarcodeConfirmationHandler.cs Adds overlay-based confirmation handler for rectangle strategy.
src/library/DIPS.Mobile.UI/API/Camera/BarcodeScanning/Overlay/BarcodeScanResultView.xaml.cs Adds result view code-behind + bindable property.
src/library/DIPS.Mobile.UI/API/Camera/BarcodeScanning/Overlay/BarcodeScanResultView.xaml Adds result view UI for debugging scan results/observations.
src/library/DIPS.Mobile.UI/API/Camera/BarcodeScanning/Overlay/BarcodeScanRectangleOverlay.cs Makes overlay animation timings configurable; refactors animation keys and dimming behavior.
src/library/DIPS.Mobile.UI/API/Camera/BarcodeScanning/iOS/BarcodeScanner.cs Adjusts iOS detection callback to capture scanRunId per detection; strategy-based rect-of-interest config.
src/library/DIPS.Mobile.UI/API/Camera/BarcodeScanning/IBarcodeConfirmationHandler.cs Introduces interface for strategy-specific confirmation logic.
src/library/DIPS.Mobile.UI/API/Camera/BarcodeScanning/Detection/BarcodeScanValidationResult.cs Adds structured validation result (valid/invalid + error/reason/state).
src/library/DIPS.Mobile.UI/API/Camera/BarcodeScanning/Detection/BarcodeScanResult.cs Updates scan result model + docs; carries validation result/state.
src/library/DIPS.Mobile.UI/API/Camera/BarcodeScanning/Detection/BarcodeObservation.cs Adds observation model for detected barcodes + detection counts.
src/library/DIPS.Mobile.UI/API/Camera/BarcodeScanning/Detection/BarcodeDetectionAggregator.cs Extracts detection aggregation into a dedicated class.
src/library/DIPS.Mobile.UI/API/Camera/BarcodeScanning/Detection/Barcode.cs Introduces barcode value model (raw value + format).
src/library/DIPS.Mobile.UI/API/Camera/BarcodeScanning/BarcodeScanStrategy.cs Adds new strategy API (TimerBarcodeScanStrategy, ScanRectangleBarcodeScanStrategy).
src/library/DIPS.Mobile.UI/API/Camera/BarcodeScanning/BarcodeScanRectangleOptions.cs Removes old ScanRectangle options type (breaking change).
src/library/DIPS.Mobile.UI/API/Camera/BarcodeScanning/BarcodeScannerStartOptions.cs Replaces rectangle/time properties with Strategy (breaking change).
src/library/DIPS.Mobile.UI/API/Camera/BarcodeScanning/BarcodeScanner.cs Refactors session lifecycle, detection pipeline, cooldown, and confirmation dispatch; adds CTS-based session cancellation.
src/library/DIPS.Mobile.UI/API/Camera/BarcodeScanning/Android/QrCodeDrawable.cs Removes unused Android drawable.
src/library/DIPS.Mobile.UI/API/Camera/BarcodeScanning/Android/CaptureStateCallback.cs Removes unused Android camera callback wrapper.
src/library/DIPS.Mobile.UI/API/Camera/BarcodeScanning/Android/CaptureSessionCallBack.cs Removes unused Android capture callback/state machine.
src/library/DIPS.Mobile.UI/API/Camera/BarcodeScanning/Android/BarcodeScanner.cs Updates Android scan-rectangle filtering to use new strategy API.
src/app/Playground/MainPage.xaml.cs Adds navigation actions for resume repro sample pages.
src/app/Playground/MainPage.xaml Adds UI entries to launch resume repro sample pages.
src/app/Playground/EirikSamples/BarcodeScanResumeRepro.xaml.cs Adds repro page code-behind to exercise pause/resume behavior.
src/app/Playground/EirikSamples/BarcodeScanResumeRepro.xaml Adds repro page UI hosting a CameraPreview.
src/app/Components/ComponentsSamples/BarcodeScanning/BarcodeTooltipSample.xaml.cs Updates sample to use Strategy.
src/app/Components/ComponentsSamples/BarcodeScanning/BarcodeTooltipSample.xaml Removes IsInFullscreen usage in sample.
src/app/Components/ComponentsSamples/BarcodeScanning/BarcodeScanningSample.xaml Removes IsInFullscreen usage in sample.
src/app/Components/ComponentsSamples/BarcodeScanning/BarcodeOverlaySample.xaml.cs Updates overlay sample to use Strategy.
src/app/Components/ComponentsSamples/BarcodeScanning/BarcodeOverlaySample.xaml Removes IsInFullscreen usage in sample.
src/app/Components/ComponentsSamples/BarcodeScanning/BarcodeCounterSample.xaml.cs Updates counter sample to use Strategy.
src/app/Components/ComponentsSamples/BarcodeScanning/BarcodeCounterSample.xaml Removes IsInFullscreen usage in sample.
CHANGELOG.md Adds 60.0.0 entry documenting bugfix + breaking changes; also includes formatting cleanup in older entries.
Comments suppressed due to low confidence (1)

src/library/DIPS.Mobile.UI/API/Camera/BarcodeScanning/Overlay/BarcodeScanRectangleOverlay.cs:52

  • The animation lengths are derived by casting TimeSpan.TotalMilliseconds directly to uint. If a consumer sets a negative duration (or a very large duration), this cast will underflow/overflow and produce an unintended animation length. Validate/clamp bracketsTravelDuration and formingDuration (e.g., <= 0 → 0/throw; > uint.MaxValue → cap) before assigning m_bracketsTravelLength / m_formingLength.

Comment thread src/app/Playground/EirikSamples/BarcodeScanResumeRepro.xaml.cs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants