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

Commit

Permalink
Fix NRE when using Line on iOS with Xcode 13.2 (#14993)
Browse files Browse the repository at this point in the history
* Update ShapeRenderer.cs

* Update ShapeRenderer.cs
  • Loading branch information
jfversluis authored Jan 10, 2022
1 parent d59f34f commit 67b6d29
Showing 1 changed file with 18 additions and 4 deletions.
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

0 comments on commit 67b6d29

Please sign in to comment.