From a17ed50cebe1e920ab3b614f0ca24a598209d865 Mon Sep 17 00:00:00 2001 From: Ali Yousefi Date: Wed, 25 Sep 2024 08:15:05 +0330 Subject: [PATCH 1/2] fix: fix OnBackButtonPressedAction to return bool --- .../Interfaces/IPage.cs | 2 +- .../Design/Pages/EasyContentPage.cs | 5 +-- .../Navigations/DefaultNavigationManager.cs | 36 +++++++++++++++++-- 3 files changed, 38 insertions(+), 5 deletions(-) diff --git a/src/CSharp/Cores/EasyMicroservices.UI.Cores.Mvvm/Interfaces/IPage.cs b/src/CSharp/Cores/EasyMicroservices.UI.Cores.Mvvm/Interfaces/IPage.cs index 22c9516..6a200db 100644 --- a/src/CSharp/Cores/EasyMicroservices.UI.Cores.Mvvm/Interfaces/IPage.cs +++ b/src/CSharp/Cores/EasyMicroservices.UI.Cores.Mvvm/Interfaces/IPage.cs @@ -16,7 +16,7 @@ public interface IPage /// /// /// - Action OnBackButtonPressedAction { get; set; } + Func OnBackButtonPressedAction { get; set; } /// /// /// diff --git a/src/CSharp/MauiComponents/EasyMicroservices.UI.MauiComponents/Design/Pages/EasyContentPage.cs b/src/CSharp/MauiComponents/EasyMicroservices.UI.MauiComponents/Design/Pages/EasyContentPage.cs index 1ae5acd..e6a9b04 100644 --- a/src/CSharp/MauiComponents/EasyMicroservices.UI.MauiComponents/Design/Pages/EasyContentPage.cs +++ b/src/CSharp/MauiComponents/EasyMicroservices.UI.MauiComponents/Design/Pages/EasyContentPage.cs @@ -14,13 +14,14 @@ private void CustomContentPage_Loaded(object sender, EventArgs e) OnLoadComplete?.Invoke(); } - public Action OnBackButtonPressedAction { get; set; } + public Func OnBackButtonPressedAction { get; set; } public Action OnLoadComplete { get; set; } protected override bool OnBackButtonPressed() { - OnBackButtonPressedAction?.Invoke(); + if (OnBackButtonPressedAction is not null) + return OnBackButtonPressedAction(); return base.OnBackButtonPressed(); } diff --git a/src/CSharp/MauiComponents/EasyMicroservices.UI.MauiComponents/Navigations/DefaultNavigationManager.cs b/src/CSharp/MauiComponents/EasyMicroservices.UI.MauiComponents/Navigations/DefaultNavigationManager.cs index 4bcda6f..3ef1187 100644 --- a/src/CSharp/MauiComponents/EasyMicroservices.UI.MauiComponents/Navigations/DefaultNavigationManager.cs +++ b/src/CSharp/MauiComponents/EasyMicroservices.UI.MauiComponents/Navigations/DefaultNavigationManager.cs @@ -43,7 +43,26 @@ public override async Task PushDataAsync(TD if (page.BindingContext is IResponsibleViewModel responsibleViewModel) { if (ipage != null) - ipage.OnBackButtonPressedAction = responsibleViewModel.Close; + { + if (ipage.OnBackButtonPressedAction is null) + { + ipage.OnBackButtonPressedAction = () => + { + responsibleViewModel.Close(); + return true; + }; + } + else + { + var func = ipage.OnBackButtonPressedAction; + ipage.OnBackButtonPressedAction = () => + { + responsibleViewModel.Close(); + return func(); + }; + } + } + var result = await responsibleViewModel.GetResult(); if (result != null && result is TResponseData responseData) return responseData; @@ -92,7 +111,7 @@ public override Task OpenBrowser(string url) /// /// /// - public void RegisterContentPage(string pageName) + public virtual void RegisterContentPage(string pageName) where TView : ContentView, new() { Pages.TryAdd(pageName, () => @@ -103,4 +122,17 @@ public void RegisterContentPage(string pageName) }; }); } + + public virtual void RegisterContentPage(string pageName) + where TView : ContentView, new() + where TEasyContentPage : EasyContentPage, new() + { + Pages.TryAdd(pageName, () => + { + return new TEasyContentPage() + { + Content = new TView() + }; + }); + } } \ No newline at end of file From 6d6cfcfd017a23da74177a4ade6818a18a183160 Mon Sep 17 00:00:00 2001 From: Ali Yousefi Date: Wed, 25 Sep 2024 08:16:27 +0330 Subject: [PATCH 2/2] fix: update packages --- .../EasyMicroservices.UI.Cores.Mvvm.csproj | 2 +- .../EasyMicroservices.UI.MauiComponents.csproj | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/CSharp/Cores/EasyMicroservices.UI.Cores.Mvvm/EasyMicroservices.UI.Cores.Mvvm.csproj b/src/CSharp/Cores/EasyMicroservices.UI.Cores.Mvvm/EasyMicroservices.UI.Cores.Mvvm.csproj index b1accd6..3427225 100644 --- a/src/CSharp/Cores/EasyMicroservices.UI.Cores.Mvvm/EasyMicroservices.UI.Cores.Mvvm.csproj +++ b/src/CSharp/Cores/EasyMicroservices.UI.Cores.Mvvm/EasyMicroservices.UI.Cores.Mvvm.csproj @@ -5,7 +5,7 @@ AnyCPU;x64;x86 EasyMicroservices true - 0.0.0.23 + 0.0.0.24 Model View View Model EasyMicroservices@gmail.com mvvm,mvpvm,modelview,modelviewviewmodel diff --git a/src/CSharp/MauiComponents/EasyMicroservices.UI.MauiComponents/EasyMicroservices.UI.MauiComponents.csproj b/src/CSharp/MauiComponents/EasyMicroservices.UI.MauiComponents/EasyMicroservices.UI.MauiComponents.csproj index 7eb78a9..d4a2d12 100644 --- a/src/CSharp/MauiComponents/EasyMicroservices.UI.MauiComponents/EasyMicroservices.UI.MauiComponents.csproj +++ b/src/CSharp/MauiComponents/EasyMicroservices.UI.MauiComponents/EasyMicroservices.UI.MauiComponents.csproj @@ -18,7 +18,7 @@ AnyCPU;x64;x86 EasyMicroservices true - 0.0.0.19 + 0.0.0.20 Maui easy and light components EasyMicroservices@gmail.com maui,ui,component,components