Skip to content

Commit bfd3c34

Browse files
authored
Shadows & Gradients don't work with a list view's header/footer - fix (#26637)
* Shadows & Gradients don't work with a list view's header/footer - fix * Added snapshots
1 parent fd40f04 commit bfd3c34

File tree

7 files changed

+100
-13
lines changed

7 files changed

+100
-13
lines changed

src/Controls/src/Core/Compatibility/Handlers/ListView/Android/ListViewRenderer.cs

+9-7
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,8 @@ internal sealed class Container : ViewGroup
558558
{
559559
IPlatformViewHandler _child;
560560

561+
AView _platformView => _child?.ToPlatform() ?? _child?.PlatformView;
562+
561563
public Container(Context context) : base(context)
562564
{
563565
}
@@ -567,35 +569,35 @@ public IPlatformViewHandler Child
567569
set
568570
{
569571
if (_child != null)
570-
RemoveView(_child.PlatformView);
572+
RemoveView(_platformView);
571573

572574
_child = value;
573575

574576
if (value != null)
575-
AddView(value.PlatformView);
577+
AddView(_platformView);
576578
}
577579
}
578580

579581
protected override void OnLayout(bool changed, int l, int t, int r, int b)
580582
{
581-
if (_child?.PlatformView == null)
583+
if (_platformView == null)
582584
{
583585
return;
584586
}
585587

586-
_child.PlatformView.Layout(0, 0, r - l, b - t);
588+
_platformView.Layout(0, 0, r - l, b - t);
587589
}
588590

589591
protected override void OnMeasure(int widthMeasureSpec, int heightMeasureSpec)
590592
{
591-
if (_child?.PlatformView == null)
593+
if (_platformView == null)
592594
{
593595
SetMeasuredDimension(0, 0);
594596
return;
595597
}
596598

597-
_child.PlatformView.Measure(widthMeasureSpec, heightMeasureSpec);
598-
SetMeasuredDimension(_child.PlatformView.MeasuredWidth, _child.PlatformView.MeasuredHeight);
599+
_platformView.Measure(widthMeasureSpec, heightMeasureSpec);
600+
SetMeasuredDimension(_platformView.MeasuredWidth, _platformView.MeasuredHeight);
599601
}
600602
}
601603

src/Controls/src/Core/Compatibility/Handlers/ListView/iOS/ListViewRenderer.cs

+6-6
Original file line numberDiff line numberDiff line change
@@ -360,14 +360,14 @@ void UpdateFooterMeasure()
360360

361361
var size = _footerRenderer.VirtualView.Measure(Bounds.Width, double.PositiveInfinity);
362362
var platformFrame = new RectangleF(0, 0, size.Width, size.Height);
363-
_footerRenderer.PlatformView.Frame = platformFrame;
363+
_footerRenderer.ToPlatform().Frame = platformFrame;
364364
_footerRenderer.VirtualView.Arrange(platformFrame.ToRectangle());
365-
Control.TableFooterView = _footerRenderer.PlatformView;
365+
Control.TableFooterView = _footerRenderer.ToPlatform();
366366

367367
BeginInvokeOnMainThread(() =>
368368
{
369369
if (_footerRenderer != null)
370-
Control.TableFooterView = _footerRenderer.PlatformView;
370+
Control.TableFooterView = _footerRenderer.ToPlatform();
371371
});
372372
}
373373

@@ -380,9 +380,9 @@ void UpdateHeaderMeasure()
380380

381381
var size = _headerRenderer.VirtualView.Measure(Bounds.Width, double.PositiveInfinity);
382382
var platformFrame = new RectangleF(0, 0, size.Width, size.Height);
383-
_headerRenderer.PlatformView.Frame = platformFrame;
383+
_headerRenderer.ToPlatform().Frame = platformFrame;
384384
_headerRenderer.VirtualView.Arrange(platformFrame.ToRectangle());
385-
Control.TableHeaderView = _headerRenderer.PlatformView;
385+
Control.TableHeaderView = _headerRenderer.ToPlatform();
386386

387387
// Time for another story with Jason. Gather round children because the following Math.Ceiling will look like it's completely useless.
388388
// You will remove it and test and find everything is fiiiiiine, but it is not fine, no it is far from fine. See iOS, or at least iOS 8
@@ -395,7 +395,7 @@ void UpdateHeaderMeasure()
395395
BeginInvokeOnMainThread(() =>
396396
{
397397
if (_headerRenderer != null)
398-
Control.TableHeaderView = _headerRenderer.PlatformView;
398+
Control.TableHeaderView = _headerRenderer.ToPlatform();
399399
});
400400
}
401401

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ContentPage
3+
xmlns:controls="clr-namespace:Maui.Controls.Sample.Issues"
4+
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
5+
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
6+
x:Class="Maui.Controls.Sample.Issues.Issue26636">
7+
<StackLayout>
8+
<ListView
9+
VerticalOptions="Center"
10+
HeightRequest="300">
11+
<ListView.Header>
12+
<Label
13+
FontSize="16"
14+
AutomationId="HeaderLabel"
15+
HorizontalTextAlignment="Center"
16+
Text="(Header) This is a border with shadows">
17+
<Label.Background>
18+
<LinearGradientBrush
19+
StartPoint="0, 0"
20+
EndPoint="1, 1">
21+
<LinearGradientBrush.GradientStops>
22+
<GradientStop Color="#8A2387"
23+
Offset="0.1"/>
24+
<GradientStop Color="#E94057"
25+
Offset="0.6"/>
26+
<GradientStop Color="#F27121"
27+
Offset="1.0"/>
28+
</LinearGradientBrush.GradientStops>
29+
</LinearGradientBrush>
30+
</Label.Background>
31+
</Label>
32+
</ListView.Header>
33+
<ListView.Footer>
34+
<Label
35+
FontSize="16"
36+
HorizontalTextAlignment="Center"
37+
Text="(Footer) This is a label with shadows">
38+
<Label.Shadow>
39+
<Shadow
40+
Brush="Green"
41+
Radius="4"
42+
Offset="0,4"/>
43+
</Label.Shadow>
44+
</Label>
45+
</ListView.Footer>
46+
</ListView>
47+
</StackLayout>
48+
</ContentPage>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
namespace Maui.Controls.Sample.Issues
2+
{
3+
4+
[Issue(IssueTracker.Github, 26636, "Shadows & Gradients don't work with a list view's header/footer", PlatformAffected.Android | PlatformAffected.iOS)]
5+
public partial class Issue26636 : ContentPage
6+
{
7+
public Issue26636()
8+
{
9+
InitializeComponent();
10+
}
11+
}
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#if ANDROID || IOS
2+
using NUnit.Framework;
3+
using UITest.Appium;
4+
using UITest.Core;
5+
6+
namespace Microsoft.Maui.TestCases.Tests.Issues
7+
{
8+
public class Issue26636 : _IssuesUITest
9+
{
10+
public Issue26636(TestDevice testDevice) : base(testDevice)
11+
{
12+
}
13+
14+
public override string Issue => "Shadows & Gradients don't work with a list view's header/footer";
15+
16+
[Test]
17+
[Category(UITestCategories.ListView)]
18+
public void GradientAndShadowShouldWork()
19+
{
20+
App.WaitForElement("HeaderLabel");
21+
VerifyScreenshot();
22+
}
23+
}
24+
}
25+
#endif
Loading

0 commit comments

Comments
 (0)