Skip to content

Can only ignore iOS Safe Area when navigation bar is hidden #17022

@davidortinau

Description

@davidortinau

Description

Porting an Xamarin.Forms app to .NET MAUI, I found that the old safe area code doesn't work as expected in .NET MAUI. I found the recommendation to use IgnoreSafeArea="True" on the layout, however this didn't do anything until...

I did a repro in a blank app and hid the navigation bar.

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="PlayItSUnsafe.MainPage"
             xmlns:ios="clr-namespace:Microsoft.Maui.Controls.PlatformConfiguration.iOSSpecific;assembly=Microsoft.Maui.Controls"
             ios:Page.UseSafeArea="False"
             BackgroundColor="Red"
             Shell.NavBarIsVisible="False"
             >


        <Grid Background="#333333"
            IgnoreSafeArea="True"
            RowDefinitions="300,*"
            >
            <BoxView Grid.Row="0"
                BackgroundColor="MediumPurple"
                />
            
            <Image Source="dotnet_bot.png" />

            <Label Text="Hello, world!" Grid.Row="1"
            TextColor="White"
                HorizontalOptions="Center"
                VerticalOptions="Center" />
        </Grid>

</ContentPage>

PlayItUnsafe.zip
Screenshot 2023-08-27 at 2 36 29 PM

This AppDelegate code should (used to) make the nav bar bg transparent to create this look.

public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions)
    {
        base.FinishedLaunching(application, launchOptions);
            
        UINavigationBar.Appearance.SetBackgroundImage(new UIImage(), UIBarMetrics.Default);
        UINavigationBar.Appearance.ShadowImage = new UIImage();
        UINavigationBar.Appearance.BackgroundColor = UIColor.Clear;
        UINavigationBar.Appearance.TintColor = UIColor.White;
        UINavigationBar.Appearance.BarTintColor = UIColor.Clear;
        UINavigationBar.Appearance.Translucent = true;

        return true;
    }

The SmartHotel360 app uses FlyoutPage and the sample repro uses Shell. Both should work.

Steps to Reproduce

run the sample from the zip and/or the repo linked. Show/hide the navigation bar. In both cases the content should be at the very top of the device screen, not at the bottom of the nav bar.

Link to public reproduction project repository

https://github.com/davidortinau/SmartHotel360-Mobile/blob/upgrade-step-1/Source/SmartHotel.Clients/SmartHotel.Clients.iOS/AppDelegate.cs

Version with bug

8.0.0-preview.7.8842
Also tested latest 7.0

Is this a regression from previous behavior?

Yes, this used to work in Xamarin.Forms

Last version that worked well

Unknown/Other

Affected platforms

iOS

Affected platform versions

16.4

Did you find any workaround?

Not without abandoning the existing implementation with ToolbarItem and flyout menu button etc.

Relevant log output

No response

Metadata

Metadata

Assignees

Labels

area-layoutStackLayout, GridLayout, ContentView, AbsoluteLayout, FlexLayout, ContentPresenterfixed-in-8.0.7fixed-in-9.0.100-preview.1.9973migration-compatibilityXamarin.Forms to .NET MAUI Migration, Upgrade Assistant, Try-Convertp/1Work that is important, and has been scheduled for release in this or an upcoming sprintpartner/cat 😻this is an issue that impacts one of our partners or a customer our advisory team is engaged withplatform/ioss/triagedIssue has been revieweds/verifiedVerified / Reproducible Issue ready for Engineering Triaget/bugSomething isn't working

Type

No type
No fields configured for issues without a type.

Projects

Status

Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions