Skip to content
This repository was archived by the owner on May 1, 2024. It is now read-only.

Commit ed86ce6

Browse files
authored
Make Frames with Labels work in ListViews again (#11976)
1 parent 651b275 commit ed86ce6

File tree

4 files changed

+36
-54
lines changed

4 files changed

+36
-54
lines changed

Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue7823.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public class Issue7823 : TestContentPage
2727

2828
protected override void Init()
2929
{
30-
var frameClippedToBouds = new Frame
30+
var frameClippedToBounds = new Frame
3131
{
3232
AutomationId = SecondaryFrame,
3333
CornerRadius = 10,
@@ -53,16 +53,16 @@ protected override void Init()
5353
CornerRadius = 5,
5454
BackgroundColor = Color.Red,
5555
Padding = 10,
56-
Content = frameClippedToBouds
56+
Content = frameClippedToBounds
5757
},
5858
new Button
5959
{
6060
AutomationId = SetClipBounds,
6161
Text = "Manually set Frame.IsClippedToBounds = false",
6262
Command = new Command(()=>
6363
{
64-
frameClippedToBouds.IsClippedToBounds = false;
65-
frameClippedToBouds.CornerRadius = 11;
64+
frameClippedToBounds.IsClippedToBounds = false;
65+
frameClippedToBounds.CornerRadius = 11;
6666
})
6767
}
6868
}

Xamarin.Forms.Platform.Android/FastRenderers/FrameRenderer.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,6 @@ protected virtual void OnElementPropertyChanged(object sender, PropertyChangedEv
246246
return;
247247
}
248248

249-
250249
if (e.PropertyName == Frame.HasShadowProperty.PropertyName)
251250
UpdateShadow();
252251
else if (e.PropertyName == VisualElement.BackgroundColorProperty.PropertyName)
@@ -263,7 +262,10 @@ protected virtual void OnElementPropertyChanged(object sender, PropertyChangedEv
263262

264263
void UpdateClippedToBounds()
265264
{
266-
this.SetClipToOutline(Element.IsClippedToBounds, Element);
265+
var shouldClip = Element.IsSet(Xamarin.Forms.Layout.IsClippedToBoundsProperty)
266+
? Element.IsClippedToBounds : Element.CornerRadius > 0f;
267+
268+
this.SetClipToOutline(shouldClip);
267269
}
268270

269271
void UpdateBackgroundColor()

Xamarin.Forms.Platform.Android/ViewExtensions.cs

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -97,53 +97,6 @@ public static void SetClipToOutline(this AView view, bool value)
9797
view.ClipToOutline = value;
9898
}
9999

100-
public static void SetClipToOutline(this AView view, bool value, VisualElement element)
101-
{
102-
if (view.IsDisposed())
103-
return;
104-
105-
var shouldClip = value;
106-
if (element is Frame frame)
107-
{
108-
shouldClip = frame.IsSet(Layout.IsClippedToBoundsProperty)
109-
? frame.IsClippedToBounds : frame.CornerRadius > 0f;
110-
}
111-
112-
if (view is FastRenderers.FrameRenderer && Forms.IsLollipopOrNewer)
113-
{
114-
view.SetClipToOutline(shouldClip);
115-
return;
116-
}
117-
118-
// setClipBounds is only available in API 18 +
119-
if ((int)Build.VERSION.SdkInt >= 18)
120-
{
121-
if (!(view is ViewGroup viewGroup))
122-
{
123-
return;
124-
}
125-
126-
// Forms layouts should not impose clipping on their children
127-
viewGroup.SetClipChildren(false);
128-
129-
// But if IsClippedToBounds is true, they _should_ enforce clipping at their own edges
130-
viewGroup.ClipBounds = shouldClip ? new ARect(0, 0, viewGroup.Width, viewGroup.Height) : null;
131-
}
132-
else
133-
{
134-
// For everything in 17 and below, use the setClipChildren method
135-
if (!(view.Parent is ViewGroup parent))
136-
return;
137-
138-
if ((int)Build.VERSION.SdkInt >= 18 && parent.ClipChildren == shouldClip)
139-
return;
140-
141-
parent.SetClipChildren(shouldClip);
142-
parent.Invalidate();
143-
}
144-
}
145-
146-
147100
public static bool SetElevation(this AView view, float value)
148101
{
149102
if (view.IsDisposed() || !Forms.IsLollipopOrNewer)

Xamarin.Forms.Platform.Android/VisualElementTracker.cs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,34 @@ void UpdateClipToBounds()
291291
return;
292292
}
293293

294-
_renderer.View.SetClipToOutline(layout.IsClippedToBounds, _renderer.Element);
294+
bool shouldClip = layout.IsClippedToBounds;
295+
296+
// setClipBounds is only available in API 18 +
297+
if ((int)Forms.SdkInt >= 18)
298+
{
299+
if (!(_renderer.View is ViewGroup viewGroup))
300+
{
301+
return;
302+
}
303+
304+
// Forms layouts should not impose clipping on their children
305+
viewGroup.SetClipChildren(false);
306+
307+
// But if IsClippedToBounds is true, they _should_ enforce clipping at their own edges
308+
viewGroup.ClipBounds = shouldClip ? new global::Android.Graphics.Rect(0, 0, viewGroup.Width, viewGroup.Height) : null;
309+
}
310+
else
311+
{
312+
// For everything in 17 and below, use the setClipChildren method
313+
if (!(_renderer.View.Parent is ViewGroup parent))
314+
return;
315+
316+
if ((int)Forms.SdkInt >= 18 && parent.ClipChildren == shouldClip)
317+
return;
318+
319+
parent.SetClipChildren(shouldClip);
320+
parent.Invalidate();
321+
}
295322
}
296323

297324
void UpdateClip()

0 commit comments

Comments
 (0)