-
Notifications
You must be signed in to change notification settings - Fork 343
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Fixed code for Issue #1160 * Changed how to refer to Subviews * Revert and deprecate RoundedStackView
- Loading branch information
Showing
3 changed files
with
91 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
src/CommunityToolkit.Maui.Core/Views/RoundedView.macios.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
using System.Runtime.InteropServices; | ||
using CoreAnimation; | ||
|
||
namespace CommunityToolkit.Maui.Core.Views; | ||
|
||
/// <summary> | ||
/// A rounded <see cref="UIView"/> | ||
/// </summary> | ||
public class RoundedView : UIView | ||
{ | ||
/// <summary> | ||
/// Initialize <see cref="RoundedView"/> | ||
/// </summary> | ||
public RoundedView(NFloat leftPadding, NFloat topPadding, NFloat rightPadding, NFloat bottomPadding) | ||
{ | ||
LeftPadding = leftPadding; | ||
TopPadding = topPadding; | ||
RightPadding = rightPadding; | ||
BottomPadding = bottomPadding; | ||
} | ||
|
||
/// <summary> | ||
/// Left Padding | ||
/// </summary> | ||
public NFloat LeftPadding { get; } | ||
|
||
/// <summary> | ||
/// Top Padding | ||
/// </summary> | ||
public NFloat TopPadding { get; } | ||
|
||
/// <summary> | ||
/// Right Padding | ||
/// </summary> | ||
public NFloat RightPadding { get; } | ||
|
||
/// <summary> | ||
/// Bottom Padding | ||
/// </summary> | ||
public NFloat BottomPadding { get; } | ||
|
||
/// <inheritdoc /> | ||
public override void Draw(CGRect rect) | ||
{ | ||
ClipsToBounds = true; | ||
|
||
var path = GetRoundedPath(rect, LeftPadding, TopPadding, RightPadding, BottomPadding); | ||
var maskLayer = new CAShapeLayer | ||
{ | ||
Frame = rect, | ||
Path = path | ||
}; | ||
|
||
Layer.Mask = maskLayer; | ||
Layer.MasksToBounds = true; | ||
} | ||
|
||
static CGPath? GetRoundedPath(CGRect rect, NFloat left, NFloat top, NFloat right, NFloat bottom) | ||
{ | ||
var path = new UIBezierPath(); | ||
path.MoveTo(new CGPoint(rect.Width - right, rect.Y)); | ||
|
||
path.AddArc(new CGPoint(rect.X + rect.Width - right, rect.Y + right), right, (NFloat)(Math.PI * 1.5), (NFloat)Math.PI * 2, true); | ||
path.AddLineTo(new CGPoint(rect.Width, rect.Height - bottom)); | ||
|
||
path.AddArc(new CGPoint(rect.X + rect.Width - bottom, rect.Y + rect.Height - bottom), bottom, 0, (NFloat)(Math.PI * .5), true); | ||
path.AddLineTo(new CGPoint(left, rect.Height)); | ||
|
||
path.AddArc(new CGPoint(rect.X + left, rect.Y + rect.Height - left), left, (NFloat)(Math.PI * .5), (NFloat)Math.PI, true); | ||
path.AddLineTo(new CGPoint(rect.X, top)); | ||
|
||
path.AddArc(new CGPoint(rect.X + top, rect.Y + top), top, (NFloat)Math.PI, (NFloat)(Math.PI * 1.5), true); | ||
|
||
path.ClosePath(); | ||
|
||
return path.CGPath; | ||
} | ||
} |