maui icon indicating copy to clipboard operation
maui copied to clipboard

[Android, 9.0 Preview 7] Blue notification / action bar started to appear on all modal pages

Open janne-hmp opened this issue 1 year ago • 8 comments
trafficstars

Description

Compared to .NET MAUI 9.0 Preview 6, Preview 7 shows a blue notification / action bar on every modal page on Android, and it seems impossible to turn it off. MainPage does not have the blue bar, and it fades in when any other page (all modals) is opened. Does anybody know how disable the notification /action bar so that it does not appear on modal pages, similar to how it worked in Preview 6? (The blue bar used to be all black and empty in Preview 6.)

share_1412216750542625141

Steps to Reproduce

  1. Build GnollHackM at https://github.com/hyvanmielenpelit/GnollHack using .NET 9.0 Preview 7 and start the app.
  2. The first page (MainPage) does not have the blue notification bar.
  3. Go to About page. When the page opens, also the blue notification bar fades in, unlike if you build the app in Preview 6

Link to public reproduction project repository

https://github.com/hyvanmielenpelit/GnollHack

Version with bug

Unknown/Other

Is this a regression from previous behavior?

Yes, this used to work in .NET MAUI

Last version that worked well

Unknown/Other

Affected platforms

Android

Affected platform versions

Android 14

Did you find any workaround?

No.

Relevant log output

No response

janne-hmp avatar Aug 14 '24 13:08 janne-hmp

Hi I'm an AI powered bot that finds similar issues based off the issue title.

Please view the issues below to see if they solve your problem, and if the issue describes your problem please consider closing this one and thumbs upping the other issue to help us prioritize it. Thank you!

Open similar issues:

Closed similar issues:

Note: You can give me feedback by thumbs upping or thumbs downing this comment.

github-actions[bot] avatar Aug 14 '24 13:08 github-actions[bot]

I see a lot of files in your project 😄 can you maybe be a bit more specific where in your code you are seeing this behavior?

jfversluis avatar Aug 14 '24 13:08 jfversluis

Does this happen in the File | New template for you?

mattleibow avatar Aug 14 '24 13:08 mattleibow

Can you change these values here: https://github.com/hyvanmielenpelit/GnollHack/blob/a198e58835dac23f6cb5e539919e09c39d8cc768/win/win32/xpl/GnollHackM/Platforms/Android/Resources/values/colors.xml#L4

And let us know if that influences the behavior?

I think this always worked this way, I wonder why this changed between preview 6 and 7?

jfversluis avatar Aug 14 '24 13:08 jfversluis

The notification bar used to be hidden, i.e., empty with just black. It is still like that on the game's MainPage, but then suddenly the bar fades in on all other pages (?). This may be related to Android SDK version 35 somehow.

share_3601464497344331126

janne-hmp avatar Aug 14 '24 13:08 janne-hmp

Yes, changing PrimaryDark to "#000000" (<color name="colorPrimaryDark">#000000</color>) did change the notification bar's background color to black, but obviously did not hide it. The notification bar fades in when a modal page scrolls in, and fades out when the modal page scrolls out. Note also that there is both the top bar and the bottom bar on modal pages, while on MainPage there's neither.

Currently, the system bars are hidden using the following Android functions in MainActivity, which seems to work on MainPage, but not on modal pages anymore. (Also, Xamarin Android works still just fine using the same code.)

        Window.AddFlags(WindowManagerFlags.Fullscreen);
...
            activity.Window.SetDecorFitsSystemWindows(false);
            activity.Window.InsetsController?.Hide(WindowInsets.Type.SystemBars());
            if (activity.Window.InsetsController != null)
                activity.Window.InsetsController.SystemBarsBehavior = (int)WindowInsetsControllerBehavior.ShowTransientBarsBySwipe;

There's a remark in Visual Studio that SetDecorFitsSystemWindows has been obsoleted in Android SDK version 35. That does not seem to explain though, why things work on MainPage, but not on modal pages.

share_1297602274416553086

janne-hmp avatar Aug 14 '24 13:08 janne-hmp

This may have something to do with the fact that App.Current.MainPage was deprecated and I had changed App.Current.MainPage.Navigation.PushModalAsync(page) to App.Current.Windows[0].Navigation.PushModalAsync(page). I now also tried just Navigation.PushModalAsync(page) (via ContentPage), but the result stays the same.

EDIT: In .NET 8.0: The default MAUI project seems to work just fine in this respect, but I have still no idea what my app does differently from the default app in showing modal pages. In GnollHack, I did override OnCreateWindow as per the Preview 7 instructions but setting App.MainPage instead of overridden window creation does not seem to help here.

EDIT: In .NET 9.0 Preview 7, the same blue bar appears in the default MAUI app on Android on a modal page, when you hide the bars as per the other comments.

janne-hmp avatar Aug 14 '24 14:08 janne-hmp

I can also confirm that this happens in the default MAUI app in 9.0 Preview 7 when you hide the bars as per above:

        Window.AddFlags(WindowManagerFlags.Fullscreen);
...
            activity.Window.SetDecorFitsSystemWindows(false);
            activity.Window.InsetsController?.Hide(WindowInsets.Type.SystemBars());
            if (activity.Window.InsetsController != null)
                activity.Window.InsetsController.SystemBarsBehavior = (int)WindowInsetsControllerBehavior.ShowTransientBarsBySwipe;

I tested earlier accidently 8.0, which worked fine.

The main page (no blue bar):

share_6032163884974552140

There's a modal page added to the click button (it is mostly all beige), and when it opens the page, the blue bar and the bottom navigation bar both fade in, also resulting in janky readjustment of the screen size:

share_5964786855831932218

If anybody knows any workarounds for this, let me know, or should I just wait for RC1?

janne-hmp avatar Aug 17 '24 09:08 janne-hmp

I can confirm this still happens in RC1.

janne-hmp avatar Sep 10 '24 21:09 janne-hmp

Need a way to modify dialog.Window before model(dialog) is displayed eg:set BarColor to Transparent

            window.ClearFlags(WindowManagerFlags.TranslucentStatus);
            window.AddFlags(WindowManagerFlags.DrawsSystemBarBackgrounds);
            window.SetStatusBarColor(Android.Graphics.Color.Transparent);
            window.SetNavigationBarColor(Android.Graphics.Color.Transparent);

https://github.com/dotnet/maui/blob/3aea7836812b011b8c2b6f646e289d292519f5d3/src/Controls/src/Core/Platform/ModalNavigationManager/ModalNavigationManager.Android.cs#L250-L260

maonaoda avatar Sep 25 '24 01:09 maonaoda

@janne-hmp can you share a simple sample that reproduces your issue? The attached repo is a huge project, which makes hard to focus on the real issue. Thanks in advance

pictos avatar Sep 30 '24 22:09 pictos

@janne-hmp can you share a simple sample that reproduces your issue? The attached repo is a huge project, which makes hard to focus on the real issue. Thanks in advance

Sure, here you go: https://github.com/hyvanmielenpelit/MauiAndroidBlueBarReproduction

Let me know if you have any questions. I will also update the repro repo in this issue.

janne-hmp avatar Oct 01 '24 14:10 janne-hmp

I would like to further note that that I added a full screen dotnet bot picture on the main page background so that you can additionally see its janky adjustment when you open or close the modal window when the system bars fade in / out. That alone is pretty annoying in a production quality game.

janne-hmp avatar Oct 01 '24 14:10 janne-hmp

Thanks @janne-hmp!

pictos avatar Oct 02 '24 01:10 pictos

@pictos Maybe you can take a look at this issue (and repro) at the same time? (could be the same problem) #24903

tranb3r avatar Oct 02 '24 06:10 tranb3r

I just tested that this still happens in RC2, too.

janne-hmp avatar Oct 09 '24 18:10 janne-hmp

@janne-hmp and others, now modal pages uses a DialogFragment and it has it own Window, so you need to configure that window to match whatever you've for your or MainActivity, here you can find how to do it.

pictos avatar Oct 09 '24 21:10 pictos

Thanks a lot! I now added the following code to MauiProgram.cs, and the modal windows now do not have system bars anymore, as before:

            .ConfigureLifecycleEvents(static lifecycleBuilder =>
            {
            #if ANDROID
                lifecycleBuilder.AddAndroid(androidLifecycleBuilder =>
                {
                    androidLifecycleBuilder.OnCreate((activity, savedInstance) =>
                    {
                        if (activity is ComponentActivity componentActivity)
                        {
                            componentActivity.GetFragmentManager()?.RegisterFragmentLifecycleCallbacks(new MyFragmentLifecycleCallbacks((fragmentManager, fragment) =>
                            {
                                // Modals in MAUI in NET9 use DialogFragment
                                if (fragment is AndroidX.Fragment.App.DialogFragment dialogFragment)
                                {
                                    if (Build.VERSION.SdkInt >= BuildVersionCodes.R)
                                    {
#pragma warning disable CA1416 // Supported on: 'android' 30.0 and later
                                        dialogFragment.Dialog!.Window!.SetDecorFitsSystemWindows(false);
                                        dialogFragment.Dialog!.Window!.InsetsController?.Hide(WindowInsets.Type.SystemBars());
                                        if (dialogFragment.Dialog!.Window!.InsetsController != null)
                                            dialogFragment.Dialog!.Window!.InsetsController.SystemBarsBehavior = (int)WindowInsetsControllerBehavior.ShowTransientBarsBySwipe;
#pragma warning restore CA1416 // Supported on: 'android' 30.0 and later
                                    }
                                    else
                                    {
#pragma warning disable CS0618 // Type or member is obsolete
                                        SystemUiFlags systemUiVisibility = (SystemUiFlags)dialogFragment.Dialog!.Window!.DecorView.SystemUiVisibility;
                                        systemUiVisibility |= SystemUiFlags.HideNavigation;
                                        systemUiVisibility |= SystemUiFlags.Immersive;
                                        dialogFragment.Dialog!.Window!.DecorView.SystemUiVisibility = (StatusBarVisibility)systemUiVisibility;
#pragma warning restore CS0618 // Type or member is obsolete
                                    }
                                }
                            }), false);
                        }
                    });
                });
            #endif
            })

There's also the following code at the end of the page:

#if ANDROID
public class MyFragmentLifecycleCallbacks(Action<AndroidX.Fragment.App.FragmentManager, AndroidX.Fragment.App.Fragment> onFragmentStarted) : AndroidX.Fragment.App.FragmentManager.FragmentLifecycleCallbacks
{
    public override void OnFragmentStarted(AndroidX.Fragment.App.FragmentManager fm, AndroidX.Fragment.App.Fragment f)
    {
        onFragmentStarted?.Invoke(fm, f);
        base.OnFragmentStarted(fm, f);
    }
}
#endif

janne-hmp avatar Oct 10 '24 08:10 janne-hmp