Skip to content

[iOS] Fixed the TargetInvocationException Occurs When Selecting Header/Footer After Changing ItemsLayout in CV2 #28890

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Apr 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .config/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"rollForward": false
},
"microsoft.dotnet.xharness.cli": {
"version": "9.0.0-prerelease.25167.9",
"version": "9.0.0-prerelease.25203.2",
"commands": [
"xharness"
],
Expand Down
12 changes: 6 additions & 6 deletions eng/Version.Details.xml
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<Dependencies>
<ProductDependencies>
<Dependency Name="Microsoft.DotNet.XHarness.TestRunners.Common" Version="9.0.0-prerelease.25167.9">
<Dependency Name="Microsoft.DotNet.XHarness.TestRunners.Common" Version="9.0.0-prerelease.25203.2">
<Uri>https://github.com/dotnet/xharness</Uri>
<Sha>8fa551353a0b2c90afb82c507f23afdf966d57c5</Sha>
<Sha>1088108e794db714c8a0a74d94da70199a7bc62c</Sha>
</Dependency>
<Dependency Name="Microsoft.DotNet.XHarness.TestRunners.Xunit" Version="9.0.0-prerelease.25167.9">
<Dependency Name="Microsoft.DotNet.XHarness.TestRunners.Xunit" Version="9.0.0-prerelease.25203.2">
<Uri>https://github.com/dotnet/xharness</Uri>
<Sha>8fa551353a0b2c90afb82c507f23afdf966d57c5</Sha>
<Sha>1088108e794db714c8a0a74d94da70199a7bc62c</Sha>
</Dependency>
<Dependency Name="Microsoft.DotNet.XHarness.CLI" Version="9.0.0-prerelease.25167.9">
<Dependency Name="Microsoft.DotNet.XHarness.CLI" Version="9.0.0-prerelease.25203.2">
<Uri>https://github.com/dotnet/xharness</Uri>
<Sha>8fa551353a0b2c90afb82c507f23afdf966d57c5</Sha>
<Sha>1088108e794db714c8a0a74d94da70199a7bc62c</Sha>
</Dependency>
</ProductDependencies>
<ToolsetDependencies>
Expand Down
6 changes: 3 additions & 3 deletions eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,9 @@
<_HarfBuzzSharpVersion>8.3.0.1</_HarfBuzzSharpVersion>
<_SkiaSharpNativeAssetsVersion>0.0.0-commit.e57e2a11dac4ccc72bea52939dede49816842005.1728</_SkiaSharpNativeAssetsVersion>
<MicrosoftTemplateEngineTasksVersion>7.0.120</MicrosoftTemplateEngineTasksVersion>
<MicrosoftDotNetXHarnessTestRunnersCommonVersion>9.0.0-prerelease.25167.9</MicrosoftDotNetXHarnessTestRunnersCommonVersion>
<MicrosoftDotNetXHarnessTestRunnersXunitVersion>9.0.0-prerelease.25167.9</MicrosoftDotNetXHarnessTestRunnersXunitVersion>
<MicrosoftDotNetXHarnessCLIVersion>9.0.0-prerelease.25167.9</MicrosoftDotNetXHarnessCLIVersion>
<MicrosoftDotNetXHarnessTestRunnersCommonVersion>9.0.0-prerelease.25203.2</MicrosoftDotNetXHarnessTestRunnersCommonVersion>
<MicrosoftDotNetXHarnessTestRunnersXunitVersion>9.0.0-prerelease.25203.2</MicrosoftDotNetXHarnessTestRunnersXunitVersion>
<MicrosoftDotNetXHarnessCLIVersion>9.0.0-prerelease.25203.2</MicrosoftDotNetXHarnessCLIVersion>
<TizenUIExtensionsVersion>0.9.2</TizenUIExtensionsVersion>
<SvgSkiaPackageVersion>2.0.0.4</SvgSkiaPackageVersion>
<FizzlerPackageVersion>1.3.0</FizzlerPackageVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -986,6 +986,7 @@ internal class ListViewDataSource : UITableViewSource
readonly WeakReference<UITableView> _uiTableView;
readonly WeakReference<FormsUITableViewController> _uiTableViewController;
protected readonly WeakReference<ListView> _list;
readonly HashSet<ContextActionsCell> _contextActionsCells = new();
bool _isDragging;
bool _setupSelection;
bool _selectionFromNative;
Expand Down Expand Up @@ -1113,6 +1114,10 @@ public override UITableViewCell GetCell(UITableView tableView, NSIndexPath index
SetCellBackgroundColor(platformCell, bgColor);
PreserveActivityIndicatorState(cell);
Performance.Stop(reference);

if(platformCell is ContextActionsCell contextActionsCell)
_contextActionsCells.Add(contextActionsCell);

return platformCell;
}

Expand Down Expand Up @@ -1495,12 +1500,16 @@ protected override void Dispose(bool disposing)

if (disposing)
{
if (!_list.TryGetTarget(out var list))
if (_list.TryGetTarget(out var list))
{
list.ItemSelected -= OnItemSelected;
WatchShortNameCollection(false);
}

foreach (var cell in _contextActionsCells)
cell.Dispose();
_contextActionsCells.Clear();

_templateToId = null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,20 +61,14 @@ protected override void RegisterViewTypes()
private protected override void RegisterSupplementaryViews(UICollectionElementKindSection kind)
{
base.RegisterSupplementaryViews(kind);
if (IsHorizontal)
{
CollectionView.RegisterClassForSupplementaryView(typeof(HorizontalSupplementaryView2),
kind, HorizontalSupplementalView2ReuseId);
CollectionView.RegisterClassForSupplementaryView(typeof(HorizontalDefaultSupplementalView2),
kind, HorizontalDefaultSupplementalView2ReuseId);
}
else
{
CollectionView.RegisterClassForSupplementaryView(typeof(VerticalSupplementaryView2),
kind, VerticalSupplementaryView2ReuseId);
CollectionView.RegisterClassForSupplementaryView(typeof(VerticalDefaultSupplementalView2),
kind, VerticalDefaultSupplementalView2ReuseId);
}
CollectionView.RegisterClassForSupplementaryView(typeof(HorizontalSupplementaryView2),
kind, HorizontalSupplementalView2ReuseId);
CollectionView.RegisterClassForSupplementaryView(typeof(HorizontalDefaultSupplementalView2),
kind, HorizontalDefaultSupplementalView2ReuseId);
CollectionView.RegisterClassForSupplementaryView(typeof(VerticalSupplementaryView2),
kind, VerticalSupplementaryView2ReuseId);
CollectionView.RegisterClassForSupplementaryView(typeof(VerticalDefaultSupplementalView2),
kind, VerticalDefaultSupplementalView2ReuseId);
}

string DetermineViewReuseId(NSString elementKind)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,20 +75,14 @@ public override UICollectionReusableView GetViewForSupplementaryElement(UICollec

private protected virtual void RegisterSupplementaryViews(UICollectionElementKindSection kind)
{
if (IsHorizontal)
{
CollectionView.RegisterClassForSupplementaryView(typeof(HorizontalSupplementaryView2),
kind, HorizontalSupplementaryView2.ReuseId);
CollectionView.RegisterClassForSupplementaryView(typeof(HorizontalDefaultSupplementalView2),
kind, HorizontalDefaultSupplementalView2.ReuseId);
}
else
{
CollectionView.RegisterClassForSupplementaryView(typeof(VerticalSupplementaryView2),
kind, VerticalSupplementaryView2.ReuseId);
CollectionView.RegisterClassForSupplementaryView(typeof(VerticalDefaultSupplementalView2),
kind, VerticalDefaultSupplementalView2.ReuseId);
}
CollectionView.RegisterClassForSupplementaryView(typeof(HorizontalSupplementaryView2),
kind, HorizontalSupplementaryView2.ReuseId);
CollectionView.RegisterClassForSupplementaryView(typeof(HorizontalDefaultSupplementalView2),
kind, HorizontalDefaultSupplementalView2.ReuseId);
CollectionView.RegisterClassForSupplementaryView(typeof(VerticalSupplementaryView2),
kind, VerticalSupplementaryView2.ReuseId);
CollectionView.RegisterClassForSupplementaryView(typeof(VerticalDefaultSupplementalView2),
kind, VerticalDefaultSupplementalView2.ReuseId);
}

string DetermineViewReuseId(NSString elementKind)
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
55 changes: 55 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue28678.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
namespace Maui.Controls.Sample.Issues;

[Issue(IssueTracker.Github, 28678, "TargetInvocationException Occurs When Selecting Header/Footer After Changing ItemsLayout in CV2", PlatformAffected.iOS)]
public class Issue28678 : ContentPage
{
public Issue28678()
{
// Create the CollectionView
var collectionView = new CollectionView2
{
HeightRequest = 100,
};

var button = new Button
{
Text = "Change ItemsLayout",
AutomationId = "Button"
};
button.Clicked += (s, e) =>
{
collectionView.ItemsLayout = new LinearItemsLayout(ItemsLayoutOrientation.Horizontal);
};

var button1 = new Button
{
Text = "Add Header",
AutomationId = "HeaderButton"
};
button1.Clicked += (s, e) =>
{
collectionView.Header = "Header";
};

var button2 = new Button
{
Text = "Add Footer",
AutomationId = "FooterButton"
};
button2.Clicked += (s, e) =>
{
collectionView.Footer = "Footer";
};

Content = new VerticalStackLayout
{
Children =
{
collectionView,
button,
button1,
button2
}
};
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,14 @@ public Bugzilla34912(TestDevice testDevice) : base(testDevice)
[Category(UITestCategories.ListView)]
public void Bugzilla34912Test()
{
App.WaitForElement("Allen");
App.Tap("Allen");
App.WaitForElement("You tapped Allen");
App.WaitForElement("OK");
App.Tap("OK");
App.WaitForElement("Disable ListView");
App.Tap("Disable ListView");
App.WaitForElement("Allen");
App.Tap("Allen");
App.WaitForNoElement("You tapped Allen");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if TEST_FAILS_ON_WINDOWS // related issue: https://github.com/dotnet/maui/issues/24482
#if TEST_FAILS_ON_WINDOWS && TEST_FAILS_ON_ANDROID // Related issue for windows: https://github.com/dotnet/maui/issues/24482 and For Android, see : https://github.com/dotnet/maui/issues/28760
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if IOS || (ANDROID && TEST_FAILS_ON_ANDROID)//android related issue: https://github.com/dotnet/maui/issues/27951
#if (IOS && TEST_FAILS_ON_IOS) || (ANDROID && TEST_FAILS_ON_ANDROID) // Android related issue: https://github.com/dotnet/maui/issues/27951, iOS related issue: https://github.com/dotnet/maui/issues/28760
//The test is applicable only to mobile platforms like iOS and Android.
using System.Drawing;
using NUnit.Framework;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using NUnit.Framework;
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

Expand All @@ -19,6 +19,11 @@ public void TextInEditorShouldScroll()
_ = App.WaitForElement("editor");
App.ScrollDown("editor");

#if MACCATALYST // In Catalyst scroll down is not effective so here we retry one more time to address the flakyness.
Thread.Sleep(500);
App.ScrollDown("editor");
#endif

// The test passes if the text inside the editor scrolls down
VerifyScreenshot();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#if TEST_FAILS_ON_IOS //For more info see: https://github.com/dotnet/maui/issues/28806
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;
Expand Down Expand Up @@ -28,3 +29,4 @@ public async Task EntryTextColorStopsWorkingAfterPropertyIsUpdatedFromBinding()
}
}
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@ public void VerifyEntryClearButtonVisibilitySetToWhileEditing()
App.DismissKeyboard();
}
#endif

#if IOS //Inconsistent keyboard visibility issue in iOS CI environments can cause test flakiness. As this test validate the clear button visibility only, so the keyboard is not mandatory.
VerifyScreenshot(cropBottom: 1200);
#else
VerifyScreenshot();
#endif
}

[Test]
Expand All @@ -45,7 +50,12 @@ public void VerifyEntryClearButtonVisibilitySetToNever()
App.DismissKeyboard();
}
#endif

#if IOS //Inconsistent keyboard visibility issue in iOS CI environments can cause test flakiness. As this test validate the clear button visibility only, so the keyboard is not mandatory.
VerifyScreenshot(cropBottom: 1200);
#else
VerifyScreenshot();
#endif
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Issues;
public class Issue28678 : _IssuesUITest
{
public Issue28678(TestDevice device) : base(device) { }

public override string Issue => "TargetInvocationException Occurs When Selecting Header/Footer After Changing ItemsLayout in CV2";

[Test]
[Category(UITestCategories.CollectionView)]
public void HeaderFooterSelectionAfterItemsLayoutChangeShouldNotCrash()
{
App.WaitForElement("Button");
App.Tap("Button");
App.Tap("HeaderButton");
App.Tap("FooterButton");
App.WaitForElement("Button");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public class Issue3049 : _IssuesUITest
const string Button1Id = "button1";
const string Button2Id = "button2";
const string Success = "Success";
const string Skip = "skip";

public Issue3049(TestDevice testDevice) : base(testDevice)
{
Expand All @@ -22,16 +23,18 @@ public Issue3049(TestDevice testDevice) : base(testDevice)
[Category(UITestCategories.DisplayAlert)]
[Category(UITestCategories.Compatibility)]
[FailsOnIOSWhenRunningOnXamarinUITest("Skip this test -- as it is not applicable since the host app is not run on iPad in CI")]
public async Task Issue3049Test()
public void Issue3049Test()
{
App.WaitForElement(Button1Id);

var skipLabelRect = App.WaitForElement(Skip).GetRect();

App.Tap(Button1Id);

await Task.Delay(500);
App.WaitForElement("Click outside ActionSheet instead");

// Tap outside ActionSheet to dismiss it
App.TapCoordinates(50, 100);
App.TapCoordinates(skipLabelRect.CenterX(), skipLabelRect.CenterY());

App.WaitForElement(Button2Id);
App.Tap(Button2Id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public void NavigatingBackToAlreadySelectedTopTabDoesntCrash()
#if WINDOWS
App.Tap("navViewItem");
#endif
App.WaitForElement(Top3);
App.Tap(Top3);
App.WaitForElement("TopTabPage3");
App.Tap("Main 2");
Expand All @@ -38,6 +39,7 @@ public void NavigatingBackToAlreadySelectedTopTabDoesntCrash()
#if WINDOWS
App.TapCoordinates(50, 50);
#endif
App.WaitForElement("Main 2");
App.Tap("Main 2");
App.WaitForElement("TopTabPage2");
App.Tap("Main 1");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public Issue7678(TestDevice device) : base(device)
[Category(UITestCategories.CarouselView)]
public void VerifyCarouselViewItemsRenderAfterBinding()
{
App.WaitForElement("carouselView", timeout: TimeSpan.FromSeconds(2));
App.WaitForElement("carouselView", timeout: TimeSpan.FromSeconds(4));
App.WaitForElementTillPageNavigationSettled("1");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ void NavigateToEndAndBack(string BackButtonId)
App.WaitForElement("Pop two");
App.WaitForElementTillPageNavigationSettled("Check back two");
App.TapBackArrow(BackButtonId);
App.WaitForElementTillPageNavigationSettled("Check back three");
App.Tap("Check back three");
App.WaitForElement("At root");
}
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 6 additions & 1 deletion src/Templates/src/templates/maui-mobile/MauiApp.1.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>DOTNET_TFM-android;DOTNET_TFM-ios;DOTNET_TFM-maccatalyst</TargetFrameworks>
Expand Down Expand Up @@ -82,7 +82,12 @@
<!--#if (IncludeSampleContent) -->
<ItemGroup>
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.3.2" />
<!--#if (Framework == "net8.0") -->
<PackageReference Include="CommunityToolkit.Maui" Version="9.1.0" />
<!--#endif-->
<!--#if (Framework == "net9.0") -->
<PackageReference Include="CommunityToolkit.Maui" Version="11.1.1" />
<!--#endif-->
<PackageReference Include="Microsoft.Data.Sqlite.Core" Version="8.0.8" />
<PackageReference Include="SQLitePCLRaw.bundle_green" Version="2.1.10" />
<PackageReference Include="Syncfusion.Maui.Toolkit" Version="1.0.4" />
Expand Down
Loading