Skip to content

Commit

Permalink
Merge branch 'PrismLibrary:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
lucacivale authored Jul 5, 2024
2 parents b59fd4a + e64870b commit 4052229
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 40 deletions.
19 changes: 17 additions & 2 deletions src/Maui/Prism.Maui/Navigation/PageNavigationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Prism.Events;
using Prism.Extensions;
using Prism.Mvvm;
using Prism.Navigation.Regions;
using Application = Microsoft.Maui.Controls.Application;
using XamlTab = Prism.Navigation.Xaml.TabbedPage;

Expand Down Expand Up @@ -100,7 +101,9 @@ private async Task<INavigationResult> GoBackInternalAsync(INavigationParameters

page = GetCurrentPage();
if (IsRoot(GetPageFromWindow(), page))
throw new NavigationException(NavigationException.CannotPopApplicationMainPage, page);
{
return SendAppToBackground(page);
}

parameters.GetNavigationParametersInternal().Add(KnownInternalParameters.NavigationMode, NavigationMode.Back);

Expand Down Expand Up @@ -843,7 +846,7 @@ private static void OnNavigatedTo(Page toPage, INavigationParameters parameters)
{
MvvmHelpers.OnNavigatedTo(navigationPage.CurrentPage, parameters);
}
else if (tabbedPage.BindingContext != tabbedPage.CurrentPage.BindingContext)
else if (tabbedPage.BindingContext != tabbedPage.CurrentPage?.BindingContext)
{
MvvmHelpers.OnNavigatedTo(tabbedPage.CurrentPage, parameters);
}
Expand Down Expand Up @@ -1255,6 +1258,18 @@ internal static bool UseReverseNavigation(Page currentPage, Type nextPageType)
return MvvmHelpers.HasNavigationPageParent(currentPage) && MvvmHelpers.IsSameOrSubclassOf<ContentPage>(nextPageType);
}

private INavigationResult SendAppToBackground(Page page)
{
#if ANDROID
if (Window.Handler.PlatformView is MauiAppCompatActivity activity)
{
activity.MoveTaskToBack(true);
return new NavigationResult();
}
#endif
throw new NavigationException(NavigationException.CannotPopApplicationMainPage, page);
}

private INavigationResult Notify(NavigationRequestType type, INavigationParameters parameters, Exception exception = null)
{
var result = new NavigationResult(exception);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System.Collections.Specialized;
using System.Collections.Specialized;
using Prism.Behaviors;
using Prism.Common;
using Prism.Ioc;
using Prism.Mvvm;
using Prism.Properties;

Expand Down Expand Up @@ -29,8 +28,8 @@ public CarouselViewRegionAdapter(IRegionBehaviorFactory regionBehaviorFactory)
/// <param name="regionTarget">The object to adapt.</param>
protected override void Adapt(IRegion region, CarouselView regionTarget)
{
if (regionTarget == null)
throw new ArgumentNullException(nameof(regionTarget));
ArgumentNullException.ThrowIfNull(region);
ArgumentNullException.ThrowIfNull(regionTarget);

bool itemsSourceIsSet = regionTarget.ItemsSource != null || regionTarget.IsSet(ItemsView.ItemsSourceProperty);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using Prism.Ioc;
using Prism.Properties;

namespace Prism.Navigation.Regions.Adapters;
Expand All @@ -25,11 +24,8 @@ public CollectionViewRegionAdapter(IRegionBehaviorFactory regionBehaviorFactory)
/// <param name="regionTarget">The object to adapt.</param>
protected override void Adapt(IRegion region, CollectionView regionTarget)
{
if (region == null)
throw new ArgumentNullException(nameof(region));

if (regionTarget == null)
throw new ArgumentNullException(nameof(regionTarget));
ArgumentNullException.ThrowIfNull(region);
ArgumentNullException.ThrowIfNull(regionTarget);

bool itemsSourceIsSet = regionTarget.ItemsSource != null || regionTarget.IsSet(ItemsView.ItemsSourceProperty);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Collections.Specialized;
using Prism.Ioc;
using System.Collections.Specialized;
using Prism.Properties;

namespace Prism.Navigation.Regions.Adapters;
Expand Down Expand Up @@ -27,8 +26,8 @@ public ContentViewRegionAdapter(IRegionBehaviorFactory regionBehaviorFactory)
/// <param name="regionTarget">The object to adapt.</param>
protected override void Adapt(IRegion region, TContentView regionTarget)
{
if (regionTarget == null)
throw new ArgumentNullException(nameof(regionTarget));
ArgumentNullException.ThrowIfNull(region);
ArgumentNullException.ThrowIfNull(regionTarget);

bool contentIsSet = regionTarget.Content != null || regionTarget.IsSet(ContentView.ContentProperty);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,8 @@ public LayoutViewRegionAdapter(IRegionBehaviorFactory regionBehaviorFactory)
/// <param name="regionTarget">The object to adapt.</param>
protected override void Adapt(IRegion region, Layout<View> regionTarget)
{
if (region == null)
throw new ArgumentNullException(nameof(region));

if (regionTarget == null)
throw new ArgumentNullException(nameof(regionTarget));
ArgumentNullException.ThrowIfNull(region);
ArgumentNullException.ThrowIfNull(regionTarget);

bool itemsSourceIsSet = regionTarget.Children?.Any() ?? false || regionTarget.IsSet(BindableLayout.ItemsSourceProperty);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System.Globalization;
using System.Globalization;
using Prism.Extensions;
using Prism.Ioc;
using Prism.Navigation.Regions.Behaviors;
using Prism.Navigation.Xaml;
using Prism.Properties;
Expand Down Expand Up @@ -75,11 +74,8 @@ IRegion IRegionAdapter.Initialize(object regionTarget, string regionName)
/// <param name="regionTarget">The object to adapt.</param>
protected virtual void AttachDefaultBehaviors(IRegion region, T regionTarget)
{
if (region == null)
throw new ArgumentNullException(nameof(region));

if (regionTarget == null)
throw new ArgumentNullException(nameof(regionTarget));
ArgumentNullException.ThrowIfNull(region);
ArgumentNullException.ThrowIfNull(regionTarget);

IRegionBehaviorFactory behaviorFactory = RegionBehaviorFactory;
if (behaviorFactory != null)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Collections.Specialized;
using Prism.Ioc;
using System.Collections.Specialized;
using Prism.Properties;

namespace Prism.Navigation.Regions.Adapters;
Expand All @@ -26,8 +25,8 @@ public ScrollViewRegionAdapter(IRegionBehaviorFactory regionBehaviorFactory)
/// <param name="regionTarget">The object to adapt.</param>
protected override void Adapt(IRegion region, ScrollView regionTarget)
{
if (regionTarget == null)
throw new ArgumentNullException(nameof(regionTarget));
ArgumentNullException.ThrowIfNull(region);
ArgumentNullException.ThrowIfNull(regionTarget);

// No binding check required as the ContentProperty is not Bindable
bool contentIsSet = regionTarget.Content != null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public NavigationTests(ITestOutputHelper testOutputHelper)
[InlineData("MockHome/NavigationPage/MockViewA")]
[InlineData("MockExplicitTabbedPage")]
[InlineData("TabbedPage?createTab=NavigationPage%2FMockViewA%2FMockViewB%3Fid%3D5%2FMockViewC&createTab=MockViewD")]
[InlineData("NavigationPage/MockViewB/TabbedPage?createTab=MockViewA/MockViewC")]
public void PagesInjectScopedInstanceOfIPageAccessor(string uri)
{
var mauiApp = CreateBuilder(prism => prism.CreateWindow(uri))
Expand Down
17 changes: 13 additions & 4 deletions tests/Maui/Prism.Maui.Tests/Fixtures/Common/MvvmHelperFixture.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
using Moq;
using Prism.Common;

namespace Prism.Maui.Tests.Fixtures.Common;

public class MvvmHelperFixture
{
public MvvmHelperFixture()
{
var provider = new Mock<IDispatcherProvider>();
provider.Setup(x => x.GetForCurrentThread()).Returns(Mock.Of<IDispatcher>());

DispatcherProvider.SetCurrent(provider.Object);
}

/// <summary>
/// This test was introduced to verify GH3143
/// </summary>
Expand Down Expand Up @@ -96,12 +105,12 @@ public async Task GetCurrentPageFromContentPageWithModalReturnsContentPage()
/// This test was introduced to verify GH3143
/// </summary>
/// <a href="https://github.com/PrismLibrary/Prism/issues/3143">Git Hub Issue 3143</a>
[Fact(Skip = "System.InvalidOperationException\nBindableObject was not instantiated on a thread with a dispatcher nor does the current application have a dispatcher.")]
[Fact]
public async Task GetCurrentPageFromTabbedPageWithModalReturnsContentPage()
{
// Given
var expected = new ContentPage();
var tabbedPage = new TabbedPage { Title = "Tab", Children = { expected }};
var tabbedPage = new TabbedPage { Title = "Tab", Children = { expected } };
var window = new Window { Page = tabbedPage };
await window.Navigation.PushModalAsync(new DialogContainerPage());

Expand All @@ -116,13 +125,13 @@ public async Task GetCurrentPageFromTabbedPageWithModalReturnsContentPage()
/// This test was introduced to verify GH3143
/// </summary>
/// <a href="https://github.com/PrismLibrary/Prism/issues/3143">Git Hub Issue 3143</a>
[Fact(Skip = "System.InvalidOperationException\nBindableObject was not instantiated on a thread with a dispatcher nor does the current application have a dispatcher.")]
[Fact]
public async Task GetCurrentPageFromTabbedNavigationPageWithModalReturnsContentPage()
{
// Given
var expected = new ContentPage();
var navigationPage = new NavigationPage(expected);
var tabbedPage = new TabbedPage { Title = "Tab", Children = { navigationPage }};
var tabbedPage = new TabbedPage { Title = "Tab", Children = { navigationPage } };
var window = new Window { Page = tabbedPage };
await window.Navigation.PushModalAsync(new DialogContainerPage());

Expand Down
4 changes: 0 additions & 4 deletions tests/Maui/Prism.Maui.Tests/Prism.Maui.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,4 @@
<ProjectReference Include="..\..\..\src\Maui\Prism.Maui\Prism.Maui.csproj" />
</ItemGroup>

<ItemGroup>
<Folder Include="Fixtures\Mvvm\" />
</ItemGroup>

</Project>

0 comments on commit 4052229

Please sign in to comment.