Apply round corners shape based on radius (#6099)

* Apply round corners shape based on radius

* update gallery

* apply to SmallComponentShape

* add color scheme back

* basic fixes

* - make corner radius default the same
- reapply theme on ios so corner is changeable
- force set ios border width to size

* fix border width for default and remove extra call to bgcolor
This commit is contained in:
Shane Neuville 2019-05-07 10:52:53 -06:00 коммит произвёл GitHub
Родитель a827e30e31
Коммит bfd4ed0f04
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
4 изменённых файлов: 32 добавлений и 20 удалений

Просмотреть файл

@ -147,8 +147,8 @@
</StackLayout>
</Frame>
<Label Text="Default With Border (No Shadow)" Margin="0,0,0,-10" />
<Frame Padding="16" BorderColor="{StaticResource DarkRedColor}" HasShadow="false">
<Label Text="Default With Border (No Shadow, CornerRadius 0)" Margin="0,0,0,-10" />
<Frame CornerRadius="0" Padding="16" BorderColor="{StaticResource DarkRedColor}" HasShadow="false">
<StackLayout Spacing="16">
<Image Source="photo.jpg" Margin="-16,-16,-16,0" Aspect="AspectFit" />
<Label Text="Walk below the arches" FontSize="24" />
@ -158,8 +158,8 @@
</StackLayout>
</Frame>
<Label Text="No Card Padding &amp; Thin Content Padding" Margin="0,0,0,-10" />
<Frame Padding="0" BorderColor="{StaticResource DarkRedColor}" CornerRadius="10">
<Label Text="No Card Padding &amp; Thin Content Padding &amp; CornerRadius 15" Margin="0,0,0,-10" />
<Frame CornerRadius="15" Padding="0" BorderColor="{StaticResource DarkRedColor}">
<StackLayout Spacing="16" BackgroundColor="{StaticResource LightRedColor}" Padding="8">
<Image Source="photo.jpg" Margin="-8,-8,-8,0" Aspect="AspectFit" />
<Label Text="Walk below the arches" FontSize="24" />

Просмотреть файл

@ -40,6 +40,7 @@ namespace Xamarin.Forms.Material.Tizen
public const float SliderTrackAlpha = kSliderBaselineEnabledBackgroundAlpha;
public const double kFrameCornerRadiusDefault = 4;
// values based on
// copying to match iOS
// TODO generalize into xplat classes

Просмотреть файл

@ -191,11 +191,9 @@ namespace Xamarin.Forms.Material.Android
return;
var cornerRadius = Element.CornerRadius;
if (cornerRadius < 0f && _defaultCornerRadius < 0f)
return;
if (_defaultCornerRadius < 0f)
_defaultCornerRadius = Radius;
_defaultCornerRadius = Context.ToPixels(MaterialColors.kFrameCornerRadiusDefault);
if (cornerRadius < 0f)
Radius = _defaultCornerRadius;

Просмотреть файл

@ -15,7 +15,7 @@ namespace Xamarin.Forms.Material.iOS
{
CardScheme _defaultCardScheme;
CardScheme _cardScheme;
nfloat _defaultCornerRadius = -1f;
float _defaultCornerRadius = -1;
VisualElementPackager _packager;
VisualElementTracker _tracker;
bool _disposed = false;
@ -86,9 +86,6 @@ namespace Xamarin.Forms.Material.iOS
Element.PropertyChanged += OnElementPropertyChanged;
UpdateCornerRadius();
UpdateBorderColor();
UpdateBackgroundColor();
ApplyTheme();
}
@ -115,17 +112,21 @@ namespace Xamarin.Forms.Material.iOS
base.Dispose(disposing);
}
protected virtual CardScheme CreateCardScheme()
{
return new CardScheme
{
ColorScheme = MaterialColors.Light.CreateColorScheme(),
ShapeScheme = new ShapeScheme(),
ColorScheme = MaterialColors.Light.CreateColorScheme()
};
}
protected virtual void ApplyTheme()
{
UpdateCornerRadius();
UpdateBorderColor();
UpdateBackgroundColor();
if (Element.BorderColor.IsDefault)
CardThemer.ApplyScheme(_cardScheme, this);
else
@ -150,16 +151,14 @@ namespace Xamarin.Forms.Material.iOS
}
else if (e.PropertyName == Xamarin.Forms.Frame.CornerRadiusProperty.PropertyName)
{
UpdateCornerRadius();
updatedTheme = true;
}
else if (e.PropertyName == Xamarin.Forms.Frame.BorderColorProperty.PropertyName)
{
UpdateBorderColor();
updatedTheme = true;
}
else if (e.PropertyName == VisualElement.BackgroundColorProperty.PropertyName)
{
UpdateBackgroundColor();
updatedTheme = true;
}
@ -173,13 +172,25 @@ namespace Xamarin.Forms.Material.iOS
{
// set the default radius on the first time
if (_defaultCornerRadius < 0)
_defaultCornerRadius = CornerRadius;
_defaultCornerRadius = (float)MaterialColors.kFrameCornerRadiusDefault;
var cornerRadius = Element.CornerRadius;
if (cornerRadius < 0)
CornerRadius = _defaultCornerRadius;
else
CornerRadius = cornerRadius;
cornerRadius = _defaultCornerRadius;
if (_cardScheme != null)
{
var shapeScheme = new ShapeScheme();
var shapeCategory = new ShapeCategory(ShapeCornerFamily.Rounded, cornerRadius);
shapeScheme.SmallComponentShape = shapeCategory;
shapeScheme.MediumComponentShape = shapeCategory;
shapeScheme.LargeComponentShape = shapeCategory;
_cardScheme.ShapeScheme = shapeScheme;
}
CornerRadius = cornerRadius;
}
void UpdateBorderColor()
@ -191,6 +202,8 @@ namespace Xamarin.Forms.Material.iOS
colorScheme.OnSurfaceColor = _defaultCardScheme.ColorScheme.OnSurfaceColor;
else
colorScheme.OnSurfaceColor = borderColor.ToUIColor();
SetBorderWidth(borderColor.IsDefault ? 0f : 1f, UIControlState.Normal);
}
}