Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-arch to work for Controls and Comet #8

Merged
merged 3 commits into from
Oct 18, 2022
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
1 change: 1 addition & 0 deletions BigIslandBarcode/BigIslandBarcode.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@

<ItemGroup>
<ProjectReference Include="..\ZXing.Net.MAUI\ZXing.Net.MAUI.csproj" />
<ProjectReference Include="..\ZXing.Net.MAUI.Controls\ZXing.Net.MAUI.Controls.csproj" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion BigIslandBarcode/MainPage.xaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:zxing="clr-namespace:ZXing.Net.Maui.Controls;assembly=ZXing.Net.MAUI"
xmlns:zxing="clr-namespace:ZXing.Net.Maui.Controls;assembly=ZXing.Net.MAUI.Controls"
x:Class="BigIslandBarcode.MainPage"
BackgroundColor="#000000">

Expand Down
1 change: 1 addition & 0 deletions BigIslandBarcode/MauiProgram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Microsoft.Maui.Controls.Hosting;
using Microsoft.Maui.LifecycleEvents;
using ZXing.Net.Maui;
using ZXing.Net.Maui.Controls;

#if ANDROID
[assembly: Android.App.UsesPermission(Android.Manifest.Permission.Camera)]
Expand Down
6 changes: 6 additions & 0 deletions ZXing.Net.MAUI.Comet/Controls.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
using Comet;
using ZXing.Net.Maui;

[assembly: CometGenerate(typeof(ICameraBarcodeReaderView), nameof(ICameraBarcodeReaderView.BarcodesDetected))]
[assembly: CometGenerate(typeof(ICameraView), nameof(ICameraView.CameraLocation))]
[assembly: CometGenerate(typeof(IBarcodeGeneratorView), nameof(IBarcodeGeneratorView.Value), nameof(IBarcodeGeneratorView.Format), Skip = new[] { $"{nameof(IBarcodeGeneratorView.ForegroundColor)}:{EnvironmentKeys.Colors.Color}" })]
59 changes: 59 additions & 0 deletions ZXing.Net.MAUI.Comet/HostBuilderExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#if IOS || MACCATALYST
global using NativePlatformCameraPreviewView = global::UIKit.UIView;
global using NativePlatformView = global::UIKit.UIView;
global using NativePlatformImageView = global::UIKit.UIImageView;
global using NativePlatformImage = global::UIKit.UIImage;
#elif ANDROID
global using NativePlatformCameraPreviewView = global::AndroidX.Camera.View.PreviewView;
global using NativePlatformView = global::Android.Views.View;
global using NativePlatformImageView = global::Android.Widget.ImageView;
global using NativePlatformImage = global::Android.Graphics.Bitmap;
#elif WINDOWS
global using NativePlatformCameraPreviewView = global::Microsoft.UI.Xaml.FrameworkElement;
global using NativePlatformView = global::Microsoft.UI.Xaml.FrameworkElement;
global using NativePlatformImageView = global::Microsoft.UI.Xaml.Controls.Image;
global using NativePlatformImage = global::Microsoft.UI.Xaml.Media.Imaging.WriteableBitmap;
#endif

using Microsoft.Extensions.DependencyInjection;
using Microsoft.Maui.Hosting;
using Microsoft.Maui;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ZXing.Net.Maui
{
public static class MauiHostBuilderExtensions
{
public static MauiAppBuilder UseBarcodeReader(this MauiAppBuilder builder)
{
builder.ConfigureMauiHandlers(handlers =>
{
handlers.AddHandler(typeof(CameraView), typeof(CameraViewHandler));
handlers.AddHandler(typeof(CameraBarcodeReaderView), typeof(CameraBarcodeReaderViewHandler));
handlers.AddHandler(typeof(BarcodeGeneratorView), typeof(BarcodeGeneratorViewHandler));
});

builder.Services.AddTransient<Readers.IBarcodeReader, Readers.ZXingBarcodeReader>();

return builder;
}

public static MauiAppBuilder UseBarcodeReader<TBarcodeReader>(this MauiAppBuilder builder) where TBarcodeReader : class, Readers.IBarcodeReader
{
builder.ConfigureMauiHandlers(handlers =>
{
handlers.AddHandler(typeof(CameraView), typeof(CameraViewHandler));
handlers.AddHandler(typeof(CameraBarcodeReaderView), typeof(CameraBarcodeReaderViewHandler));
handlers.AddHandler(typeof(BarcodeGeneratorView), typeof(BarcodeGeneratorViewHandler));
});

builder.Services.AddTransient<Readers.IBarcodeReader, TBarcodeReader>();

return builder;
}

}
}
28 changes: 28 additions & 0 deletions ZXing.Net.MAUI.Comet/ZXing.Net.MAUI.Comet.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net6.0-android;net6.0-maccatalyst;net6.0-ios</TargetFrameworks>
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net6.0-windows10.0.19041</TargetFrameworks>
<PackageId>ZXing.Net.Maui.Comet</PackageId>
<Title>ZXing.Net.MAUI Barcode Scanner for .NET MAUI</Title>
<Authors>Redth</Authors>
<UseMaui>True</UseMaui>
<SingleProject>True</SingleProject>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<UseSystemResourceKeys>false</UseSystemResourceKeys>
<Copyright>Copyright © Redth</Copyright>
<PackageProjectUrl>https://github.com/redth/BigIslandBarcoding</PackageProjectUrl>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<RepositoryUrl>https://github.com/redth/BigIslandBarcoding</RepositoryUrl>
<AssemblyFileVersion>$(PackageVersion)</AssemblyFileVersion>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<DebugType>portable</DebugType>
<OutputType>Library</OutputType>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="ZXing.Net" Version="0.16.8" />
<PackageReference Include="Clancey.Comet" Version="0.3.465-beta" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ZXing.Net.MAUI\ZXing.Net.MAUI.csproj" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,8 @@ public partial class CameraBarcodeReaderView : View, ICameraBarcodeReaderView
public event EventHandler<BarcodeDetectionEventArgs> BarcodesDetected;
public event EventHandler<CameraFrameBufferEventArgs> FrameReady;

protected override void OnHandlerChanging(HandlerChangingEventArgs args)
{
base.OnHandlerChanging(args);
if (args.OldHandler is CameraBarcodeReaderViewHandler oldHandler)
{
oldHandler.BarcodesDetected -= Handler_BarcodesDetected;
oldHandler.FrameReady -= Handler_FrameReady;
}

if (args.NewHandler is CameraBarcodeReaderViewHandler newHandler)
{
newHandler.BarcodesDetected += Handler_BarcodesDetected;
newHandler.FrameReady += Handler_FrameReady;
}
}

void Handler_BarcodesDetected(object sender, BarcodeDetectionEventArgs e)
=> BarcodesDetected?.Invoke(this, e);
void ICameraBarcodeReaderView.BarcodesDetected(BarcodeDetectionEventArgs e) => BarcodesDetected?.Invoke(this, e);
void ICameraFrameAnalyzer.FrameReady(ZXing.Net.Maui.CameraFrameBufferEventArgs e) => FrameReady?.Invoke(this, e);

public static readonly BindableProperty OptionsProperty =
BindableProperty.Create(nameof(Options), typeof(BarcodeReaderOptions), typeof(CameraBarcodeReaderView), defaultValueCreator: bindableObj => new BarcodeReaderOptions());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,7 @@ public partial class CameraView : View, ICameraView
{
public event EventHandler<CameraFrameBufferEventArgs> FrameReady;

protected override void OnHandlerChanging(HandlerChangingEventArgs args)
{
base.OnHandlerChanging(args);
if (args.OldHandler is CameraViewHandler oldHandler)
oldHandler.FrameReady -= Handler_FrameReady;

if (args.NewHandler is CameraViewHandler newHandler)
newHandler.FrameReady += Handler_FrameReady;
}

void Handler_FrameReady(object sender, CameraFrameBufferEventArgs e)
void ICameraFrameAnalyzer.FrameReady(CameraFrameBufferEventArgs e)
=> FrameReady?.Invoke(this, e);

public static readonly BindableProperty IsTorchOnProperty =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
using System.Threading.Tasks;
using ZXing.Net.Maui.Controls;

namespace ZXing.Net.Maui
namespace ZXing.Net.Maui.Controls
{
public static class CameraViewExtensions
{
Expand Down
27 changes: 27 additions & 0 deletions ZXing.Net.MAUI.Controls/ZXing.Net.MAUI.Controls.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net6.0-android;net6.0-maccatalyst;net6.0-ios</TargetFrameworks>
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net6.0-windows10.0.19041</TargetFrameworks>
<PackageId>ZXing.Net.Maui.Controls</PackageId>
<Title>ZXing.Net.MAUI Barcode Scanner for .NET MAUI</Title>
<Authors>Redth</Authors>
<UseMaui>True</UseMaui>
<SingleProject>True</SingleProject>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<UseSystemResourceKeys>false</UseSystemResourceKeys>
<Copyright>Copyright © Redth</Copyright>
<PackageProjectUrl>https://github.com/redth/BigIslandBarcoding</PackageProjectUrl>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<RepositoryUrl>https://github.com/redth/BigIslandBarcoding</RepositoryUrl>
<AssemblyFileVersion>$(PackageVersion)</AssemblyFileVersion>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<DebugType>portable</DebugType>
<OutputType>Library</OutputType>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="ZXing.Net" Version="0.16.8" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ZXing.Net.MAUI\ZXing.Net.MAUI.csproj" />
</ItemGroup>
</Project>
6 changes: 6 additions & 0 deletions ZXing.Net.MAUI.sln
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ZXing.Net.MAUI", "ZXing.Net
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BigIslandBarcode", "BigIslandBarcode\BigIslandBarcode.csproj", "{D3EBA600-16E4-4C91-A9E9-CC600FA2B481}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ZXing.Net.MAUI.Controls", "ZXing.Net.MAUI.Controls\ZXing.Net.MAUI.Controls.csproj", "{F7911DCB-5278-4CE9-A934-48089F92162A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -22,6 +24,10 @@ Global
{D3EBA600-16E4-4C91-A9E9-CC600FA2B481}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
{D3EBA600-16E4-4C91-A9E9-CC600FA2B481}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D3EBA600-16E4-4C91-A9E9-CC600FA2B481}.Release|Any CPU.Build.0 = Release|Any CPU
{F7911DCB-5278-4CE9-A934-48089F92162A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F7911DCB-5278-4CE9-A934-48089F92162A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F7911DCB-5278-4CE9-A934-48089F92162A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F7911DCB-5278-4CE9-A934-48089F92162A}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
16 changes: 16 additions & 0 deletions ZXing.Net.MAUI/GlobalUsings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#if IOS || MACCATALYST
global using NativePlatformCameraPreviewView = global::UIKit.UIView;
global using NativePlatformView = global::UIKit.UIView;
global using NativePlatformImageView = global::UIKit.UIImageView;
global using NativePlatformImage = global::UIKit.UIImage;
#elif ANDROID
global using NativePlatformCameraPreviewView = global::AndroidX.Camera.View.PreviewView;
global using NativePlatformView = global::Android.Views.View;
global using NativePlatformImageView = global::Android.Widget.ImageView;
global using NativePlatformImage = global::Android.Graphics.Bitmap;
#elif WINDOWS
global using NativePlatformCameraPreviewView = global::Microsoft.UI.Xaml.FrameworkElement;
global using NativePlatformView = global::Microsoft.UI.Xaml.FrameworkElement;
global using NativePlatformImageView = global::Microsoft.UI.Xaml.Controls.Image;
global using NativePlatformImage = global::Microsoft.UI.Xaml.Media.Imaging.WriteableBitmap;
#endif
2 changes: 1 addition & 1 deletion ZXing.Net.MAUI/ICameraBarcodeReaderView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public interface ICameraBarcodeReaderView : ICameraView
{
BarcodeReaderOptions Options { get; }

event EventHandler<BarcodeDetectionEventArgs> BarcodesDetected;
void BarcodesDetected(BarcodeDetectionEventArgs args);

bool IsDetecting { get; set; }
}
Expand Down
2 changes: 1 addition & 1 deletion ZXing.Net.MAUI/ICameraView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace ZXing.Net.Maui
{
public interface ICameraFrameAnalyzer
{
event EventHandler<CameraFrameBufferEventArgs> FrameReady;
void FrameReady(CameraFrameBufferEventArgs args);
}

public interface ICameraView : IView, ICameraFrameAnalyzer
Expand Down