Skip to content
This repository was archived by the owner on May 1, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions samples/XCT.Sample/Pages/TestCases/LinkerCameraViewPage.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?xml version="1.0" encoding="utf-8" ?>
<pages:BasePage
x:Class="Xamarin.CommunityToolkit.Sample.Pages.TestCases.LinkerCameraViewPage"
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:pages="clr-namespace:Xamarin.CommunityToolkit.Sample.Pages"
xmlns:xct="http://xamarin.com/schemas/2020/toolkit">
<ContentPage.Content>
<StackLayout>
<Label HorizontalTextAlignment="Center" Text="This is to test if the Linker is keeping the MediaCaptured and MediaCaptureFailed events if they are used!" />
<Grid>
<xct:CameraView
x:Name="cameraView"
CaptureMode="Photo"
HorizontalOptions="FillAndExpand"
OnAvailable="CameraView_OnAvailable"
VerticalOptions="FillAndExpand">
<xct:CameraView.Behaviors>
<xct:EventToCommandBehavior Command="{Binding CaptureCommand}" EventName="MediaCaptured" />
</xct:CameraView.Behaviors>
</xct:CameraView>
<Button
x:Name="shutterButton"
Margin="40"
BackgroundColor="WhiteSmoke"
BorderColor="Black"
BorderWidth="1"
Clicked="ShutterButtonClicked"
CornerRadius="40"
HeightRequest="80"
HorizontalOptions="CenterAndExpand"
IsEnabled="False"
VerticalOptions="End"
WidthRequest="80" />
<Image
x:Name="previewPicture"
Margin="40"
Aspect="AspectFill"
BackgroundColor="Black"
HeightRequest="80"
HorizontalOptions="EndAndExpand"
VerticalOptions="EndAndExpand"
WidthRequest="80" />
</Grid>
</StackLayout>
</ContentPage.Content>
</pages:BasePage>
55 changes: 55 additions & 0 deletions samples/XCT.Sample/Pages/TestCases/LinkerCameraViewPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.CommunityToolkit.Sample.ViewModels;
using Xamarin.CommunityToolkit.UI.Views;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;

namespace Xamarin.CommunityToolkit.Sample.Pages.TestCases
{
public partial class LinkerCameraViewPage
{
int counter = 0;

public LinkerCameraViewPage()
{
InitializeComponent();
BindingContext = new CameraViewTestViewModel();
}

public void CameraView_OnAvailable(object sender, bool e)
{
shutterButton.IsEnabled = e;
}

public void CameraView_MediaCaptured(object sender, MediaCapturedEventArgs e)
{
shutterButton.Text = $"{++counter}";
previewPicture.Source = e.Image;
previewPicture.Rotation = e.Rotation;
}

void ShutterButtonClicked(object sender, EventArgs e)
{
cameraView.Shutter();
}
}

sealed class CameraViewTestViewModel : BaseViewModel
{
public Command<object> CaptureCommand { get; }

public CameraViewTestViewModel()
{
CaptureCommand = new Command<object>(CaptureCommandExecute);
}

void CaptureCommandExecute(object args)
{
Console.WriteLine(args);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ protected override IEnumerable<SectionModel> CreateItems() => new[]
typeof(PopupModalPage),
"Popup into modal",
"Using Popup into modal page show the popup"),

new SectionModel(
typeof(LinkerCameraViewPage),
"Linker for CameraView",
"Make sure that Linker is keeping the MediaCaptured and MediaCaptureFailed events if they are used."),
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ namespace Xamarin.CommunityToolkit.UI.Views
{
public class CameraView : View
{
[Preserve(Conditional = true)]
public event EventHandler<MediaCapturedEventArgs>? MediaCaptured;

[Preserve(Conditional = true)]
public event EventHandler<string>? MediaCaptureFailed;

public event EventHandler<bool>? OnAvailable;
Expand Down