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
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ protected override void OnElementChanged(ElementChangedEventArgs<DrawingView> e)

protected override void OnSizeChanged(int w, int h, int oldw, int oldh)
{
const int minW = 1;
const int minH = 1;
w = w < minW ? minW : w;
h = h < minH ? minH : h;
base.OnSizeChanged(w, h, oldw, oldh);

canvasBitmap = Bitmap.CreateBitmap(w, h, Bitmap.Config.Argb8888!)!;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ protected override void OnElementPropertyChanged(object sender, PropertyChangedE

public override void TouchesBegan(NSSet touches, UIEvent? evt)
{
SetParentTouches(false);

Element.Points.CollectionChanged -= OnPointsCollectionChanged;
Element.Points.Clear();
currentPath.RemoveAllPoints();
Expand All @@ -65,16 +67,6 @@ public override void TouchesMoved(NSSet touches, UIEvent? evt)
AddPointToPath(currentPoint);
}

void AddPointToPath(CGPoint currentPoint)
{
currentPath.AddLineTo(currentPoint);
SetNeedsDisplay();
Element.Points.CollectionChanged -= OnPointsCollectionChanged;
var point = currentPoint.ToPoint();
Element.Points.Add(point);
Element.Points.CollectionChanged += OnPointsCollectionChanged;
}

public override void TouchesEnded(NSSet touches, UIEvent? evt)
{
UpdatePath();
Expand All @@ -86,16 +78,32 @@ public override void TouchesEnded(NSSet touches, UIEvent? evt)

if (Element.ClearOnFinish)
Element.Points.Clear();

SetParentTouches(true);
}

public override void TouchesCancelled(NSSet touches, UIEvent? evt) => InvokeOnMainThread(SetNeedsDisplay);
public override void TouchesCancelled(NSSet touches, UIEvent? evt)
{
InvokeOnMainThread(SetNeedsDisplay);
SetParentTouches(true);
}

public override void Draw(CGRect rect)
{
lineColor!.SetStroke();
currentPath.Stroke();
}

void AddPointToPath(CGPoint currentPoint)
{
currentPath.AddLineTo(currentPoint);
SetNeedsDisplay();
Element.Points.CollectionChanged -= OnPointsCollectionChanged;
var point = currentPoint.ToPoint();
Element.Points.Add(point);
Element.Points.CollectionChanged += OnPointsCollectionChanged;
}

void LoadPoints()
{
var stylusPoints = Element.Points.Select(point => new CGPoint(point.X, point.Y)).ToList();
Expand Down Expand Up @@ -211,5 +219,18 @@ protected override void Dispose(bool disposing)

base.Dispose(disposing);
}

void SetParentTouches(bool enabled)
{
var parent = Superview;

while (parent != null)
{
if (parent.GetType() == typeof(ScrollViewRenderer))
((ScrollViewRenderer)parent).ScrollEnabled = enabled;

parent = parent.Superview;
}
}
}
}