diff --git a/src/Maui/Prism.Maui/Ioc/RegionNavigationRegistrationExtensions.cs b/src/Maui/Prism.Maui/Ioc/RegionNavigationRegistrationExtensions.cs index 94d52f7cf..800affcd5 100644 --- a/src/Maui/Prism.Maui/Ioc/RegionNavigationRegistrationExtensions.cs +++ b/src/Maui/Prism.Maui/Ioc/RegionNavigationRegistrationExtensions.cs @@ -114,7 +114,8 @@ 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(); - regionAdapterMappings.RegisterDefaultMapping(); + regionAdapterMappings.RegisterDefaultMapping, LayoutViewRegionAdapter>(); + regionAdapterMappings.RegisterDefaultMapping(); regionAdapterMappings.RegisterDefaultMapping(); regionAdapterMappings.RegisterDefaultMapping(); return regionAdapterMappings; diff --git a/src/Maui/Prism.Maui/Navigation/Regions/Adapters/LayoutRegionAdapter.cs b/src/Maui/Prism.Maui/Navigation/Regions/Adapters/LayoutRegionAdapter.cs new file mode 100644 index 000000000..8b4008c50 --- /dev/null +++ b/src/Maui/Prism.Maui/Navigation/Regions/Adapters/LayoutRegionAdapter.cs @@ -0,0 +1,50 @@ +using Prism.Properties; + +namespace Prism.Navigation.Regions.Adapters; + +/// +/// Adapter that creates a new and monitors its +/// active view to set it on the adapted . +/// +public class LayoutRegionAdapter : RegionAdapterBase +{ + /// + /// Initializes a new instance of . + /// + /// The factory used to create the region behaviors to attach to the created regions. + public LayoutRegionAdapter(IRegionBehaviorFactory regionBehaviorFactory) + : base(regionBehaviorFactory) + { + } + + /// + /// Adapts a to an . + /// + /// The new region being used. + /// The object to adapt. + protected override void Adapt(IRegion region, Layout regionTarget) + { + if (region == null) + throw new ArgumentNullException(nameof(region)); + + if (regionTarget == null) + throw new ArgumentNullException(nameof(regionTarget)); + + bool itemsSourceIsSet = regionTarget.Children?.Any() ?? false || regionTarget.IsSet(BindableLayout.ItemsSourceProperty); + + if (itemsSourceIsSet) + { + throw new InvalidOperationException(Resources.LayoutViewHasChildrenException); + } + + BindableLayout.SetItemsSource(regionTarget, region.Views); + BindableLayout.SetItemTemplate(regionTarget, new RegionItemsSourceTemplate()); + } + + /// + /// Creates a new instance of . + /// + /// A new instance of . + protected override IRegion CreateRegion(IContainerProvider container) => + container.Resolve(); +} diff --git a/src/Maui/Prism.Maui/Navigation/Regions/Adapters/LayoutViewRegionAdapter.cs b/src/Maui/Prism.Maui/Navigation/Regions/Adapters/LayoutViewRegionAdapter.cs index 56349f75b..9d2c591b7 100644 --- a/src/Maui/Prism.Maui/Navigation/Regions/Adapters/LayoutViewRegionAdapter.cs +++ b/src/Maui/Prism.Maui/Navigation/Regions/Adapters/LayoutViewRegionAdapter.cs @@ -1,12 +1,13 @@ +using Microsoft.Maui.Controls.Compatibility; using Prism.Properties; namespace Prism.Navigation.Regions.Adapters; /// /// Adapter that creates a new and monitors its -/// active view to set it on the adapted . +/// active view to set it on the adapted . /// -public class LayoutViewRegionAdapter : RegionAdapterBase +public class LayoutViewRegionAdapter : RegionAdapterBase> { /// /// Initializes a new instance of . @@ -18,11 +19,11 @@ public LayoutViewRegionAdapter(IRegionBehaviorFactory regionBehaviorFactory) } /// - /// Adapts a to an . + /// Adapts a to an . /// /// The new region being used. /// The object to adapt. - protected override void Adapt(IRegion region, Layout regionTarget) + protected override void Adapt(IRegion region, Layout regionTarget) { if (region == null) throw new ArgumentNullException(nameof(region));