diff --git a/Xamarin.Forms.Platform.iOS/Shapes/ShapeRenderer.cs b/Xamarin.Forms.Platform.iOS/Shapes/ShapeRenderer.cs index 89b2add418d..4386da30bfc 100644 --- a/Xamarin.Forms.Platform.iOS/Shapes/ShapeRenderer.cs +++ b/Xamarin.Forms.Platform.iOS/Shapes/ShapeRenderer.cs @@ -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) @@ -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