Skip to content

Commit

Permalink
Merge pull request #18 from Ali-YousefiTelori/develop
Browse files Browse the repository at this point in the history
add custom content page creator
  • Loading branch information
Ali-YousefiTelori authored Dec 22, 2023
2 parents 80a4995 + 4a44e16 commit 591343b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public abstract class NavigationManagerBase
/// <summary>
///
/// </summary>
protected ConcurrentDictionary<string, Type> Pages { get; set; } = new ConcurrentDictionary<string, Type>();
protected ConcurrentDictionary<string, Func<IPage>> Pages { get; set; } = new ConcurrentDictionary<string, Func<IPage>>();

/// <summary>
///
Expand Down Expand Up @@ -76,6 +76,6 @@ public abstract class NavigationManagerBase
public void RegisterPage<T>(string pageName)
where T : IPage, new()
{
Pages.TryAdd(pageName, typeof(T));
Pages.TryAdd(pageName, () => new T());
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using EasyMicroservices.UI.Cores;
using EasyMicroservices.UI.Cores.Interfaces;
using EasyMicroservices.UI.Cores.Navigations;
using EasyMicroservices.UI.MauiComponents.Design.Pages;

namespace EasyMicroservices.UI.MauiComponents.Navigations;
public class DefaultNavigationManager : NavigationManagerBase
Expand All @@ -23,9 +24,9 @@ public override Task<TResponseData> PushAsync<TResponseData>(string pageName, bo

public override async Task<TResponseData> PushDataAsync<TData, TResponseData>(TData data, string pageName, bool doClear = false)
{
if (!Pages.TryGetValue(pageName, out Type pageTpe))
if (!Pages.TryGetValue(pageName, out Func<IPage> pageCreator))
throw new Exception($"Page {pageName} not found, did you register it?");
var findPage = Activator.CreateInstance(pageTpe);
var findPage = pageCreator();
ContentPage page = findPage as ContentPage;
if (page == null)
throw new NotImplementedException($"Page {pageName} is not inherit Page!");
Expand Down Expand Up @@ -86,4 +87,20 @@ public override Task<bool> OpenBrowser(string url)
{
return Browser.OpenAsync(url, BrowserLaunchMode.SystemPreferred);
}

/// <summary>
///
/// </summary>
/// <param name="pageName"></param>
public void RegisterContentPage<TView>(string pageName)
where TView : ContentView, new()
{
Pages.TryAdd(pageName, () =>
{
return new EasyContentPage()
{
Content = new TView()
};
});
}
}

0 comments on commit 591343b

Please sign in to comment.