-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[BUG] [Regions] LayoutViewRegionAdapter should be mapped to Maui.Cont…
…rols.Layout instead of Maui.Controls.Compatibility.Layout
- Loading branch information
Civale, Luca
authored and
Civale, Luca
committed
Jun 11, 2024
1 parent
52492f3
commit a701cb5
Showing
3 changed files
with
57 additions
and
5 deletions.
There are no files selected for viewing
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
50 changes: 50 additions & 0 deletions
50
src/Maui/Prism.Maui/Navigation/Regions/Adapters/LayoutRegionAdapter.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,50 @@ | ||
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"/>. | ||
/// </summary> | ||
public class LayoutRegionAdapter : RegionAdapterBase<Layout> | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of <see cref="LayoutRegionAdapter"/>. | ||
/// </summary> | ||
/// <param name="regionBehaviorFactory">The factory used to create the region behaviors to attach to the created regions.</param> | ||
public LayoutRegionAdapter(IRegionBehaviorFactory regionBehaviorFactory) | ||
: base(regionBehaviorFactory) | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// 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 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()); | ||
} | ||
|
||
/// <summary> | ||
/// Creates a new instance of <see cref="IRegion"/>. | ||
/// </summary> | ||
/// <returns>A new instance of <see cref="Region"/>.</returns> | ||
protected override IRegion CreateRegion(IContainerProvider container) => | ||
container.Resolve<Region>(); | ||
} |
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