Skip to content

Commit

Permalink
Hidden ListView doesn't appear as expected - fix
Browse files Browse the repository at this point in the history
  • Loading branch information
kubaflo authored and rmarinho committed Feb 12, 2025
1 parent 771462d commit 7887b21
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,8 @@ protected override void OnElementPropertyChanged(object sender, PropertyChangedE
UpdateHorizontalScrollBarVisibility();
else if (e.PropertyName == ScrollView.VerticalScrollBarVisibilityProperty.PropertyName)
UpdateVerticalScrollBarVisibility();
else if (e.PropertyName == ListView.IsVisibleProperty.PropertyName)
UpdateVisibility();
}

/*
Expand Down Expand Up @@ -541,6 +543,17 @@ void UpdateHorizontalScrollBarVisibility()
Control.HorizontalScrollBarEnabled = newHorizontalScrollVisiblility == ScrollBarVisibility.Always;
}

private void UpdateVisibility()
{
if (Element.IsVisible)
{
if (Element.Parent is View parent)
{
parent.InvalidateMeasure();
}
}
}

void UpdateVerticalScrollBarVisibility()
{
if (_defaultVerticalScrollVisibility == 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,8 @@ protected override void OnElementPropertyChanged(object sender, PropertyChangedE
UpdateVerticalScrollBarVisibility();
else if (e.PropertyName == ScrollView.HorizontalScrollBarVisibilityProperty.PropertyName)
UpdateHorizontalScrollBarVisibility();
else if (e.PropertyName == ListView.IsVisibleProperty.PropertyName)
UpdateVisibility();
}

public override void TraitCollectionDidChange(UITraitCollection previousTraitCollection)
Expand Down Expand Up @@ -494,6 +496,17 @@ void UpdateFooter()
}
}

private void UpdateVisibility()
{
if (Element.IsVisible)
{
if (Element.Parent is View parent)
{
parent.InvalidateMeasure();
}
}
}

void UpdateHeader()
{
var header = ListView.HeaderElement;
Expand Down
36 changes: 36 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue27630.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
namespace Maui.Controls.Sample.Issues
{
[Issue(IssueTracker.Github, 27630, "Hidden ListView doesn't appear as expected", PlatformAffected.iOS | PlatformAffected.Android)]
public class Issue27630 : TestContentPage
{
protected override void Init()
{
var listView = new ListView
{
HeightRequest = 100,
IsVisible = false,
ItemTemplate = new DataTemplate(() => new ViewCell()
{
View = new Label()
{
Text = "Hello",
AutomationId = "ViewCellLabel"
}
}),
ItemsSource = new string[] { "Item 1", "Item 2", "Item 3" }
};

var button = new Button
{
Text = "Show/Hide ListView",
AutomationId = "Button",
Command = new Command(() => listView.IsVisible = !listView.IsVisible)
};

Content = new VerticalStackLayout()
{
Children = { button, listView }
};
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#if ANDROID || IOS
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Issues
{
public class Issue27630 : _IssuesUITest
{
public Issue27630(TestDevice testDevice) : base(testDevice)
{
}

public override string Issue => "Hidden ListView doesn't appear as expected";

[Test]
[Category(UITestCategories.ListView)]
public void ListViewShouldBeVisible()
{
App.WaitForElement("Button");
App.Click("Button");
App.WaitForElement("ViewCellLabel");
}
}
}
#endif

0 comments on commit 7887b21

Please sign in to comment.