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

Fix NRE when using Line on iOS with Xcode 13.2 #14993

Merged
merged 2 commits into from
Jan 10, 2022
Merged
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
22 changes: 18 additions & 4 deletions Xamarin.Forms.Platform.iOS/Shapes/ShapeRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -386,8 +386,18 @@ void BuildRenderPath()
viewBounds.Width -= _strokeWidth;
viewBounds.Height -= _strokeWidth;

nfloat widthScale = viewBounds.Width / _pathFillBounds.Width;
nfloat heightScale = viewBounds.Height / _pathFillBounds.Height;
if (viewBounds.Width < 0)
viewBounds.Width = 0;

if (viewBounds.Height < 0)
viewBounds.Height = 0;

var calculatedWidth = viewBounds.Width / _pathFillBounds.Width;
var calculatedHeight = viewBounds.Height / _pathFillBounds.Height;

nfloat widthScale = nfloat.IsNaN(calculatedWidth) ? 0 : calculatedWidth;
nfloat heightScale = nfloat.IsNaN(calculatedHeight) ? 0 : calculatedHeight;

var stretchTransform = CGAffineTransform.MakeIdentity();

switch (_stretch)
Expand Down Expand Up @@ -441,11 +451,15 @@ void BuildRenderPath()

if (_pathStrokeBounds.Width > Bounds.Width)
width = Bounds.Width - adjustX;
if (_pathStrokeBounds.Height > Bounds.Height)
if (_pathStrokeBounds.Height > Bounds.Height)
height = Bounds.Height - adjustY;

Frame = new CGRect(adjustX, adjustY, width, height);
var transform = new CGAffineTransform(Bounds.Width / width, 0, 0, Bounds.Height / height, -adjustX, -adjustY);

var calculatedWidth = Bounds.Width / width;
var calculatedHeight = Bounds.Height / height;

var transform = new CGAffineTransform(nfloat.IsNaN(calculatedWidth) ? 0 : calculatedWidth, 0, 0, nfloat.IsNaN(calculatedHeight) ? 0: calculatedHeight, -adjustX, -adjustY);
_renderPath = _path.CopyByTransformingPath(transform);
}
else
Expand Down