Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Android] CarouselView: VirtualView cannot be null here, when clearin…
…g and adding items on second navigation - fix (#22207) * Fix #22035 * Added UITest * Updated test * Updated test * Updated test * Updated test * - small change to code and fix test * Update Issue22035.cs * Update Issue22035.cs * - fix test * - fix test --------- Co-authored-by: Javier Suárez <javiersuarezruiz@hotmail.com> Co-authored-by: Shane Neuville <shneuvil@microsoft.com> Co-authored-by: Shane Neuville <shane94@hotmail.com>
- Loading branch information
1 parent
a1c9b93
commit 4bf8af5
Showing
6 changed files
with
159 additions
and
1 deletion.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
src/Controls/samples/Controls.Sample.UITests/Issues/Issue22035.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,20 @@ | ||
<?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.Issue22035Page1"> | ||
<VerticalStackLayout | ||
Spacing="25" | ||
Padding="30,0" | ||
VerticalOptions="Center"> | ||
<Label | ||
Text="Navigate to the page with the CarouselView several times. If the CarouselView always loads items without exceptions, the test passes."/> | ||
<Button | ||
x:Name="NavigateBtn" | ||
AutomationId="TestNavigateButton" | ||
Text="Go to CarouselView" | ||
SemanticProperties.Hint="Goes to page with CarouselView" | ||
Clicked="OnNavigateClicked" | ||
HorizontalOptions="Center" /> | ||
</VerticalStackLayout> | ||
</ContentPage> |
30 changes: 30 additions & 0 deletions
30
src/Controls/samples/Controls.Sample.UITests/Issues/Issue22035.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,30 @@ | ||
using System; | ||
using Microsoft.Maui.Controls; | ||
using Microsoft.Maui.Controls.Xaml; | ||
|
||
namespace Maui.Controls.Sample.Issues | ||
{ | ||
[XamlCompilation(XamlCompilationOptions.Compile)] | ||
[Issue(IssueTracker.Github, 22035, "[Android] CarouselView: VirtualView cannot be null here, when clearing and adding items on second navigation", PlatformAffected.Android)] | ||
public class Issue22035 : NavigationPage | ||
{ | ||
public Issue22035() : base(new Issue22035Page1()) | ||
{ | ||
|
||
} | ||
} | ||
|
||
public partial class Issue22035Page1 : ContentPage | ||
{ | ||
Issue22035Page2 _Issue22035Page2 = new Issue22035Page2(); | ||
public Issue22035Page1() | ||
{ | ||
InitializeComponent(); | ||
} | ||
|
||
async void OnNavigateClicked(object sender, EventArgs e) | ||
{ | ||
await Navigation.PushAsync(_Issue22035Page2); | ||
} | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
src/Controls/samples/Controls.Sample.UITests/Issues/Issue22035Page2.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,34 @@ | ||
<?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.Issue22035Page2" | ||
xmlns:local="clr-namespace:Maui.Controls.Sample.Issues"> | ||
<Grid RowDefinitions="Auto,*"> | ||
<Button | ||
Grid.Row="0" | ||
AutomationId="TestLoadButton" | ||
Text="Load Items" | ||
Pressed="OnLoadButtonPressed" /> | ||
<CarouselView | ||
Grid.Row="1" | ||
ItemsSource="{Binding Images}" | ||
MaximumHeightRequest="150"> | ||
<CarouselView.ItemTemplate> | ||
<DataTemplate x:DataType="local:Issue22035Model"> | ||
<Grid | ||
RowDefinitions="*, Auto"> | ||
<Image | ||
Source="{Binding ImagePath}" | ||
AutomationId="{Binding AutomationId}" /> | ||
<Label | ||
Grid.Row="1" | ||
HorizontalOptions="Center" | ||
AutomationId="{Binding AutomationId}" | ||
Text="{Binding Text}"/> | ||
</Grid> | ||
</DataTemplate> | ||
</CarouselView.ItemTemplate> | ||
</CarouselView> | ||
</Grid> | ||
</ContentPage> |
38 changes: 38 additions & 0 deletions
38
src/Controls/samples/Controls.Sample.UITests/Issues/Issue22035Page2.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,38 @@ | ||
using System; | ||
using System.Collections.ObjectModel; | ||
using System.Threading.Tasks; | ||
using Microsoft.Maui.Controls; | ||
using Microsoft.Maui.Controls.Xaml; | ||
|
||
namespace Maui.Controls.Sample.Issues | ||
{ | ||
[XamlCompilation(XamlCompilationOptions.Compile)] | ||
public partial class Issue22035Page2 : ContentPage | ||
{ | ||
public Issue22035Page2() | ||
{ | ||
InitializeComponent(); | ||
|
||
BindingContext = this; | ||
} | ||
|
||
public ObservableCollection<Issue22035Model> Images { get; set; } = new(); | ||
|
||
void OnLoadButtonPressed(object sender, EventArgs e) | ||
{ | ||
Images.Clear(); | ||
|
||
Images.Add(new Issue22035Model { Text = "Item 1", ImagePath = "photo21314.jpg" }); | ||
Images.Add(new Issue22035Model { Text = "Item 2", ImagePath = "oasis.jpg" }); | ||
Images.Add(new Issue22035Model { Text = "Item 3", ImagePath = "photo21314.jpg" }); | ||
Images.Add(new Issue22035Model { Text = "Item 4", ImagePath = "oasis.jpg" }); | ||
} | ||
} | ||
|
||
public class Issue22035Model | ||
{ | ||
public string Text { get; set; } | ||
public string ImagePath { get; set; } | ||
public string AutomationId => Text.Replace(" ", "", StringComparison.InvariantCultureIgnoreCase); | ||
} | ||
} |
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,35 @@ | ||
using NUnit.Framework; | ||
using UITest.Appium; | ||
using UITest.Core; | ||
|
||
namespace Microsoft.Maui.AppiumTests.Issues | ||
{ | ||
[Category(UITestCategories.CarouselView)] | ||
public class Issue22035 : _IssuesUITest | ||
{ | ||
public Issue22035(TestDevice device) : base(device) | ||
{ | ||
} | ||
|
||
public override string Issue => "[Android] CarouselView: VirtualView cannot be null here, when clearing and adding items on second navigation"; | ||
|
||
[Test] | ||
public void CarouselViewVirtualViewNotNull() | ||
{ | ||
this.IgnoreIfPlatforms(new TestDevice[] { TestDevice.iOS, TestDevice.Mac, TestDevice.Windows }, | ||
"This test is failing, likely due to product issue. More information: https://github.com/dotnet/maui/issues/22287"); | ||
|
||
for (int i = 0; i < 2; i++) | ||
{ | ||
App.WaitForElement("TestNavigateButton"); | ||
App.Tap("TestNavigateButton"); | ||
App.WaitForElement("TestLoadButton"); | ||
App.Tap("TestLoadButton"); | ||
App.WaitForElement("Item1"); | ||
App.Back(); | ||
} | ||
|
||
// Without exceptions, the test has passed. | ||
} | ||
} | ||
} |