-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement Padding in ILabel Handlers #421
Conversation
@@ -33,6 +33,7 @@ void SetupMauiLayout() | |||
verticalStack.Add(new Label { Text = "This should be BIG text!", FontSize = 24 }); | |||
verticalStack.Add(new Label { Text = "This should be BOLD text!", FontAttributes = FontAttributes.Bold }); | |||
verticalStack.Add(new Label { Text = "This should be a CUSTOM font!", FontFamily = "Dokdo" }); | |||
verticalStack.Add(new Label { Text = "This should have padding", Padding = new Thickness(40), BackgroundColor = Color.LightBlue }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adds an example of the property to the sample project.
@@ -2,5 +2,6 @@ namespace Microsoft.Maui | |||
{ | |||
public interface ILabel : IView, IText, IFont | |||
{ | |||
Thickness Padding { get; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adds the property to the interface.
{ | ||
handler.TypedNativeView?.UpdatePadding(label); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a mapping method to the Android aspect of the handler.
@@ -11,5 +11,6 @@ public partial class LabelHandler : AbstractViewHandler<ILabel, object> | |||
public static void MapFontFamily(LabelHandler handler, ILabel label) { } | |||
public static void MapFontSize(LabelHandler handler, ILabel label) { } | |||
public static void MapFontAttributes(LabelHandler handler, ILabel label) { } | |||
public static void MapPadding(LabelHandler handler, ILabel label) { } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a mapping method to the Standard aspect of the handler; the Standard aspect is just a placeholder and is never actually called.
@@ -9,6 +9,7 @@ public partial class LabelHandler | |||
[nameof(ILabel.FontFamily)] = MapFontFamily, | |||
[nameof(ILabel.FontSize)] = MapFontSize, | |||
[nameof(ILabel.FontAttributes)] = MapFontAttributes, | |||
[nameof(ILabel.Padding)] = MapPadding, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add the mapping to the PropertyMapper for the handler.
{ | ||
handler.TypedNativeView?.UpdatePadding(label); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a mapping method to the iOS aspect of the handler.
(int)context.ToPixels(label.Padding.Top), | ||
(int)context.ToPixels(label.Padding.Right), | ||
(int)context.ToPixels(label.Padding.Bottom)); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add an extension method to handle the actual update for the native Android control. This logic is ported directly from the Forms Label renderer for Android.
public static void UpdatePadding(this object nothing, ILabel label) | ||
{ | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The placeholder extension method for Standard; this is never actually called.
(float)label.Padding.Bottom, | ||
(float)label.Padding.Right); | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add an extension method to handle the actual update for the native iOS control. This logic is ported directly from the Forms Label renderer for iOS.
width: size.Width + TextInsets.Left + TextInsets.Right, | ||
height: size.Height + TextInsets.Top + TextInsets.Bottom); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For this particular property, we needed to extend the UILabel class with some custom logic because Padding doesn't exist natively. This class was ported from the Forms iOS platform project.
Assert.Equal(expectedRight, right); | ||
Assert.Equal(expectedBottom, bottom); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adds an on-device test to verify that the property is being set on the native Android control. This test will be run on an Android device as part of the CI process.
Assert.Equal(15, insets.Right); | ||
Assert.Equal(20, insets.Bottom); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adds an on-device test to verify that the property is being set on the native iOS control. This test will be run on an iOS device as part of the CI process.
@@ -11,5 +11,7 @@ public partial class LabelStub : StubBase, ILabel | |||
public string FontFamily { get; set; } | |||
|
|||
public double FontSize { get; set; } | |||
|
|||
public Thickness Padding { get; set; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The stub classes are implementations of the MAUI interfaces used for on-device testing.
Implements #369
Thickness Padding { get; }
to theILabel
interface