[Android] Fixes work IsClippedToBounds on (Fast Renderer) Frame (#6358) fixes #3150 fixes #6447

* [Android] Fixes work IsClippedToBounds on (Fast Renderer) Frame
- fixes float values in Dynamic ViewGallery

* added on-screen instructions for test

* added API check

* added SetClipToOutline to ViewExtensions

* added button to toggle IsClippedToBounds
This commit is contained in:
Pavel Yakovlev 2019-06-17 04:43:11 -07:00 коммит произвёл Rui Marinho
Родитель 317f7b7d26
Коммит b8bffb6c79
5 изменённых файлов: 125 добавлений и 9 удалений

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

@ -0,0 +1,48 @@
using Xamarin.Forms.CustomAttributes;
using Xamarin.Forms.Internals;
namespace Xamarin.Forms.Controls.Issues
{
[Preserve(AllMembers = true)]
[Issue(IssueTracker.Github, 3150, "IsClippedToBounds on (Fast Renderer) Frame not working", PlatformAffected.Android)]
class Issue3150 : TestContentPage
{
protected override void Init()
{
const string buttonText = "Toggle IsClippedToBounds: ";
var frame = new Frame
{
BackgroundColor = Color.Blue,
HorizontalOptions = LayoutOptions.CenterAndExpand,
VerticalOptions = LayoutOptions.CenterAndExpand,
IsClippedToBounds = false,
Content = new BoxView
{
BackgroundColor = Color.Yellow,
TranslationX = 50
}
};
Button button = null;
button = new Button()
{
Text = $"{buttonText}{frame.IsClippedToBounds}",
Command = new Command(() =>
{
frame.IsClippedToBounds = !frame.IsClippedToBounds;
button.Text = $"{buttonText}{frame.IsClippedToBounds}";
})
};
Content = new StackLayout
{
Children = {
new Label { Text = "If the yellow box extends past the end of the blue box, the test has passed" },
frame,
button
}
};
}
}
}

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

@ -9,6 +9,7 @@
<Import_RootNamespace>Xamarin.Forms.Controls.Issues</Import_RootNamespace>
</PropertyGroup>
<ItemGroup>
<Compile Include="$(MSBuildThisFileDirectory)Issue3150.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue6262.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla59172.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue6260.cs" />

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

@ -12,6 +12,14 @@ namespace Xamarin.Forms.Controls
internal static Dictionary<string, (Func<object> ctor, NamedAction[] methods)> TestedTypes = new Dictionary<string, (Func<object> ctor, NamedAction[] methods)>
{
{ nameof(ActivityIndicator), (() => new ActivityIndicator() { IsRunning = false }, null) },
{ nameof(Frame), (() => new Frame {
BackgroundColor = Color.Blue,
Content = new BoxView
{
BackgroundColor = Color.Yellow,
TranslationX = 50
}
}, null) },
{ nameof(ProgressBar), (() => new ProgressBar(), null) },
{ nameof(Button), (() => new Button { Text = "Button" }, null) },
{ nameof(Label), (() => new Label { Text = "label" }, null) },
@ -142,7 +150,9 @@ namespace Xamarin.Forms.Controls
}
else if (property.PropertyType == typeof(double) ||
property.PropertyType == typeof(float) ||
property.PropertyType == typeof(int))
property.PropertyType == typeof(int) ||
property.PropertyType == typeof(uint) ||
property.PropertyType == typeof(long))
{
propertyLayout.Children.Add(
CreateValuePicker(property, bindableProperties.FirstOrDefault(p => p.PropertyName == property.Name), element));
@ -225,8 +235,30 @@ namespace Xamarin.Forms.Controls
max = _minMaxProperties[property.Name].max;
}
var isInt = property.PropertyType == typeof(int);
var value = isInt ? (int)property.GetValue(element) : (double)property.GetValue(element);
var stringFormat = "0";
var objectValue = property.GetValue(element);
double value = 0;
switch (objectValue)
{
case int i:
value = i;
break;
case uint ui:
value = ui;
break;
case long l:
value = l;
break;
case float f:
value = f;
stringFormat += ".#";
break;
case double d:
value = d;
stringFormat += ".#";
break;
}
var slider = new Slider(min, max, value);
var actions = new Grid
@ -260,17 +292,31 @@ namespace Xamarin.Forms.Controls
var valueLabel = new Label
{
Text = slider.Value.ToString(isInt ? "0" : "0.#"),
Text = slider.Value.ToString(stringFormat),
HorizontalOptions = LayoutOptions.End
};
slider.ValueChanged += (_, e) =>
{
if (isInt)
property.SetValue(element, (int)e.NewValue);
else
property.SetValue(element, e.NewValue);
valueLabel.Text = e.NewValue.ToString(isInt ? "0" : "0.#");
switch (objectValue)
{
case int i:
property.SetValue(element, (int)e.NewValue);
break;
case uint ui:
property.SetValue(element, (uint)e.NewValue);
break;
case long l:
property.SetValue(element, (long)e.NewValue);
break;
case float f:
property.SetValue(element, (float)e.NewValue);
break;
case double d:
property.SetValue(element, e.NewValue);
break;
}
valueLabel.Text = e.NewValue.ToString(stringFormat);
};
actions.AddChild(slider, 0, 1);

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

@ -191,6 +191,7 @@ namespace Xamarin.Forms.Platform.Android.FastRenderers
UpdateBackgroundColor();
UpdateCornerRadius();
UpdateBorderColor();
UpdateClippedToBounds();
ElevationHelper.SetElevation(this, e.NewElement);
}
@ -234,8 +235,12 @@ namespace Xamarin.Forms.Platform.Android.FastRenderers
UpdateCornerRadius();
else if (e.PropertyName == Frame.BorderColorProperty.PropertyName)
UpdateBorderColor();
else if (e.Is(Xamarin.Forms.Layout.IsClippedToBoundsProperty))
UpdateClippedToBounds();
}
void UpdateClippedToBounds() => this.SetClipToOutline(Element.IsClippedToBounds);
void UpdateBackgroundColor()
{
if (_disposed)

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

@ -77,5 +77,21 @@ namespace Xamarin.Forms.Platform.Android
view.Id = Platform.GenerateViewId();
}
}
public static bool GetClipToOutline(this AView view)
{
if (view.IsDisposed() || !Forms.IsLollipopOrNewer)
return false;
return view.ClipToOutline;
}
public static void SetClipToOutline(this AView view, bool value)
{
if (view.IsDisposed() || !Forms.IsLollipopOrNewer)
return;
view.ClipToOutline = value;
}
}
}