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

Image with FontImageSource not displaying expected font icon in Android and embedded MAUI when Finish called on initial launch Activity. #19846

Open
nau-dwb opened this issue Jan 11, 2024 · 0 comments
Labels
area-controls-image Image control area-fonts Custom fonts and Font related API's migration-compatibility Xamarin.Forms to .NET MAUI Migration, Upgrade Assistant, Try-Convert platform/android 🤖 t/bug Something isn't working

Comments

@nau-dwb
Copy link

nau-dwb commented Jan 11, 2024

Description

We're trying to migrate our Xamarin Android and Xamarin iOS application with embedded Xamarin Forms to .NET Android and iOS with embedded MAUI. I'm running into an issue in Android with Images on MAUI pages that have a font image source using a font icon file to where the image does not display.

Per some of the examples on using embedded MAUI, we initialize all the MAUI code in the launch Android Activity and save off the instance of MauiContext in a singleton for use elsewhere in the application. When converting a MAUI page to an Android Fragment, we need to provide the MAUI Context instance.

Our Android application's initial launch Activity is for a login page. Once the user authenticates, we create a new Intent for a "landing page" activity and invoke StartActivity to display this to the user. We then invoke Finish() on the initial login launch activity.

From what I've been able to determine, the fact that we invoke Finish on the launch activity that also initializes the MAUI context is the root cause of this issue. This seems like a fairly common use case though (an initial login activity that is completed after authentication once a new activity is started).

I'm not sure if any of the changes proposed in Issue 1718 would resolve this? Or if this is working as expected\designed if there's better guidance out there for how to handle the embedded MAUI experience?

This worked fine in Xamarin Forms. iOS is not impacted though that's likely due to difference in how we start up and initialize the two platforms.

This does not repro in Android if we don't invoke Finish on the launch activity. If we recreate the MAUI context in Android before navigating to the page with the font image source then it works as well.

Either simple-maui-embedded or simple-android-embedded in the provided repo have options to launch the page with it working or failing. You can also comment out Finish() in the main activity to see how that impacts it too.

Steps to Reproduce

  1. Create a .NET Android application using MAUI embedded.
  2. Create a singleton class to store the MAUI Context that will be created when the app starts.
  3. In the main launch activity, do all the MAUI initialization, create the MAUI context, and store it off in the singleton.
  4. Create a MAUI page that has an Image configured with FontImageSource binding to a glyph from an icon font file.
  5. Create a second Activity in Android. This activity on load should create an instance of the MAUI page, run it through the extension method to render it as an Android Fragment using the MAUI context instance stored in the singleton, and then add that Fragment to the stack.
  6. Back in the main launch Activity, add a button that when clicked will invoke StartActivity to launch this second Android activity. Make sure to invoke Finish() on this initial Activity after starting the new one.

Expected: The page displays with the expected image displaying the font icon.
Actual: No font icon is displayed.

Option 1 to have it work:

  1. Run through all the same prior steps but remove the call to Finish() from the initial activity - font icon image will display as expected.

Option 2 to have it work:

  1. In the second activity, recreate the MAUI initialization and MauiContext instance and use this when rendering the fragment from the page. Font icon image will display as expected.

Either simple-maui-embedded or simple-android-embedded in the provided repo can be used to further explore this.

Link to public reproduction project repository

https://github.com/nau-dwb/maui-embedded-use-issues/tree/main

Version with bug

Unknown/Other

Is this a regression from previous behavior?

Yes, this used to work in Xamarin.Forms

Last version that worked well

Unknown/Other

Affected platforms

Android, I was not able test on other platforms

Affected platform versions

Android 26+ with .NET 7

Did you find any workaround?

Not a workaround per say, but two scenarios where this will work:

  1. Don't invoke Finish() on the initial activity that created the MAUI Context that's being used throughout the application. This is not an option for us.

  2. Reinitialize the MAUI stuff and create a new instance of MauiContext on the second Activity. I don't know what the other implications or side effects of this could be but it seems to run counter to all the examples I've seen on the use of embedded MAUI.

Relevant log output

No response

@nau-dwb nau-dwb added the t/bug Something isn't working label Jan 11, 2024
@jsuarezruiz jsuarezruiz added the area-controls-image Image control label Jan 12, 2024
@ghost ghost added the legacy-area-controls Label, Button, CheckBox, Slider, Stepper, Switch, Picker, Entry, Editor label Jan 12, 2024
@jsuarezruiz jsuarezruiz added platform/android 🤖 and removed legacy-area-controls Label, Button, CheckBox, Slider, Stepper, Switch, Picker, Entry, Editor labels Jan 12, 2024
@samhouts samhouts added the migration-compatibility Xamarin.Forms to .NET MAUI Migration, Upgrade Assistant, Try-Convert label Jan 12, 2024
@Eilon Eilon added the area-fonts Custom fonts and Font related API's label Jan 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-controls-image Image control area-fonts Custom fonts and Font related API's migration-compatibility Xamarin.Forms to .NET MAUI Migration, Upgrade Assistant, Try-Convert platform/android 🤖 t/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants