Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for MAUI Embedding #60

Open
2 tasks done
andreas-nesheim opened this issue Apr 18, 2023 · 5 comments
Open
2 tasks done

Support for MAUI Embedding #60

andreas-nesheim opened this issue Apr 18, 2023 · 5 comments

Comments

@andreas-nesheim
Copy link

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

  • Android
  • iOS

MAUIEmbedding.zip

@bakerhillpins
Copy link
Contributor

bakerhillpins commented May 18, 2023

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
Copy link

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,

  • First issue, caused the Window to display with a white background. There is a line of code in the constructor of PopupWindow.cs that set the background to be transparent, that I uncommented and it fixed the issue.
  • Second issue, caused my app to crash and it occurred when I opened and closed the popup repeatedly. The HitTest in the UIWindow is getting raised multiple times and this seems to cause issues when it tries to close the popup. I added the _stop boolean to just prevent anymore calls to SendBackgroundClick.

@AldairOrta
Copy link

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
Copy link

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
Copy link
Owner

@ultimategrandson

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants