diff --git a/src/Prism.Forms.Extended/ViewModels/DefaultViewModel.cs b/src/Prism.Forms.Extended/ViewModels/DefaultViewModel.cs index 400059e..c666d45 100644 --- a/src/Prism.Forms.Extended/ViewModels/DefaultViewModel.cs +++ b/src/Prism.Forms.Extended/ViewModels/DefaultViewModel.cs @@ -1,9 +1,9 @@ -using Prism.AppModel; -using Prism.Mvvm; +using Prism.Mvvm; +using Prism.Navigation; namespace Prism.Forms.Extended.ViewModels { - internal class DefaultViewModel : BindableBase, IAutoInitialize + internal class DefaultViewModel : BindableBase, IInitialize { private string _title; public string Title @@ -11,5 +11,14 @@ public string Title get => _title; set => SetProperty(ref _title, value); } + + public void Initialize(INavigationParameters parameters) + { + if(parameters.TryGetValue("Title", out string title) || + parameters.TryGetValue("title", out title)) + { + Title = title; + } + } } } diff --git a/src/Shiny.Prism/Modularity/IContainerRegistryAutoLoadExtensions.cs b/src/Shiny.Prism/Modularity/IContainerRegistryAutoLoadExtensions.cs deleted file mode 100644 index e2f84a6..0000000 --- a/src/Shiny.Prism/Modularity/IContainerRegistryAutoLoadExtensions.cs +++ /dev/null @@ -1,52 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Reflection; -using Prism; -using Prism.Ioc; -using Xamarin.Forms; - -namespace Shiny.Prism.Modularity -{ - internal static class IContainerRegistryAutoLoadExtensions - { - public static void AutoRegisterViews(this Type type, IContainerRegistry containerRegistry) - { - if (!type.GetCustomAttributes().Any(a => a is AutoRegisterForNavigationAttribute)) return; - - var regAttr = type.GetCustomAttribute(); - var assembly = type.Assembly; - - var viewTypes = assembly.ExportedTypes.Where(t => t.IsSubclassOf(typeof(Page))); - RegisterViewsAutomatically(containerRegistry, viewTypes); - } - - private static void RegisterViewsAutomatically(IContainerRegistry containerRegistry, IEnumerable viewTypes) - { - foreach (var viewType in viewTypes) - { - RegisterView(containerRegistry, viewType); - } - - RegisterView(containerRegistry, typeof(NavigationPage), true); - RegisterView(containerRegistry, typeof(TabbedPage), true); - } - - private static void RegisterView(IContainerRegistry containerRegistry, Type viewType, bool checkIfRegistered = false) - { - //var name = AutoRegistrationViewNameProvider.GetNavigationSegmentName(viewType); - var name = GetNavigationSegmentName(viewType); - - if (!checkIfRegistered || containerRegistry.IsRegistered(name)) - { - containerRegistry.RegisterForNavigation(viewType, name); - } - } - - internal static string GetNavigationSegmentName(Type type) - { - var nameProviderType = Type.GetType("Prism.Ioc.AutoRegistrationViewNameProvider, Prism.Forms"); - return (string)nameProviderType.GetMethod(nameof(GetNavigationSegmentName)).Invoke(null, new[] { type }); - } - } -} diff --git a/src/Shiny.Prism/Modularity/ShinyPrismModuleInitializer.cs b/src/Shiny.Prism/Modularity/ShinyPrismModuleInitializer.cs index e124048..1d609f4 100644 --- a/src/Shiny.Prism/Modularity/ShinyPrismModuleInitializer.cs +++ b/src/Shiny.Prism/Modularity/ShinyPrismModuleInitializer.cs @@ -25,7 +25,6 @@ public void Initialize(IModuleInfo moduleInfo) if (module != null) { module.RegisterTypes(_container); - module.GetType().AutoRegisterViews(_container); module.OnInitialized(_container); } } diff --git a/tests/Prism.Forms.Extended.Mocks/Mocks/AppMock.xaml.cs b/tests/Prism.Forms.Extended.Mocks/Mocks/AppMock.xaml.cs index dd68d94..5afcfdb 100644 --- a/tests/Prism.Forms.Extended.Mocks/Mocks/AppMock.xaml.cs +++ b/tests/Prism.Forms.Extended.Mocks/Mocks/AppMock.xaml.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using Prism.Forms.Extended.Mocks.Views; using Prism.Ioc; using Prism.Navigation; using Xamarin.Forms; @@ -11,7 +7,6 @@ namespace Prism.Forms.Extended.Mocks { [XamlCompilation(XamlCompilationOptions.Compile)] - [AutoRegisterForNavigation] public partial class AppMock : PrismApplication { public AppMock() @@ -30,6 +25,10 @@ protected override void RegisterTypes(IContainerRegistry containerRegistry) { containerRegistry.RegisterForNavigation(); containerRegistry.RegisterForNavigation(); + containerRegistry.RegisterForNavigation(); + containerRegistry.RegisterForNavigation(); + containerRegistry.RegisterForNavigation(); + containerRegistry.RegisterForNavigation(); } } } \ No newline at end of file diff --git a/tests/Shiny.Prism.Tests/Tests/ModularityTests.cs b/tests/Shiny.Prism.Tests/Tests/ModularityTests.cs index 01871dc..93977de 100644 --- a/tests/Shiny.Prism.Tests/Tests/ModularityTests.cs +++ b/tests/Shiny.Prism.Tests/Tests/ModularityTests.cs @@ -3,7 +3,6 @@ using Shiny.Prism.Mocks; using Shiny.Prism.Mocks.Modularity; using Shiny.Prism.Mocks.Modularity.Services; -using Shiny.Prism.Modularity; using Xunit; using Xunit.Abstractions; @@ -34,14 +33,5 @@ public void StartupModuleServicesAreNotRegisteredFromContainerRegistry() Assert.False(((IContainerProvider)PrismContainerExtension.Current).IsRegistered()); } - - [Fact] - public void GetNavigationSegmentNameInvokesInternalMethod() - { - var currentType = GetType(); - var segmentName = IContainerRegistryAutoLoadExtensions.GetNavigationSegmentName(currentType); - - Assert.Equal(currentType.Name, segmentName); - } } }