Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Diagnostics.CodeAnalysis;
using Microsoft.Maui.Controls.Compatibility;
using Prism.Mvvm;
using Prism.Navigation.Regions;
using Prism.Navigation.Regions.Adapters;
Expand Down Expand Up @@ -115,7 +114,7 @@ internal static IContainerRegistry RegisterRegionServices(this IContainerRegistr
// TODO: CollectionView is buggy with only last View showing despite multiple Active Views
// BUG: iOS Crash with CollectionView https://github.com/xamarin/Xamarin.Forms/issues/9970
//regionAdapterMappings.RegisterDefaultMapping<CollectionView, CollectionViewRegionAdapter>();
regionAdapterMappings.RegisterDefaultMapping<Layout<View>, LayoutViewRegionAdapter>();
regionAdapterMappings.RegisterDefaultMapping<Layout, LayoutViewRegionAdapter>();
regionAdapterMappings.RegisterDefaultMapping<ScrollView, ScrollViewRegionAdapter>();
regionAdapterMappings.RegisterDefaultMapping<ContentView, ContentViewRegionAdapter>();
return regionAdapterMappings;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
using Microsoft.Maui.Controls.Compatibility;
using Prism.Ioc;
using Prism.Properties;

namespace Prism.Navigation.Regions.Adapters;

/// <summary>
/// Adapter that creates a new <see cref="Region"/> and monitors its
/// active view to set it on the adapted <see cref="Layout{View}"/>.
/// active view to set it on the adapted <see cref="Layout"/>.
/// </summary>
public class LayoutViewRegionAdapter : RegionAdapterBase<Layout<View>>
public class LayoutViewRegionAdapter : RegionAdapterBase<Layout>
{
/// <summary>
/// Initializes a new instance of <see cref="LayoutViewRegionAdapter"/>.
Expand All @@ -20,11 +18,11 @@ public LayoutViewRegionAdapter(IRegionBehaviorFactory regionBehaviorFactory)
}

/// <summary>
/// Adapts a <see cref="Layout{View}"/> to an <see cref="IRegion"/>.
/// Adapts a <see cref="Layout"/> to an <see cref="IRegion"/>.
/// </summary>
/// <param name="region">The new region being used.</param>
/// <param name="regionTarget">The object to adapt.</param>
protected override void Adapt(IRegion region, Layout<View> regionTarget)
protected override void Adapt(IRegion region, Layout regionTarget)
{
if (region == null)
throw new ArgumentNullException(nameof(region));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Prism.DryIoc.Maui.Tests.Mocks.ViewModels;
using Prism.DryIoc.Maui.Tests.Mocks.ViewModels;
using Prism.DryIoc.Maui.Tests.Mocks.Views;
using Prism.Navigation.Xaml;

Expand Down Expand Up @@ -53,6 +53,33 @@ public void FrameRegion_CreatedBy_RegisterViewWithRegion()
Assert.IsType<MockRegionViewAViewModel>(page.FrameRegion.Content.BindingContext);
}

[Fact]
public void Issue3159_LayoutRegion_CreatedBy_RegisterViewWithRegion()
{
var mauiApp = CreateBuilder(prism =>
prism.RegisterTypes(container =>
{
container.RegisterForNavigation<MockContentRegionPage, MockContentRegionPageViewModel>();
container.RegisterForRegionNavigation<MockRegionViewA, MockRegionViewAViewModel>();
})
.OnInitialized(container =>
{
var regionManager = container.Resolve<IRegionManager>();
regionManager.RegisterViewWithRegion("LayoutRegion", "MockRegionViewA");
})
.CreateWindow("MockContentRegionPage"))
.Build();
var window = GetWindow(mauiApp);

Assert.IsType<MockContentRegionPage>(window.Page);
var page = window.Page as MockContentRegionPage;

Assert.NotNull(page.LayoutRegion.Children);
Assert.NotEmpty(page.LayoutRegion.Children);
Assert.IsType<ContentView>(page.LayoutRegion.Children.First());
Assert.IsType<MockRegionViewAViewModel>(((ContentView)page.LayoutRegion.First()).Content.BindingContext);
}

[Fact]
public void RegionsShareContainer_WithPage()
{
Expand All @@ -76,7 +103,7 @@ public void RegionsShareContainer_WithPage()

var regionManager = mauiApp.Services.GetRequiredService<IRegionManager>();
var regions = regionManager.Regions.Cast<ITargetAwareRegion>();
Assert.Equal(2, regions.Count());
Assert.Equal(3, regions.Count());
foreach (var region in regions)
{
Assert.Same(page.GetContainerProvider(), region.Container);
Expand Down Expand Up @@ -110,7 +137,7 @@ public void RegionViewModel_HasPageAccessor_WithCorrectPage()
}

[Fact]
public void RegionManager_HasTwoRegions()
public void RegionManager_HasRegionsAmount()
{
var mauiApp = CreateBuilder(prism =>
prism.RegisterTypes(container =>
Expand All @@ -122,7 +149,7 @@ public void RegionManager_HasTwoRegions()
var window = GetWindow(mauiApp);

var regionManager = mauiApp.Services.GetRequiredService<IRegionManager>();
Assert.Equal(2, regionManager.Regions.Count());
Assert.Equal(3, regionManager.Regions.Count());
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Prism.DryIoc.Maui.Tests.Mocks.Views;
namespace Prism.DryIoc.Maui.Tests.Mocks.Views;

public class MockContentRegionPage : ContentPage
{
Expand All @@ -10,14 +10,20 @@ public MockContentRegionPage()
FrameRegion = new Frame();
FrameRegion.SetValue(Prism.Navigation.Regions.Xaml.RegionManager.RegionNameProperty, nameof(FrameRegion));

LayoutRegion = new StackLayout();
LayoutRegion.SetValue(Prism.Navigation.Regions.Xaml.RegionManager.RegionNameProperty, nameof(LayoutRegion));

Content = new StackLayout
{
ContentRegion,
FrameRegion
FrameRegion,
LayoutRegion
};
}

public ContentView ContentRegion { get; }

public Frame FrameRegion { get; }

public Layout LayoutRegion { get; }
}