Skip to content
This repository has been archived by the owner on May 5, 2021. It is now read-only.

Commit

Permalink
Rewrote the Xamarin.Forms views:
Browse files Browse the repository at this point in the history
 - SignaturePadCanvasView is now wrapped as this is chromeless
 - SignaturePadView is now a fully Xamarin.Forms view so that it can be better customized as there is access to the individual views
  • Loading branch information
mattleibow committed Apr 21, 2017
1 parent 713ecbd commit ba653e5
Show file tree
Hide file tree
Showing 8 changed files with 672 additions and 255 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
</PropertyGroup>
<ItemGroup>
<Compile Include="$(MSBuildThisFileDirectory)ColorExtensions.cs" />
<Compile Include="$(MSBuildThisFileDirectory)SignaturePadRenderer.cs" />
<Compile Include="$(MSBuildThisFileDirectory)SignaturePadCanvasRenderer.cs" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -1,58 +1,49 @@
using System;
using System.ComponentModel;
using System.IO;
using System.Threading.Tasks;
using System.Linq;
using Xamarin.Forms;
using SignaturePad.Forms;
using Color = Xamarin.Forms.Color;
using Point = Xamarin.Forms.Point;
#if WINDOWS_PHONE
using System.Windows.Media;
using System.Windows.Media.Imaging;
using Xamarin.Forms.Platform.WinPhone;
using NativeSignaturePadView = Xamarin.Controls.SignaturePad;
using NativeSignaturePadCanvasView = Xamarin.Controls.SignaturePadCanvasView;
using NativePoint = System.Windows.Point;
#elif WINDOWS_UWP
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Media.Imaging;
using Xamarin.Forms.Platform.UWP;
using Microsoft.Graphics.Canvas;
using NativeSignaturePadView = Xamarin.Controls.SignaturePad;
using NativeSignaturePadCanvasView = Xamarin.Controls.SignaturePadCanvasView;
using NativePoint = Windows.Foundation.Point;
#elif __IOS__
using UIKit;
using Xamarin.Forms.Platform.iOS;
using NativeSignaturePadView = Xamarin.Controls.SignaturePadView;
using NativeSignaturePadCanvasView = Xamarin.Controls.SignaturePadCanvasView;
using NativePoint = CoreGraphics.CGPoint;
using NativeColor = UIKit.UIColor;
#elif __ANDROID__
using Android.Graphics;
using Android.Widget;
using Xamarin.Forms.Platform.Android;
using NativeSignaturePadView = Xamarin.Controls.SignaturePadView;
using NativeSignaturePadCanvasView = Xamarin.Controls.SignaturePadCanvasView;
using NativePoint = System.Drawing.PointF;
using NativeColor = Android.Graphics.Color;
#endif

[assembly: ExportRenderer (typeof (SignaturePadView), typeof (SignaturePadRenderer))]
[assembly: ExportRenderer (typeof (SignaturePadCanvasView), typeof (SignaturePadCanvasRenderer))]

namespace SignaturePad.Forms
{
public class SignaturePadRenderer : ViewRenderer<SignaturePadView, NativeSignaturePadView>
public class SignaturePadCanvasRenderer : ViewRenderer<SignaturePadCanvasView, NativeSignaturePadCanvasView>
{
protected override void OnElementChanged (ElementChangedEventArgs<SignaturePadView> e)
protected override void OnElementChanged (ElementChangedEventArgs<SignaturePadCanvasView> e)
{
base.OnElementChanged (e);

if (Control == null && e.NewElement != null)
{
// Instantiate the native control and assign it to the Control property
#if __ANDROID__
var native = new NativeSignaturePadView (Xamarin.Forms.Forms.Context);
var native = new NativeSignaturePadCanvasView (Xamarin.Forms.Forms.Context);
#else
var native = new NativeSignaturePadView ();
var native = new NativeSignaturePadCanvasView ();
#endif

native.StrokeCompleted += OnStrokeCompleted;

SetNativeControl (native);
}

Expand All @@ -63,6 +54,8 @@ protected override void OnElementChanged (ElementChangedEventArgs<SignaturePadVi
e.OldElement.IsBlankRequested -= OnIsBlankRequested;
e.OldElement.PointsRequested -= OnPointsRequested;
e.OldElement.PointsSpecified -= OnPointsSpecified;
e.OldElement.StrokesRequested -= OnStrokesRequested;
e.OldElement.StrokesSpecified -= OnStrokesSpecified;
e.OldElement.ClearRequested -= OnClearRequested;
}

Expand All @@ -73,6 +66,8 @@ protected override void OnElementChanged (ElementChangedEventArgs<SignaturePadVi
e.NewElement.IsBlankRequested += OnIsBlankRequested;
e.NewElement.PointsRequested += OnPointsRequested;
e.NewElement.PointsSpecified += OnPointsSpecified;
e.NewElement.StrokesRequested += OnStrokesRequested;
e.NewElement.StrokesSpecified += OnStrokesSpecified;
e.NewElement.ClearRequested += OnClearRequested;

UpdateAll ();
Expand All @@ -86,7 +81,12 @@ protected override void OnElementPropertyChanged (object sender, PropertyChanged
Update (e.PropertyName);
}

private void OnImageStreamRequested (object sender, SignaturePadView.ImageStreamRequestedEventArgs e)
private void OnStrokeCompleted (object sender, EventArgs e)
{
Element?.OnStrokeCompleted ();
}

private void OnImageStreamRequested (object sender, SignaturePadCanvasView.ImageStreamRequestedEventArgs e)
{
var ctrl = Control;
if (ctrl != null)
Expand Down Expand Up @@ -114,7 +114,7 @@ private void OnImageStreamRequested (object sender, SignaturePadView.ImageStream
}
}

private void OnIsBlankRequested (object sender, SignaturePadView.IsBlankRequestedEventArgs e)
private void OnIsBlankRequested (object sender, SignaturePadCanvasView.IsBlankRequestedEventArgs e)
{
var ctrl = Control;
if (ctrl != null)
Expand All @@ -123,7 +123,7 @@ private void OnIsBlankRequested (object sender, SignaturePadView.IsBlankRequeste
}
}

private void OnPointsRequested (object sender, SignaturePadView.PointsEventArgs e)
private void OnPointsRequested (object sender, SignaturePadCanvasView.PointsEventArgs e)
{
var ctrl = Control;
if (ctrl != null)
Expand All @@ -132,7 +132,7 @@ private void OnPointsRequested (object sender, SignaturePadView.PointsEventArgs
}
}

private void OnPointsSpecified (object sender, SignaturePadView.PointsEventArgs e)
private void OnPointsSpecified (object sender, SignaturePadCanvasView.PointsEventArgs e)
{
var ctrl = Control;
if (ctrl != null)
Expand All @@ -141,7 +141,25 @@ private void OnPointsSpecified (object sender, SignaturePadView.PointsEventArgs
}
}

private void OnClearRequested (object sender, System.EventArgs e)
private void OnStrokesRequested (object sender, SignaturePadCanvasView.StrokesEventArgs e)
{
var ctrl = Control;
if (ctrl != null)
{
e.Strokes = ctrl.Strokes.Select (s => s.Select (p => new Point (p.X, p.Y)));
}
}

private void OnStrokesSpecified (object sender, SignaturePadCanvasView.StrokesEventArgs e)
{
var ctrl = Control;
if (ctrl != null)
{
ctrl.LoadStrokes (e.Strokes.Select (s => s.Select (p => new NativePoint ((float)p.X, (float)p.Y)).ToArray ()).ToArray ());
}
}

private void OnClearRequested (object sender, EventArgs e)
{
var ctrl = Control;
if (ctrl != null)
Expand All @@ -160,38 +178,6 @@ private void UpdateAll ()
return;
}

if (Element.BackgroundColor != Color.Default)
{
Control.BackgroundColor = Element.BackgroundColor.ToNative ();
}
if (!string.IsNullOrEmpty (Element.CaptionText))
{
Control.CaptionText = Element.CaptionText;
}
if (Element.CaptionTextColor != Color.Default)
{
Control.Caption.SetTextColor (Element.CaptionTextColor);
}
if (!string.IsNullOrEmpty (Element.ClearText))
{
Control.ClearLabelText = Element.ClearText;
}
if (Element.ClearTextColor != Color.Default)
{
Control.ClearLabel.SetTextColor (Element.ClearTextColor);
}
if (!string.IsNullOrEmpty (Element.PromptText))
{
Control.SignaturePromptText = Element.PromptText;
}
if (Element.PromptTextColor != Color.Default)
{
Control.SignaturePrompt.SetTextColor (Element.PromptTextColor);
}
if (Element.SignatureLineColor != Color.Default)
{
Control.SignatureLineColor = Element.SignatureLineColor.ToNative ();
}
if (Element.StrokeColor != Color.Default)
{
Control.StrokeColor = Element.StrokeColor.ToNative ();
Expand All @@ -212,43 +198,11 @@ private void Update (string property)
return;
}

if (property == SignaturePadView.BackgroundColorProperty.PropertyName)
{
Control.BackgroundColor = Element.BackgroundColor.ToNative ();
}
else if (property == SignaturePadView.CaptionTextProperty.PropertyName)
{
Control.CaptionText = Element.CaptionText;
}
else if (property == SignaturePadView.CaptionTextColorProperty.PropertyName)
{
Control.Caption.SetTextColor (Element.CaptionTextColor);
}
else if (property == SignaturePadView.ClearTextProperty.PropertyName)
{
Control.ClearLabelText = Element.ClearText;
}
else if (property == SignaturePadView.ClearTextColorProperty.PropertyName)
{
Control.ClearLabel.SetTextColor (Element.ClearTextColor);
}
else if (property == SignaturePadView.PromptTextProperty.PropertyName)
{
Control.SignaturePromptText = Element.PromptText;
}
else if (property == SignaturePadView.PromptTextColorProperty.PropertyName)
{
Control.SignaturePrompt.SetTextColor (Element.PromptTextColor);
}
else if (property == SignaturePadView.SignatureLineColorProperty.PropertyName)
{
Control.SignatureLineColor = Element.SignatureLineColor.ToNative ();
}
else if (property == SignaturePadView.StrokeColorProperty.PropertyName)
if (property == SignaturePadCanvasView.StrokeColorProperty.PropertyName)
{
Control.StrokeColor = Element.StrokeColor.ToNative ();
}
else if (property == SignaturePadView.StrokeWidthProperty.PropertyName)
else if (property == SignaturePadCanvasView.StrokeWidthProperty.PropertyName)
{
Control.StrokeWidth = Element.StrokeWidth;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@
<Compile Include="$(MSBuildThisFileDirectory)SignatureImageFormat.cs" />
<Compile Include="$(MSBuildThisFileDirectory)SignaturePadView.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ImageConstructionSettings.cs" />
<Compile Include="$(MSBuildThisFileDirectory)SignaturePadCanvasView.cs" />
</ItemGroup>
</Project>
Loading

0 comments on commit ba653e5

Please sign in to comment.