Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Trigger remeasure when constraints on CV changes (#22270)
- Loading branch information
Showing
5 changed files
with
282 additions
and
21 deletions.
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
src/Controls/samples/Controls.Sample.UITests/Issues/Issue21967.xaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" | ||
x:Class="Maui.Controls.Sample.Issues.Issue21967" | ||
Title="Issue21967"> | ||
<Grid | ||
RowDefinitions="Auto,Auto,Auto,*" | ||
RowSpacing="8" | ||
Margin="8"> | ||
|
||
<Label Grid.Row="0" Text="Click the resize button and elements in the CV should resize."> | ||
</Label> | ||
|
||
<Button | ||
Grid.Row="1" | ||
Text="Set to Full Size" | ||
AutomationId="FullSize" | ||
x:Name="buttonFullSize" | ||
HorizontalOptions="Center" | ||
VerticalOptions="Center"/> | ||
|
||
<Button | ||
Grid.Row="2" | ||
Text="Resize" | ||
AutomationId="Resize" | ||
x:Name="button" | ||
HorizontalOptions="Center" | ||
VerticalOptions="Center"/> | ||
|
||
<CollectionView | ||
Grid.Row="3" | ||
x:Name="cv" | ||
ItemSizingStrategy="MeasureFirstItem"> | ||
|
||
<CollectionView.ItemsLayout> | ||
<GridItemsLayout | ||
Orientation="Vertical" | ||
HorizontalItemSpacing="8" | ||
VerticalItemSpacing="8" | ||
Span="2"/> | ||
</CollectionView.ItemsLayout> | ||
|
||
<CollectionView.ItemTemplate> | ||
<DataTemplate> | ||
<Grid BackgroundColor="LightGray"> | ||
<Label | ||
Text="{Binding Text}" | ||
AutomationId="{Binding AutomationId}" | ||
HorizontalOptions="Fill" | ||
VerticalOptions="Fill"/> | ||
</Grid> | ||
</DataTemplate> | ||
</CollectionView.ItemTemplate> | ||
|
||
</CollectionView> | ||
|
||
</Grid> | ||
</ContentPage> |
49 changes: 49 additions & 0 deletions
49
src/Controls/samples/Controls.Sample.UITests/Issues/Issue21967.xaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
using System; | ||
using Microsoft.Maui; | ||
using Microsoft.Maui.Controls; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace Maui.Controls.Sample.Issues; | ||
|
||
[Issue(IssueTracker.Github, 21967, "CollectionView causes invalid measurements on resize", PlatformAffected.Android)] | ||
public partial class Issue21967 : ContentPage | ||
{ | ||
public readonly record struct Data(string Text, string AutomationId); | ||
public Issue21967() | ||
{ | ||
InitializeComponent(); | ||
cv.ItemsSource = | ||
new List<string> { "Item1", "Item2", "Item3", "Item4", "Item5" } | ||
.Select((x, i) => | ||
{ | ||
string text = x; | ||
if (i == 1) | ||
{ | ||
// Generate long text that would measure really big to ensure everything stays measured the | ||
text = Enumerable.Range(0,1000).Select(x => x.ToString()).Aggregate((x, y) => x + " " + y); | ||
} | ||
return new Data(text, x); | ||
}) | ||
.ToList(); | ||
|
||
|
||
button.Clicked += (_, _) => | ||
{ | ||
if (cv.WidthRequest == 200) | ||
{ | ||
cv.WidthRequest = 100; | ||
} | ||
else | ||
{ | ||
cv.WidthRequest = 200; | ||
} | ||
}; | ||
|
||
buttonFullSize.Clicked += (_, _) => | ||
{ | ||
cv.WidthRequest = Microsoft.Maui.Primitives.Dimension.Unset; | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
using NUnit.Framework; | ||
using OpenQA.Selenium; | ||
using UITest.Appium; | ||
using UITest.Core; | ||
|
||
namespace Microsoft.Maui.AppiumTests.Issues | ||
{ | ||
public class Issue21967 : _IssuesUITest | ||
{ | ||
public Issue21967(TestDevice device) : base(device) | ||
{ | ||
} | ||
|
||
public override string Issue => "CollectionView causes invalid measurements on resize"; | ||
|
||
[Test] | ||
[Category(UITestCategories.CollectionView)] | ||
public void CollectionViewItemsResizeWhenContraintsOnCollectionViewChange() | ||
{ | ||
var largestSize = App.WaitForElement("Item1").GetRect(); | ||
App.Tap("Resize"); | ||
var mediumSize = App.WaitForElement("Item1").GetRect(); | ||
App.Tap("Resize"); | ||
var smallSize = App.WaitForElement("Item1").GetRect(); | ||
|
||
Assert.Greater(largestSize.Width, mediumSize.Width); | ||
Assert.Greater(mediumSize.Width, smallSize.Width); | ||
} | ||
|
||
[Test] | ||
[Category(UITestCategories.CollectionView)] | ||
public void CollectionViewFirstItemCorrectlySetsTheMeasure() | ||
{ | ||
var itemSize = App.WaitForElement("Item1").GetRect(); | ||
Assert.Greater(200, itemSize.Height); | ||
} | ||
|
||
[Test] | ||
[Category(UITestCategories.CollectionView)] | ||
public void CollectionViewWorksWhenRotatingDevice() | ||
{ | ||
this.IgnoreIfPlatforms(new TestDevice[] { TestDevice.Mac, TestDevice.Windows }); | ||
|
||
try | ||
{ | ||
App.WaitForElement("FullSize"); | ||
App.Tap("FullSize"); | ||
App.SetOrientationPortrait(); | ||
var itemSizePortrait = App.WaitForElement("Item1").GetRect(); | ||
App.SetOrientationLandscape(); | ||
var itemSizeLandscape = App.WaitForElement("Item1").GetRect(); | ||
App.SetOrientationPortrait(); | ||
var itemSizePortrait2 = App.WaitForElement("Item1").GetRect(); | ||
|
||
Assert.Greater(itemSizeLandscape.Width, itemSizePortrait.Width); | ||
Assert.AreEqual(itemSizePortrait2.Width, itemSizePortrait.Width); | ||
} | ||
finally | ||
{ | ||
App.SetOrientationPortrait(); | ||
} | ||
} | ||
} | ||
} |