Skip to content
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
6 changes: 6 additions & 0 deletions src/Controls/src/Core/Hosting/AppHostBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#elif IOS || MACCATALYST
using Microsoft.Maui.Controls.Compatibility.Platform.iOS;
using Microsoft.Maui.Controls.Handlers.Compatibility;
using Microsoft.Maui.Controls.Handlers.Items2;
#elif TIZEN
using Microsoft.Maui.Controls.Handlers.Compatibility;
using Microsoft.Maui.Controls.Compatibility.Platform.Tizen;
Expand Down Expand Up @@ -61,8 +62,13 @@ public static partial class AppHostBuilderExtensions

internal static IMauiHandlersCollection AddControlsHandlers(this IMauiHandlersCollection handlersCollection)
{
#if IOS || MACCATALYST
handlersCollection.AddHandler<CollectionView, CollectionViewHandler2>();
handlersCollection.AddHandler<CarouselView, CarouselViewHandler2>();
#else
handlersCollection.AddHandler<CollectionView, CollectionViewHandler>();
handlersCollection.AddHandler<CarouselView, CarouselViewHandler>();
#endif
handlersCollection.AddHandler<Application, ApplicationHandler>();
handlersCollection.AddHandler<ActivityIndicator, ActivityIndicatorHandler>();
handlersCollection.AddHandler<BoxView, BoxViewHandler>();
Expand Down
8 changes: 0 additions & 8 deletions src/Templates/src/templates/maui-mobile/MauiProgram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,6 @@ public static MauiApp CreateMauiApp()
#if (IncludeSampleContent)
.UseMauiCommunityToolkit()
.ConfigureSyncfusionToolkit()
.ConfigureMauiHandlers(handlers =>
{
//-:cnd:noEmit
#if IOS || MACCATALYST
handlers.AddHandler<Microsoft.Maui.Controls.CollectionView, Microsoft.Maui.Controls.Handlers.Items2.CollectionViewHandler2>();
#endif
//+:cnd:noEmit
})
#endif
.ConfigureFonts(fonts =>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -333,32 +333,4 @@ public void BuildWithDifferentVersionNumber(string id, string config, string dis
Assert.IsTrue(DotnetInternal.Build(projectFile, config, properties: buildProps, msbuildWarningsAsErrors: true),
$"Project {Path.GetFileName(projectFile)} failed to build. Check test output/attachments for errors.");
}

// This test is super temporary and is just for the interim
// while we productize the CollectionViewHandler2. Once we
// ship it as the default, this test will fail and can be deleted.
[Test]
[TestCase("maui", DotNetCurrent, "", false)]
[TestCase("maui", DotNetCurrent, "--sample-content", true)]
public void SampleShouldHaveHandler2Registered(string id, string framework, string additionalDotNetNewParams, bool shouldHaveHandler2)
{
var projectDir = TestDirectory;
var programFile = Path.Combine(projectDir, "MauiProgram.cs");

Assert.IsTrue(DotnetInternal.New(id, projectDir, framework, additionalDotNetNewParams),
$"Unable to create template {id}. Check test output for errors.");

var programContents = File.ReadAllText(programFile);

if (shouldHaveHandler2)
{
AssertContains("#if IOS || MACCATALYST", programContents);
AssertContains("handlers.AddHandler<Microsoft.Maui.Controls.CollectionView, Microsoft.Maui.Controls.Handlers.Items2.CollectionViewHandler2>();", programContents);
}
else
{
AssertDoesNotContain("#if IOS || MACCATALYST", programContents);
AssertDoesNotContain("handlers.AddHandler<Microsoft.Maui.Controls.CollectionView, Microsoft.Maui.Controls.Handlers.Items2.CollectionViewHandler2>();", programContents);
}
}
}