forked from LuckyDucko/Mopups
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
LuckyDucko#63 Fix: Issues with setup and use of configurable animations.
Using dynamic loading of types and values.
- Loading branch information
1 parent
878d1c6
commit 4a06b8f
Showing
3 changed files
with
199 additions
and
242 deletions.
There are no files selected for viewing
215 changes: 107 additions & 108 deletions
215
Mopups/Mopups.Maui/Platforms/Windows/Impl/PopupPlatformWindows.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,108 +1,107 @@ | ||
| ||
using System; | ||
using Microsoft.Maui.Platform; | ||
using Mopups.Interfaces; | ||
using Mopups.Pages; | ||
using Mopups.Platforms.Windows; | ||
using Mopups.Services; | ||
|
||
namespace Mopups.Windows.Implementation | ||
{ | ||
class PopupPlatformWindows : IPopupPlatform | ||
{ | ||
private IPopupNavigation PopupNavigationInstance => MopupService.Instance; | ||
|
||
//public event EventHandler OnInitialized | ||
//{ | ||
// add => Popup.OnInitialized += value; | ||
// remove => Popup.OnInitialized -= value; | ||
//} | ||
|
||
//public bool IsInitialized => Popup.IsInitialized; | ||
|
||
public bool IsSystemAnimationEnabled => true; | ||
|
||
public PopupPlatformWindows() | ||
{ | ||
//SystemNavigationManager.GetForCurrentView().BackRequested += OnBackRequested; | ||
} | ||
|
||
public static bool SendBackPressed(Action? backPressedHandler = null) | ||
{ | ||
var popupNavigationInstance = MopupService.Instance; | ||
|
||
if (popupNavigationInstance.PopupStack.Count > 0) | ||
{ | ||
var lastPage = popupNavigationInstance.PopupStack[popupNavigationInstance.PopupStack.Count - 1]; | ||
|
||
var isPreventClose = lastPage.SendBackButtonPressed(); | ||
|
||
if (!isPreventClose) | ||
{ | ||
popupNavigationInstance.PopAsync().SafeFireAndForget(); | ||
} | ||
|
||
return true; | ||
} | ||
|
||
backPressedHandler?.Invoke(); | ||
|
||
return false; | ||
} | ||
|
||
public async Task AddAsync(PopupPage page) | ||
{ | ||
page.Parent = Application.Current.MainPage; | ||
|
||
var popup = new global::Microsoft.UI.Xaml.Controls.Primitives.Popup(); | ||
|
||
// Use TOPLATFORM to create your handlers | ||
// I'd recommend wiring up all your services through ConfigureMopups | ||
// builder.Services.AddScoped<IPopupPlatform, PopupPlatform>(); | ||
// builder.Services.AddScoped<IPopupNavigation, PopupNavigation>(); | ||
// Then you can use contructor resolution instead of singletons | ||
// But I figured we could do that in a later PR and just work on windows here | ||
|
||
var renderer = (PopupPageRenderer)page.ToPlatform(Application.Current.MainPage.Handler.MauiContext); | ||
|
||
renderer.Prepare(popup); | ||
popup.Child = renderer; | ||
|
||
|
||
// https://github.com/microsoft/microsoft-ui-xaml/issues/3389 | ||
popup.XamlRoot = | ||
Application.Current.MainPage.Handler.MauiContext.Services.GetService<Microsoft.UI.Xaml.Window>().Content.XamlRoot; | ||
|
||
popup.IsOpen = true; | ||
page.ForceLayout(); | ||
|
||
await Task.Delay(5); | ||
} | ||
|
||
public async Task RemoveAsync(PopupPage page) | ||
{ | ||
if (page == null) | ||
throw new Exception("Popup page is null"); | ||
|
||
var renderer = (PopupPageRenderer)page.ToPlatform(Application.Current.MainPage.Handler.MauiContext); | ||
var popup = renderer.Container; | ||
|
||
if (popup != null) | ||
{ | ||
renderer.Destroy(); | ||
|
||
Cleanup(page); | ||
page.Parent = null; | ||
popup.Child = null; | ||
popup.IsOpen = false; | ||
} | ||
|
||
await Task.Delay(5); | ||
} | ||
|
||
internal static void Cleanup(VisualElement element) | ||
{ | ||
element.Handler?.DisconnectHandler(); | ||
} | ||
} | ||
} | ||
using AsyncAwaitBestPractices; | ||
using Microsoft.Maui.Platform; | ||
using Mopups.Interfaces; | ||
using Mopups.Pages; | ||
using Mopups.Platforms.Windows; | ||
using Mopups.Services; | ||
|
||
namespace Mopups.Windows.Implementation | ||
{ | ||
class PopupPlatformWindows : IPopupPlatform | ||
{ | ||
private IPopupNavigation PopupNavigationInstance => MopupService.Instance; | ||
|
||
//public event EventHandler OnInitialized | ||
//{ | ||
// add => Popup.OnInitialized += value; | ||
// remove => Popup.OnInitialized -= value; | ||
//} | ||
|
||
//public bool IsInitialized => Popup.IsInitialized; | ||
|
||
public bool IsSystemAnimationEnabled => true; | ||
|
||
public PopupPlatformWindows() | ||
{ | ||
//SystemNavigationManager.GetForCurrentView().BackRequested += OnBackRequested; | ||
} | ||
|
||
public static bool SendBackPressed(Action? backPressedHandler = null) | ||
{ | ||
var popupNavigationInstance = MopupService.Instance; | ||
|
||
if (popupNavigationInstance.PopupStack.Count > 0) | ||
{ | ||
var lastPage = popupNavigationInstance.PopupStack[popupNavigationInstance.PopupStack.Count - 1]; | ||
|
||
var isPreventClose = lastPage.SendBackButtonPressed(); | ||
|
||
if (!isPreventClose) | ||
{ | ||
popupNavigationInstance.PopAsync().SafeFireAndForget(); | ||
} | ||
|
||
return true; | ||
} | ||
|
||
backPressedHandler?.Invoke(); | ||
|
||
return false; | ||
} | ||
|
||
public async Task AddAsync(PopupPage page) | ||
{ | ||
page.Parent = Application.Current.MainPage; | ||
|
||
var popup = new global::Microsoft.UI.Xaml.Controls.Primitives.Popup(); | ||
|
||
// Use TOPLATFORM to create your handlers | ||
// I'd recommend wiring up all your services through ConfigureMopups | ||
// builder.Services.AddScoped<IPopupPlatform, PopupPlatform>(); | ||
// builder.Services.AddScoped<IPopupNavigation, PopupNavigation>(); | ||
// Then you can use contructor resolution instead of singletons | ||
// But I figured we could do that in a later PR and just work on windows here | ||
|
||
var renderer = (PopupPageRenderer)page.ToPlatform(Application.Current.MainPage.Handler.MauiContext); | ||
|
||
renderer.Prepare(popup); | ||
popup.Child = renderer; | ||
|
||
|
||
// https://github.com/microsoft/microsoft-ui-xaml/issues/3389 | ||
popup.XamlRoot = | ||
Application.Current.MainPage.Handler.MauiContext.Services.GetService<Microsoft.UI.Xaml.Window>().Content.XamlRoot; | ||
|
||
popup.IsOpen = true; | ||
page.ForceLayout(); | ||
|
||
await Task.Delay(5); | ||
} | ||
|
||
public async Task RemoveAsync(PopupPage page) | ||
{ | ||
if (page == null) | ||
throw new Exception("Popup page is null"); | ||
|
||
var renderer = (PopupPageRenderer)page.ToPlatform(Application.Current.MainPage.Handler.MauiContext); | ||
var popup = renderer.Container; | ||
|
||
if (popup != null) | ||
{ | ||
renderer.Destroy(); | ||
|
||
Cleanup(page); | ||
page.Parent = null; | ||
popup.Child = null; | ||
popup.IsOpen = false; | ||
} | ||
|
||
await Task.Delay(5); | ||
} | ||
|
||
internal static void Cleanup(VisualElement element) | ||
{ | ||
element.Handler?.DisconnectHandler(); | ||
} | ||
} | ||
} |
Oops, something went wrong.