Introduce the ability to extend camera functionality - #3274
Draft
bijington wants to merge 5 commits into
Draft
Conversation
…h as Barcode scanning
6 tasks
CliffAgius
reviewed
Jul 27, 2026
Contributor
There was a problem hiding this comment.
Are we still supporting Tizen? it's not possible to build a MAUI app on tizen as it's stuck on Net6...
Contributor
Author
There was a problem hiding this comment.
Good point! I needed to patch this for the builds to pass but it won't do anything
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds an extensibility mechanism to CameraView via attachable “scenarios” (e.g., barcode scanning), wires scenario handling into platform camera pipelines (Android/iOS), and provides a sample barcode-scanning page demonstrating the new capability.
Changes:
- Introduces
ICameraView.Scenarios/CameraView.Scenariosas a collection ofCameraScenarioinstances. - Adds
CameraManagerscenario management (add/remove/reset) plus platform hooks to integrate platform-specific outputs/use-cases. - Adds a new sample page and platform implementations for barcode scanning (including an Android MLKit package reference).
Reviewed changes
Copilot reviewed 25 out of 25 changed files in this pull request and generated 15 comments.
Show a summary per file
| File | Description |
|---|---|
| src/CommunityToolkit.Maui.Camera/Views/CameraView.shared.cs | Adds Scenarios bindable collection to CameraView. |
| src/CommunityToolkit.Maui.Camera/Interfaces/ICameraView.shared.cs | Exposes Scenarios on the camera view contract. |
| src/CommunityToolkit.Maui.Camera/Handlers/CameraViewHandler.shared.cs | Maps Scenarios and reacts to collection changes to update camera pipeline. |
| src/CommunityToolkit.Maui.Camera/Primitives/CameraScenario.shared.cs | Introduces base scenario lifecycle API (Initialize, attach/detach hooks). |
| src/CommunityToolkit.Maui.Camera/Primitives/PlatformCameraScenario.shared.cs | Adds a platform-specialized scenario base type. |
| src/CommunityToolkit.Maui.Camera/Primitives/PlatformCameraScenario.android.cs | Declares Android-specific platform scenario surface (UseCase). |
| src/CommunityToolkit.Maui.Camera/Primitives/PlatformCameraScenario.macios.cs | Declares Apple-specific platform scenario surface (AVCaptureOutput). |
| src/CommunityToolkit.Maui.Camera/CameraManager.shared.cs | Adds scenario list + add/remove/reset and preview refresh behavior. |
| src/CommunityToolkit.Maui.Camera/CameraManager.android.cs | Integrates additional UseCases into rebinding flow. |
| src/CommunityToolkit.Maui.Camera/CameraManager.macios.cs | Integrates scenario outputs into AVCaptureSession startup. |
| src/CommunityToolkit.Maui.Camera/CameraManager.net.cs | Adds scenario APIs for unsupported platforms (throws NotSupported). |
| src/CommunityToolkit.Maui.Camera/CameraManager.tizen.cs | Adjusts partial method signatures and adds scenario APIs (throws NotSupported). |
| samples/CommunityToolkit.Maui.Sample/ViewModels/Views/ViewsGalleryViewModel.cs | Adds a sample gallery entry for barcode scanning. |
| samples/CommunityToolkit.Maui.Sample/ViewModels/Views/CameraView/BarcodeScanningViewModel.cs | New view model to display detected barcode text and refresh cameras. |
| samples/CommunityToolkit.Maui.Sample/Pages/Views/CameraView/BarcodeScanningPage.xaml | New page wiring CameraView.Scenarios to a barcode-scanning scenario. |
| samples/CommunityToolkit.Maui.Sample/Pages/Views/CameraView/BarcodeScanningPage.xaml.cs | New page code-behind to refresh camera list on appearing. |
| samples/CommunityToolkit.Maui.Sample/PlatformBarcodeScanningScenario.cs | Shared scenario surface (bindable Command) for barcode detection callbacks. |
| samples/CommunityToolkit.Maui.Sample/Platforms/PlatformBarcodeScanningScenario.cs | Adds a partial scenario file in Platforms folder. |
| samples/CommunityToolkit.Maui.Sample/Platforms/Android/PlatformBarcodeScanningScenario.cs | Android-specific scenario implementation using CameraX ImageAnalysis. |
| samples/CommunityToolkit.Maui.Sample/Platforms/Android/BarcodeAnalyzer.cs | Android barcode analyzer implementation using MLKit. |
| samples/CommunityToolkit.Maui.Sample/Platforms/iOS/PlatformBarcodeScanningScenario.cs | iOS-specific scenario using AVCaptureMetadataOutput. |
| samples/CommunityToolkit.Maui.Sample/Platforms/MacCatalyst/PlatformBarcodeScanningScenario.cs | Mac Catalyst-specific scenario using AVCaptureMetadataOutput. |
| samples/CommunityToolkit.Maui.Sample/MauiProgram.cs | Registers the new barcode scanning page + view model. |
| samples/CommunityToolkit.Maui.Sample/AppShell.xaml.cs | Adds shell mapping for barcode scanning page. |
| samples/CommunityToolkit.Maui.Sample/CommunityToolkit.Maui.Sample.csproj | Adds Android-only MLKit barcode scanning package reference. |
Comment on lines
+25
to
+27
| readonly IList<CameraScenario> scenarios = []; | ||
|
|
||
| protected IReadOnlyList<CameraScenario> Scenarios => scenarios.AsReadOnly(); |
Comment on lines
+5
to
+9
| /// <summary> | ||
| /// | ||
| /// </summary> | ||
| partial class PlatformCameraScenario : CameraScenario | ||
| { |
Comment on lines
+5
to
+9
| /// <summary> | ||
| /// | ||
| /// </summary> | ||
| partial class PlatformCameraScenario : CameraScenario | ||
| { |
Comment on lines
+6
to
+12
| /// <summary> | ||
| /// | ||
| /// </summary> | ||
| public partial class PlatformBarcodeScanningScenario : PlatformCameraScenario | ||
| { | ||
| public ICommand? Command { get; set; } | ||
| } No newline at end of file |
Comment on lines
+19
to
+21
| <toolkit:CameraView.Scenarios> | ||
| <sample:PlatformBarcodeScanningScenario Command="{Binding BindingContext.CodeDetectedCommand, Source={x:Reference Camera}}" /> | ||
| </toolkit:CameraView.Scenarios> |
Comment on lines
+24
to
+26
| /// <summary>Bindable property for <see cref="CameraScenario"/>.</summary> | ||
| public static readonly BindableProperty ScenariosProperty = ScenariosPropertyKey.BindableProperty; | ||
|
|
Comment on lines
295
to
297
| /// <inheritdoc cref="ICameraView.StopCameraPreview"/> | ||
| public void StopCameraPreview() => | ||
| Handler.CameraManager.StopCameraPreview(); | ||
| public void StopCameraPreview() =>Handler.CameraManager.StopCameraPreview(); | ||
|
|
Comment on lines
+14
to
+18
| base.OnAppearing(); | ||
|
|
||
| var cancellationTokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(3)); | ||
| await BindingContext.RefreshCamerasCommand.ExecuteAsync(cancellationTokenSource.Token); | ||
| } |
Comment on lines
+21
to
+33
| /// <summary> | ||
| /// | ||
| /// </summary> | ||
| public virtual void OnAttached() | ||
| { | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// | ||
| /// </summary> | ||
| public virtual void OnDetached() | ||
| { | ||
| } |
Comment on lines
+3
to
+7
| /// <summary> | ||
| /// | ||
| /// </summary> | ||
| public abstract partial class PlatformCameraScenario : CameraScenario | ||
| { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Current status
This it the remaining TODO list
Introduce the ability to extend camera functionality for concepts such as Barcode scanning.
Replaces the original PR attempt at #2841.
Description of Change
Camera Scenarios Usage Guide
The Community Toolkit for MAUI CameraView allows extending its functionality through "Scenarios". There are two primary ways to implement a scenario:
PlatformCameraScenarioandFrameBasedCameraScenario.PlatformCameraScenario
PlatformCameraScenariois designed for scenarios where you want to leverage platform-specific high-performance APIs (e.g., Google ML Kit on Android, Apple Vision framework on iOS, or Windows Media Capture APIs).When to use it
Implementation Example (Windows)
In the sample project,
PlatformBarcodeScanningScenarioon Windows uses theMediaFrameReaderto capture frames and decode them usingZXing.Netwithin the platform-specific code.FrameBasedCameraScenario
FrameBasedCameraScenariois a specialized version ofPlatformCameraScenariothat abstracts the frame capture process. It provides a platform-agnosticOnFrameReceivedmethod that gives you access to aCameraFramecontaining raw byte data.When to use it
ZXing.Net) that can process raw image data.Implementation Example (Shared)
In the sample project,
SharedBarcodeScanningScenariodemonstrates how to implement barcode scanning in shared code.Key Differences
ImageProxy,CMSampleBuffer)CameraFrame(Raw bytes)Usage in XAML
Both types of scenarios are used in the same way with the
CameraView.Linked Issues
PR Checklist
approved(bug) orChampioned(feature/proposal)mainat time of PRAdditional information
Example of it working on macOS
scanning.mov