Skip to content

[Proposal] CameraView minimal port #259

@pictos

Description

@pictos

[CameraView minimal port]

  • Proposed
  • Prototype: Not Started
  • Implementation: Not Started
    • iOS Support
    • Android Support
    • macOS Support
    • Windows Support
  • Unit Tests: Not Started
  • Sample: Not Started
  • Documentation: Not Started

Link to Discussion

Summary

Today on XCT we have a very complete CameraView implementation but with a lot of bugs and a complex codebase to maintain. In the table below you can see all features implemented by each platform.

Android iOS Windows
Preview
Preview Aspect 🚫 🚫
Mirror preview 🚫 🚫
Zoom
Take photo
Flash
Take video
Record audio
Video stabilization

My plan, described in discussion #206, is to drop some features for the v1.0 of this lib. and use CameraX implementation for Android. You can see in the table below what features we will have for v1.0.

Android iOS Windows
Preview
Take photo
Flash

After this first implementation, we can add the missing features to all platforms.

Motivation

The motivation for this plan was the fact that CameraView lacks in quality right now and this's our chance to fix it and provide a more reliable Camera control for our community.

Detailed Design

CameraView.shared.cs

public class CameraView : View
{
  public static readonly BindableProperty IsCameraViewBusyProperty;
  public static readonly BindableProperty IsAvailableProperty;
  public static readonly BindableProperty FlashModeProperty;
  
  // Use WeakEventManager 
  public event EventHandler<bool>? OnAvailable;
  public event EventHandler<MediaCapturedEventArgs>? MediaCaptured; 
  public event EventHandler<string>? MediaCaptureFailed;
  
  public bool IsCameraViewBusy { get; }
  public bool IsAvailable { get; }
  public CameraOptions CameraOptions { get; set; } 
  public void Shutter();
}

Usage Syntax

XAML Usage

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:xct="http://xamarin.com/schemas/2020/toolkit"
             x:Class="MyLittleApp.MainPage">

     <StackLayout>
        <xct:CameraView
                x:Name="cameraView"
                FlashMode="On"
                MediaCaptured="CameraView_MediaCaptured"
                HorizontalOptions="FillAndExpand"
                VerticalOptions="FillAndExpand" />
    </StackLayout>
</ContentPage>

C# Usage

class MyPage : ContentPage
{
  public MyPage()
  {
    Content = new CameraView
    {
      FlashMode = CameraFlashMode.Off,
    }.FillAndExpand()
     .Invoke(cameraView => cameraView.MediaCaptured += HandleMediaCaptured);
  }

  void HandleMediaCaptured(object? sender, MediaCapturedEventArgs e)
  {
    //...
  }
}

Drawbacks

We will (probably*) break our users on v1.0 since the API will be missing a lot of features.

  • there's a chance that we can implement all features for v1.0 if we have a lot of community help.

Alternatives

  • Follow the [Proposal] CameraView #106 proposal and just port the XCT code to here, but with that, we will bring all issues (if we don't solve them during the port, what I believe it's very hard to do)

Unresolved Questions

Metadata

Metadata

Assignees

Labels

approvedThis Proposal has been approved and is ready to be added to the ToolkitchampionA member of the .NET MAUI Toolkit core team has chosen to champion this featurein-progresspending documentationThis feature requires documentationproposalA fully fleshed out proposal describing a new feature in syntactic and semantic detail

Type

No type

Projects

Status

Completed

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions