Skip to content

Commit

Permalink
remove support for Partial Views
Browse files Browse the repository at this point in the history
  • Loading branch information
dansiegel committed Aug 10, 2020
1 parent c1fa5dd commit b70f870
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 182 deletions.
30 changes: 28 additions & 2 deletions PrismLibrary_Forms.sln
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "Prism.Unity.Shared", "src\C
EndProject
Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "Prism.DryIoc.Shared", "src\Containers\Prism.DryIoc.Shared\Prism.DryIoc.Shared.shproj", "{6E7EC81D-DA39-4C4F-A898-0148558C34F4}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MockApp", "tests\Forms\MockApp\MockApp.csproj", "{0E7ACB55-03FD-4EF6-A116-D6E85BC0C605}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MockApp", "tests\Forms\MockApp\MockApp.csproj", "{0E7ACB55-03FD-4EF6-A116-D6E85BC0C605}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Prism.Forms.Regions", "src\Forms\Prism.Forms.Regions\Prism.Forms.Regions.csproj", "{7E197F24-C16B-4A20-BA37-685C473FFE11}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Prism.Forms.Regions", "src\Forms\Prism.Forms.Regions\Prism.Forms.Regions.csproj", "{7E197F24-C16B-4A20-BA37-685C473FFE11}"
EndProject
Global
GlobalSection(SharedMSBuildProjectFiles) = preSolution
Expand Down Expand Up @@ -154,6 +154,30 @@ Global
{2FD30CAF-6930-41F3-8104-3D018C8BDD9E}.Release|x64.Build.0 = Release|Any CPU
{2FD30CAF-6930-41F3-8104-3D018C8BDD9E}.Release|x86.ActiveCfg = Release|Any CPU
{2FD30CAF-6930-41F3-8104-3D018C8BDD9E}.Release|x86.Build.0 = Release|Any CPU
{0E7ACB55-03FD-4EF6-A116-D6E85BC0C605}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0E7ACB55-03FD-4EF6-A116-D6E85BC0C605}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0E7ACB55-03FD-4EF6-A116-D6E85BC0C605}.Debug|x64.ActiveCfg = Debug|Any CPU
{0E7ACB55-03FD-4EF6-A116-D6E85BC0C605}.Debug|x64.Build.0 = Debug|Any CPU
{0E7ACB55-03FD-4EF6-A116-D6E85BC0C605}.Debug|x86.ActiveCfg = Debug|Any CPU
{0E7ACB55-03FD-4EF6-A116-D6E85BC0C605}.Debug|x86.Build.0 = Debug|Any CPU
{0E7ACB55-03FD-4EF6-A116-D6E85BC0C605}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0E7ACB55-03FD-4EF6-A116-D6E85BC0C605}.Release|Any CPU.Build.0 = Release|Any CPU
{0E7ACB55-03FD-4EF6-A116-D6E85BC0C605}.Release|x64.ActiveCfg = Release|Any CPU
{0E7ACB55-03FD-4EF6-A116-D6E85BC0C605}.Release|x64.Build.0 = Release|Any CPU
{0E7ACB55-03FD-4EF6-A116-D6E85BC0C605}.Release|x86.ActiveCfg = Release|Any CPU
{0E7ACB55-03FD-4EF6-A116-D6E85BC0C605}.Release|x86.Build.0 = Release|Any CPU
{7E197F24-C16B-4A20-BA37-685C473FFE11}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7E197F24-C16B-4A20-BA37-685C473FFE11}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7E197F24-C16B-4A20-BA37-685C473FFE11}.Debug|x64.ActiveCfg = Debug|Any CPU
{7E197F24-C16B-4A20-BA37-685C473FFE11}.Debug|x64.Build.0 = Debug|Any CPU
{7E197F24-C16B-4A20-BA37-685C473FFE11}.Debug|x86.ActiveCfg = Debug|Any CPU
{7E197F24-C16B-4A20-BA37-685C473FFE11}.Debug|x86.Build.0 = Debug|Any CPU
{7E197F24-C16B-4A20-BA37-685C473FFE11}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7E197F24-C16B-4A20-BA37-685C473FFE11}.Release|Any CPU.Build.0 = Release|Any CPU
{7E197F24-C16B-4A20-BA37-685C473FFE11}.Release|x64.ActiveCfg = Release|Any CPU
{7E197F24-C16B-4A20-BA37-685C473FFE11}.Release|x64.Build.0 = Release|Any CPU
{7E197F24-C16B-4A20-BA37-685C473FFE11}.Release|x86.ActiveCfg = Release|Any CPU
{7E197F24-C16B-4A20-BA37-685C473FFE11}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -173,6 +197,8 @@ Global
{09DC3C91-141C-468E-9CE6-71091A95BED8} = {07A089D7-5FAF-492A-BE7F-B854E255E32C}
{D66336A6-07E5-401A-A710-DAEDD6975D59} = {09DC3C91-141C-468E-9CE6-71091A95BED8}
{6E7EC81D-DA39-4C4F-A898-0148558C34F4} = {09DC3C91-141C-468E-9CE6-71091A95BED8}
{0E7ACB55-03FD-4EF6-A116-D6E85BC0C605} = {CF8CB255-8A76-48A7-B09A-88B14648D3A8}
{7E197F24-C16B-4A20-BA37-685C473FFE11} = {CFDB2435-DE4F-4A95-A612-35671358F0A5}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {E03CA9C3-F24B-442E-B378-C325728E9E29}
Expand Down
26 changes: 26 additions & 0 deletions src/Forms/Prism.Forms/Extensions/VisualElementExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using Xamarin.Forms;

namespace Prism.Extensions
{
internal static class VisualElementExtensions
{
public static bool TryGetParentPage(this VisualElement element, out Page page)
{
page = GetParentPage(element);
return page != null;
}

private static Page GetParentPage(Element visualElement)
{
switch (visualElement.Parent)
{
case Page page:
return page;
case null:
return null;
default:
return GetParentPage(visualElement.Parent);
}
}
}
}
63 changes: 1 addition & 62 deletions src/Forms/Prism.Forms/Mvvm/ViewModelLocator.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System;
using System.Collections.Generic;
using Xamarin.Forms;
using Xamarin.Forms;

namespace Prism.Mvvm
{
Expand All @@ -15,16 +13,6 @@ public static class ViewModelLocator
public static readonly BindableProperty AutowireViewModelProperty =
BindableProperty.CreateAttached("AutowireViewModel", typeof(bool?), typeof(ViewModelLocator), null, propertyChanged: OnAutowireViewModelChanged);

/// <summary>
/// Instructs Prism to use a given page as the parent for a Partial View
/// </summary>
[Obsolete("This API is Obsolete and will be removed during the 8.0 previews")]
public static readonly BindableProperty AutowirePartialViewProperty =
BindableProperty.CreateAttached("AutowirePartialView", typeof(Page), typeof(ViewModelLocator), null, propertyChanged: OnAutowirePartialViewChanged);

internal static readonly BindableProperty PartialViewsProperty =
BindableProperty.CreateAttached("PrismPartialViews", typeof(List<BindableObject>), typeof(ViewModelLocator), null);

/// <summary>
/// Gets the AutowireViewModel property value.
/// </summary>
Expand All @@ -45,62 +33,13 @@ public static void SetAutowireViewModel(BindableObject bindable, bool? value)
bindable.SetValue(ViewModelLocator.AutowireViewModelProperty, value);
}

[Obsolete("This API is Obsolete and will be removed during the 8.0 previews")]
public static Page GetAutowirePartialView(BindableObject bindable)
{
return (Page)bindable.GetValue(AutowirePartialViewProperty);
}

[Obsolete("This API is Obsolete and will be removed during the 8.0 previews")]
public static void SetAutowirePartialView(BindableObject bindable, Page page)
{
bindable.SetValue(AutowirePartialViewProperty, page);
}

[Obsolete("This API is Obsolete and will be removed during the 8.0 previews")]
internal static List<BindableObject> GetPartialViews(this Page page)
{
return (List<BindableObject>)page.GetValue(PartialViewsProperty);
}

private static void OnAutowireViewModelChanged(BindableObject bindable, object oldValue, object newValue)
{
bool? bNewValue = (bool?)newValue;
if (bNewValue.HasValue && bNewValue.Value)
ViewModelLocationProvider.AutoWireViewModelChanged(bindable, Bind);
}

[Obsolete("This API is Obsolete and will be removed during the 8.0 previews")]
private static void OnAutowirePartialViewChanged(BindableObject bindable, object oldValue, object newValue)
{
if (oldValue == newValue)
return;

if (oldValue is Page oldPage)
{
List<BindableObject> oldPartials = oldPage.GetPartialViews();
oldPartials.Remove(bindable);
}

if (newValue is Page page)
{
// Add View to Views Collection for Page.
List<BindableObject> partialViews = page.GetPartialViews();
if (partialViews == null)
{
partialViews = new List<BindableObject>();
page.SetValue(PartialViewsProperty, partialViews);
}

partialViews.Add(bindable);
// Set Autowire Property
if (bindable.GetValue(AutowireViewModelProperty) == null)
{
bindable.SetValue(AutowireViewModelProperty, true);
}
}
}

/// <summary>
/// Sets the <see cref="Xamarin.Forms.BindableObject.BindingContext"/> of a View
/// </summary>
Expand Down
17 changes: 6 additions & 11 deletions src/Forms/Prism.Forms/PrismApplicationBase.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Prism.AppModel;
using Prism.Behaviors;
using Prism.Common;
using Prism.Events;
using Prism.Extensions;
using Prism.Ioc;
using Prism.Logging;
using Prism.Modularity;
using Prism.Mvvm;
using Prism.Navigation;
using Prism.Services;
using Prism.Services.Dialogs;
using System;
using System.Collections.Generic;
using System.Linq;
using Xamarin.Forms;
using Xamarin.Forms.Internals;

Expand Down Expand Up @@ -127,15 +128,9 @@ private INavigationService CreateNavigationService(object view)
{
return Navigation.Xaml.Navigation.GetNavigationService(page);
}
else if (view is VisualElement visualElement)
else if (view is VisualElement visualElement && visualElement.TryGetParentPage(out var parent))
{
page = ViewModelLocator.GetAutowirePartialView(visualElement);
if (page != null)
{
return CreateNavigationService(page);
}

return CreateNavigationService(visualElement.Parent);
return Navigation.Xaml.Navigation.GetNavigationService(parent);
}

return Container.Resolve<INavigationService>();
Expand Down
105 changes: 0 additions & 105 deletions tests/Forms/Prism.DI.Forms.Tests/Fixtures/PartialViewFixture.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
</ResourceDictionary>
</ContentPage.Resources>
<StackLayout>
<local:PartialView mvvm:ViewModelLocator.AutowirePartialView="{x:Reference xamlViewMock}" />
<Entry x:Name="testEntry"
Text="{Binding Test,Converter={StaticResource mockValueConverter}}" />
</StackLayout>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
<Compile Include="$(MSBuildThisFileDirectory)Fixtures\Ioc\ContainerProviderFixture.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Fixtures\FixtureBase.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Fixtures\Navigation\XamlNavigationFixture.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Fixtures\PartialViewFixture.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Fixtures\PrismApplicationFixture.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Mocks\Converters\MockValueConverter.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Mocks\Events\TestActionEvent.cs" />
Expand Down

0 comments on commit b70f870

Please sign in to comment.