-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Windows] Avoid Carousel changes the current position when window is …
…resized (#22222) * Added repro sample * Added UI Test * Fix the issue * Added pending snapshot * Run added test on all the platforms * More changes * Updated sample * Added snapshots * Updated test
- Loading branch information
1 parent
1dfae6f
commit 4a1cc39
Showing
7 changed files
with
163 additions
and
5 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
src/Controls/samples/Controls.Sample.UITests/Issues/Issue22000.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,42 @@ | ||
<?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.Issue22000"> | ||
<Grid | ||
RowDefinitions="Auto, *, Auto"> | ||
<Grid.Resources> | ||
|
||
<DataTemplate x:Key="SampleItemTemplate"> | ||
<Grid | ||
RowDefinitions="Auto, Auto" | ||
BackgroundColor="{Binding Color, Mode=OneWay}"> | ||
<Label | ||
TextColor="White" | ||
Text="{Binding Title, Mode=OneWay}" | ||
FontAttributes="Bold" /> | ||
<Label | ||
Grid.Row="1" | ||
TextColor="White" | ||
Text="{Binding Description, Mode=OneWay}" /> | ||
</Grid> | ||
</DataTemplate> | ||
|
||
</Grid.Resources> | ||
<Label | ||
AutomationId="WaitForStubControl" | ||
Text="Tap the Button several times to resize the CarouselView. If the CurrentItem not change, the test has passed."/> | ||
<CarouselView | ||
x:Name="TestCarouselView" | ||
Grid.Row="1" | ||
ItemTemplate="{StaticResource SampleItemTemplate}" | ||
Loop="False" | ||
HeightRequest="250" | ||
HorizontalOptions="Center"/> | ||
<Button | ||
AutomationId="UpdateSizeButton" | ||
Grid.Row="2" | ||
Text="Update Size" | ||
Clicked="OnUpdateSizeClicked"/> | ||
</Grid> | ||
</ContentPage> |
62 changes: 62 additions & 0 deletions
62
src/Controls/samples/Controls.Sample.UITests/Issues/Issue22000.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,62 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using Microsoft.Maui.Controls; | ||
using Microsoft.Maui.Graphics; | ||
|
||
namespace Maui.Controls.Sample.Issues | ||
{ | ||
[Issue(IssueTracker.Github, 22000, "[Windows] Carousel changes the current position when window is resized", PlatformAffected.UWP)] | ||
public partial class Issue22000 : ContentPage | ||
{ | ||
readonly Random _random; | ||
|
||
public Issue22000() | ||
{ | ||
InitializeComponent(); | ||
|
||
_random = new Random(); | ||
|
||
var exampleItems = new List<Issue22000Model> | ||
{ | ||
new Issue22000Model( "First", "First CarouselView item", Colors.Red ), | ||
new Issue22000Model( "Second", "Second CarouselView item", Colors.LightBlue ), | ||
new Issue22000Model( "Third", "Third CarouselView item", Colors.Pink ), | ||
new Issue22000Model( "Fourth", "Fourth CarouselView item", Colors.GreenYellow ), | ||
new Issue22000Model( "Fifth", "Fifth CarouselView item", Colors.Purple ), | ||
}; | ||
|
||
TestCarouselView.ItemsSource = exampleItems; | ||
|
||
UpdateCarouselViewSize(); | ||
} | ||
|
||
void OnUpdateSizeClicked(object sender, EventArgs e) | ||
{ | ||
UpdateCarouselViewSize(); | ||
} | ||
|
||
void UpdateCarouselViewSize() | ||
{ | ||
var currentWidth = TestCarouselView.WidthRequest; | ||
|
||
if (currentWidth == 400) | ||
TestCarouselView.WidthRequest = 300; | ||
else | ||
TestCarouselView.WidthRequest = 200; | ||
} | ||
} | ||
|
||
class Issue22000Model | ||
{ | ||
public Issue22000Model(string title, string description, Color color) | ||
{ | ||
Title = title; | ||
Description = description; | ||
Color = color; | ||
} | ||
|
||
public string Title { get; set; } | ||
public string Description { get; set; } | ||
public Color Color { get; set; } | ||
} | ||
} |
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,29 @@ | ||
using NUnit.Framework; | ||
using UITest.Appium; | ||
using UITest.Core; | ||
|
||
namespace Microsoft.Maui.AppiumTests.Issues | ||
{ | ||
public class Issue22000 : _IssuesUITest | ||
{ | ||
public Issue22000(TestDevice device) : base(device) { } | ||
|
||
public override string Issue => "[Windows] Carousel changes the current position when window is resized"; | ||
|
||
[Test] | ||
[Category(UITestCategories.CarouselView)] | ||
public async Task ResizeCarouselViewKeepsIndex() | ||
{ | ||
App.WaitForElement("WaitForStubControl"); | ||
|
||
for (int i = 0; i < 10; i++) | ||
{ | ||
App.Click("UpdateSizeButton"); | ||
} | ||
|
||
await Task.Delay(500); | ||
|
||
VerifyScreenshot(); | ||
} | ||
} | ||
} |
Binary file added
BIN
+42.8 KB
src/Controls/tests/UITests/snapshots/android/ResizeCarouselViewKeepsIndex.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+47.1 KB
src/Controls/tests/UITests/snapshots/ios/ResizeCarouselViewKeepsIndex.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+10.5 KB
src/Controls/tests/UITests/snapshots/windows/ResizeCarouselViewKeepsIndex.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.