LuckyDucko / Mopups

Popups For MAUI
BSD 3-Clause "New" or "Revised" License
271 stars 49 forks source link

Support for MAUI Embedding #60

Open andreas-nesheim opened 1 year ago

andreas-nesheim commented 1 year ago

SUMMARY Hi! Thank you very much for your work in porting this library to .NET MAUI, it is greatly appreciated!

We have an app that utilizes MAUI Embedding to use MAUI pages in ".NET for Android" and ".NET for iOS" apps (previously Xamarin.Android and Xamarin.iOS). I was hoping to use your library in this app, but it seems that the Mopups registration doesn't seem to take effect when using this approach. Do you know if this is possible at all with this approach, or if this is something that's possible to implement? When I try to open a popup page from the iOS project, I get this error at runtime:

System.NullReferenceException: Object reference not set to an instance of an object. at Mopups.iOS.Implementation.iOSMopups.AddAsync(PopupPage page) at Mopups.Services.PopupNavigation.<>c__DisplayClass20_0.<<PushAsync>g__PushPage|0>d.MoveNext()

On Android I just get a NullReferenceException at runtime.

DETAILS The use-case involves having one class library for the iOS/Android app and one class library where the MAUI pages are located. I use the embedding technique (as described in the previous link) and I use the host builder to add the .ConfigureMopups() in my AppDelegate.cs / MainActivity.cs. I've attached a repro of a project that uses MAUI embedding and that tries to use this package.

I understand that this embedding technique might not be all that used, but it would be great if there is a way to make this package work with this setup.

PLATFORMS

MAUIEmbedding.zip

bakerhillpins commented 1 year ago

On Android anyway, (iOS probably similar), MauiApplication.Current is null. How does one get this to become initialized or what should one be using instead of this?

page.Parent = MauiApplication.Current.Application.Windows[0].Content as Element;

Apparently Alerts in MAUI have the same issue, so it's probably going to be a race to see who takes on the solution first.

ultimategrandson commented 1 year ago

I have made some changes to make Mopups work with Maui Embedded. So far so good...

The main change I made was to check if the PopupPage.Parent is null or not before setting it to the MauiApplication.Current..Windows[0].Content

To make it work with Maui Embedded when you create your popup page:

I also fixed couple issues on iOS, I'm not sure if these were a result of using Maui Embedded or not but,

AldairOrta commented 1 year ago

Does it could solve the issue that when showing (for example) a loading popup before a navigation page "PushAsync" the popup stays in the backgroud ?

ultimategrandson commented 1 year ago

Nope. It looks like if you use Maui Embedded anything relating to navigation, like pushing/popping views and events like Appearing/Disappearing either don't work properly or not at all.

To fix those issues, you will have to implement it yourself, using MaterialAlertDialogBuilder on android or UIAlertController on iOS.

LuckyDucko commented 1 year ago

@ultimategrandson

Just clocking in noticed your work, i should make another release with this in the mix