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

[Enhancement] Embedding MAUI-Open MAUI "Page" from Xamarin.Android #9606

Open
Tracked by #1718
saamerm opened this issue Aug 23, 2022 · 2 comments
Open
Tracked by #1718

[Enhancement] Embedding MAUI-Open MAUI "Page" from Xamarin.Android #9606

saamerm opened this issue Aug 23, 2022 · 2 comments
Labels
area-controls-general General issues that span multiple controls, or common base classes such as View or Element platform/android 🤖 proposal/open t/native-embedding
Milestone

Comments

@saamerm
Copy link

saamerm commented Aug 23, 2022

Description

As you can see in the current MAUI PageExtensions available for Android and iOS, MAUI allows you to convert any type of MAUI Page to a native ViewController in iOS, but it only allows converting a MAUI ContentPage to a native Fragment in Android.

The MAUI Page plays a major role when you are trying to implement an MAUI NavigationPage or TabbedPage allowing for a dashboard with tabs and subsequently being able to navigate between pages without having to go back into native code. So, currently I can handover complete control to MAUI on iOS, but on Android I can only use MAUI to display a single ContentPage with no control over navigation.

My request is to extend the API to allow opening an MAUI Page from Xamarin.Android, rather than just a ContentPage.

Public API Changes

This would require creating an overridden constructor in the /AppCompat/PageExtensions.cs file referenced above that would take a Page and instead of a ContentPage. I am not sure of the other changes this would require to make this happen in the MAUI .Platform.Android project.

Intended Use-Case

This would be great for teams trying to use Embedding to convert projects from using Xamarin.Native to MAUI, for easier maintenance & implementation of features, to prevent so many people from switching to other Multi-platform App UI frameworks instead. We could create a "Migration Guide from Xamarin Native to MAUI" too which would be super attractive for so many companies!

Added Explanation: You can open NavigationPages on iOS, as you can see in this sample here which allows using functions like PushAsync or PopAsync, by simply doing:

UIViewController user2 = new NavigationPage(new TestPage()).CreateViewController();

So for Android as seen here, currently we can only do this: ✅

Android.Support.V4.App.Fragment fragment = new TestPage().CreateSupportFragment(this);

and we need to create a way to do something like this: ❌

Android.Support.V4.App.Fragment fragment = new NavigationPage(new TestPage()).CreateSupportFragment(this);

PS: Here's a sample Github that contains a playground created as a Spike. If someone knows of a work around, please let me know.

@ghost
Copy link

ghost commented Aug 23, 2022

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.

@qrys
Copy link

qrys commented Aug 7, 2023

we are implementing something similar as a strategic approach in converting our Xamarin Native app to MAUI adopting a Strangler Fig pattern.

We are using the following snippet:

        MauiAppBuilder builder = MauiApp.CreateBuilder();
        builder.UseMauiEmbedding<Microsoft.Maui.Controls.Application>();
        _mauiApp = builder.Build();
        MauiContext mauiContext = new MauiContext(_mauiApp.Services, this);
        MauiPage1 mainPage = new(this);

        Android.Views.View view = mainPage.ToContainerView(mauiContext);
        SetContentView(view);

It appears that we can load the maui page this way, however, as you have mentioned, could not navigate to another maui page using the Navigation class, ie.

Navigation.PushAsync(new MauiPage2(_parentView));

upon investigating the contents of Navigation, it would appear that MauiPage2 is actually pushed into the NavigationStack but is not rendering or becoming the main screen. Perhaps, the issue is around this section of the Navigation class???

@saamerm have you had any progress with this?
@jsuarezruiz @jfversluis do you have info if this will be resolved in the next release?

what would be the process involved if I want to help and look into this ticket?

note: Native embedding on iOS appears to work as expected without issues

@Eilon Eilon added the area-controls-general General issues that span multiple controls, or common base classes such as View or Element label May 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-controls-general General issues that span multiple controls, or common base classes such as View or Element platform/android 🤖 proposal/open t/native-embedding
Projects
None yet
Development

No branches or pull requests

5 participants