Make Frames with Labels work in ListViews again (#11976)
This commit is contained in:
Родитель
651b27552a
Коммит
ed86ce6280
|
@ -27,7 +27,7 @@ namespace Xamarin.Forms.Controls.Issues
|
|||
|
||||
protected override void Init()
|
||||
{
|
||||
var frameClippedToBouds = new Frame
|
||||
var frameClippedToBounds = new Frame
|
||||
{
|
||||
AutomationId = SecondaryFrame,
|
||||
CornerRadius = 10,
|
||||
|
@ -53,7 +53,7 @@ namespace Xamarin.Forms.Controls.Issues
|
|||
CornerRadius = 5,
|
||||
BackgroundColor = Color.Red,
|
||||
Padding = 10,
|
||||
Content = frameClippedToBouds
|
||||
Content = frameClippedToBounds
|
||||
},
|
||||
new Button
|
||||
{
|
||||
|
@ -61,8 +61,8 @@ namespace Xamarin.Forms.Controls.Issues
|
|||
Text = "Manually set Frame.IsClippedToBounds = false",
|
||||
Command = new Command(()=>
|
||||
{
|
||||
frameClippedToBouds.IsClippedToBounds = false;
|
||||
frameClippedToBouds.CornerRadius = 11;
|
||||
frameClippedToBounds.IsClippedToBounds = false;
|
||||
frameClippedToBounds.CornerRadius = 11;
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -246,7 +246,6 @@ namespace Xamarin.Forms.Platform.Android.FastRenderers
|
|||
return;
|
||||
}
|
||||
|
||||
|
||||
if (e.PropertyName == Frame.HasShadowProperty.PropertyName)
|
||||
UpdateShadow();
|
||||
else if (e.PropertyName == VisualElement.BackgroundColorProperty.PropertyName)
|
||||
|
@ -263,7 +262,10 @@ namespace Xamarin.Forms.Platform.Android.FastRenderers
|
|||
|
||||
void UpdateClippedToBounds()
|
||||
{
|
||||
this.SetClipToOutline(Element.IsClippedToBounds, Element);
|
||||
var shouldClip = Element.IsSet(Xamarin.Forms.Layout.IsClippedToBoundsProperty)
|
||||
? Element.IsClippedToBounds : Element.CornerRadius > 0f;
|
||||
|
||||
this.SetClipToOutline(shouldClip);
|
||||
}
|
||||
|
||||
void UpdateBackgroundColor()
|
||||
|
|
|
@ -97,53 +97,6 @@ namespace Xamarin.Forms.Platform.Android
|
|||
view.ClipToOutline = value;
|
||||
}
|
||||
|
||||
public static void SetClipToOutline(this AView view, bool value, VisualElement element)
|
||||
{
|
||||
if (view.IsDisposed())
|
||||
return;
|
||||
|
||||
var shouldClip = value;
|
||||
if (element is Frame frame)
|
||||
{
|
||||
shouldClip = frame.IsSet(Layout.IsClippedToBoundsProperty)
|
||||
? frame.IsClippedToBounds : frame.CornerRadius > 0f;
|
||||
}
|
||||
|
||||
if (view is FastRenderers.FrameRenderer && Forms.IsLollipopOrNewer)
|
||||
{
|
||||
view.SetClipToOutline(shouldClip);
|
||||
return;
|
||||
}
|
||||
|
||||
// setClipBounds is only available in API 18 +
|
||||
if ((int)Build.VERSION.SdkInt >= 18)
|
||||
{
|
||||
if (!(view is ViewGroup viewGroup))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Forms layouts should not impose clipping on their children
|
||||
viewGroup.SetClipChildren(false);
|
||||
|
||||
// But if IsClippedToBounds is true, they _should_ enforce clipping at their own edges
|
||||
viewGroup.ClipBounds = shouldClip ? new ARect(0, 0, viewGroup.Width, viewGroup.Height) : null;
|
||||
}
|
||||
else
|
||||
{
|
||||
// For everything in 17 and below, use the setClipChildren method
|
||||
if (!(view.Parent is ViewGroup parent))
|
||||
return;
|
||||
|
||||
if ((int)Build.VERSION.SdkInt >= 18 && parent.ClipChildren == shouldClip)
|
||||
return;
|
||||
|
||||
parent.SetClipChildren(shouldClip);
|
||||
parent.Invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static bool SetElevation(this AView view, float value)
|
||||
{
|
||||
if (view.IsDisposed() || !Forms.IsLollipopOrNewer)
|
||||
|
|
|
@ -291,7 +291,34 @@ namespace Xamarin.Forms.Platform.Android
|
|||
return;
|
||||
}
|
||||
|
||||
_renderer.View.SetClipToOutline(layout.IsClippedToBounds, _renderer.Element);
|
||||
bool shouldClip = layout.IsClippedToBounds;
|
||||
|
||||
// setClipBounds is only available in API 18 +
|
||||
if ((int)Forms.SdkInt >= 18)
|
||||
{
|
||||
if (!(_renderer.View is ViewGroup viewGroup))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Forms layouts should not impose clipping on their children
|
||||
viewGroup.SetClipChildren(false);
|
||||
|
||||
// But if IsClippedToBounds is true, they _should_ enforce clipping at their own edges
|
||||
viewGroup.ClipBounds = shouldClip ? new global::Android.Graphics.Rect(0, 0, viewGroup.Width, viewGroup.Height) : null;
|
||||
}
|
||||
else
|
||||
{
|
||||
// For everything in 17 and below, use the setClipChildren method
|
||||
if (!(_renderer.View.Parent is ViewGroup parent))
|
||||
return;
|
||||
|
||||
if ((int)Forms.SdkInt >= 18 && parent.ClipChildren == shouldClip)
|
||||
return;
|
||||
|
||||
parent.SetClipChildren(shouldClip);
|
||||
parent.Invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
void UpdateClip()
|
||||
|
|
Загрузка…
Ссылка в новой задаче