Skip to content

[regression/7.0.0] ISafeAreaView.IgnoreSafeArea isn't respected in .NET 7Β #12823

Closed

Description

@AlexeyStarkov

Description

I've upgraded my project from .NET6 to .NET7 and noticed that IgnoreSafeArea I use within page content layout (i.e. Grid) is not respected anymore. SafeArea is still there whether IgnoreSafeArea is true or false. It works well in .NET6.

Steps to Reproduce

  1. Create .NET 7 MAUI project
  2. Create ContentPage with Grid set as Content
  3. Set Grid BackgroundColor to Grey and IgnoreSafeArea to True
  4. Assign the newly created page to the MainPage property of App class
  5. Run iOS application

Link to public reproduction project repository

https://github.com/AlexeyStarkov/MAUI_NET7_IgnoreSafeArea_Issue

Version with bug

7.0 (current)

Last version that worked well

6.0.424

Affected platforms

iOS

Affected platform versions

iOS 16.2

Did you find any workaround?

No response

Relevant log output

No response

Activity

  1. added
    t/bug
    on Jan 21, 2023
  2. added
    area-layout
    on Jan 23, 2023
  3. added this to the Backlog milestone on Jan 23, 2023
  4. bcaceiro commented on Jan 24, 2023

    @bcaceiro

    I am facing the same problem.

  5. scriptBoris commented on Mar 21, 2023

    @scriptBoris

    Any updates?

  6. anupkrjee commented on Apr 7, 2023

    @anupkrjee

    I am facing same issue in .NET 7

  7. nathanjeynes commented on Apr 11, 2023

    @nathanjeynes

    This is an issue for us as well, this is basic functionality which has been broken in .NET 7 and should be fixed

  8. added
    p/1
    on Apr 11, 2023
  9. self-assigned this
    on Apr 25, 2023
  10. RobTF commented on Apr 27, 2023

    @RobTF

    Yep, got this issue as well. Idea of ETA for fix would be much appreciated. Is basic required functionality.

  11. ianbaddino commented on May 3, 2023

    @ianbaddino

    I also have this blocking issue. Is this working in .NET 6 / 8?

    I'm using a ContentPage with a nested WebView

    I have tried both the XAML and the following code-behind solution to no avail.
    On().SetUseSafeArea(false);

  12. mattleibow commented on May 3, 2023

    @mattleibow
    Member

    I just tested with .NET MAUI 7.0.81 using the iOS platform specific ad it seems to work when you set it on the Page not the layouts. The docs also indicate this: https://learn.microsoft.com/dotnet/maui/ios/platform-specifics/page-safe-area-layout

    Looking at the code for the Layout, not sure that does anything as seems to only be half implemented as is not even a bindable property.

  13. RobTF commented on May 3, 2023

    @RobTF

    Using it on the page is how I tried with no effect - to be honest I don't really see the point of adding the option onto individual layouts, as it should be a page-level concern anyway, shouldn't it? Xamarin only had the option on the page and worked fine.

    The only thing that might be nice is to allow the developer to opt in/out of individual safe area directions (i.e. flow the page into the top, but not the bottom safe zone), but let's not run before we can walk (or crawl!).

    I managed to work around this in the end with the following, painful hack;

    Firstly, you must set the UseSafeArea to be false on the page.

    <ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
                 xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
                 xmlns:ios="clr-namespace:Microsoft.Maui.Controls.PlatformConfiguration.iOSSpecific;assembly=Microsoft.Maui.Controls"
                 x:Class="MyApp.MyClass"
                 ios:Page.UseSafeArea="False"
                 Shell.NavBarIsVisible="False">

    Then, create some service to obtain the safe area insets (for Android just return 0 everywhere).

    internal sealed class SafeAreaInsets : ISafeAreaInsets
    {
        /// <inheritdoc/>
        public Thickness GetSafeAreaInsets()
        {
            if (!OperatingSystem.IsIOSVersionAtLeast(11))
            {
                return Thickness.Zero;
            }
    
            var window = UIApplication.SharedApplication.Delegate.GetWindow();
            var insets = window.SafeAreaInsets;
            return new Thickness(insets.Left, insets.Top, insets.Right, insets.Bottom);
        }
    }

    Then in the page...

        /// <inheritdoc />
        protected override void OnAppearing()
        {
            base.OnAppearing();
    
    #if __IOS__
            var actualInsets = IPlatformApplication.Current.Services!.GetRequiredService<ISafeAreaInsets>().GetSafeAreaInsets();
            var topArea = actualInsets.Top;
            var bottomArea = actualInsets.Bottom;
            var safeInsets = On<iOS>().SafeAreaInsets();
            safeInsets.Top = -topArea;
            safeInsets.Bottom = -bottomArea;
    
            Padding = safeInsets;
    #endif
        }

    I found this here;
    https://stackoverflow.com/questions/74724489/net-maui-ios-usesafearea-not-working-stacklayout-verticalstacklayout-and-grid

    Basically, you pull the insets manually from the underlying OS (away from the broken MAUI abstraction), flip the sign and patch the values into the insets object provided by the broken MAUI bits, then use those values to set a negative page padding manually to "drag" it into the safe inset space.

    Horrible hack I know, but any of you ex-Xamarin victims developers will be used to it.

  14. 14 remaining items

  15. added this to the .NET 8 GA milestone on Jul 12, 2023
  16. added a commit that references this issue on Jul 19, 2023
    71e6bb5
  17. borrmann commented on Jul 25, 2023

    @borrmann
    Contributor

    IgnoreSafeArea also can't be set in a StyleSheet for all Grids/ Layouts as it doesn't seem to have the necessary getters and setters to do so. Is there some sort of workaround to set the default to ignoring the safe area for all pages and layouts?

  18. borrmann commented on Jul 25, 2023

    @borrmann
    Contributor

    So I scanned through a lot of related issues like here 12417 and to be able to generically use all the available space per default I am using the

    Mapper from @Felicity-R

    Microsoft.Maui.Handlers.LayoutHandler.Mapper.AppendToMapping("Custom", (h, v) =>
            {
                if (v is Layout layout)
                {
                    layout.IgnoreSafeArea = true;
                }
            });
    

    and I have to set UseSafeArea like @hartez commented

    xmlns:ios="clr-namespace:Microsoft.Maui.Controls.PlatformConfiguration.iOSSpecific;assembly=Microsoft.Maui.Controls"
    ios:Page.UseSafeArea="False"
    

    on all my (Base) ContentPages

    Also add

    Window.SetStatusBarColor(Android.Graphics.Color.Transparent);
    Window.SetNavigationBarColor(Android.Graphics.Color.Transparent);
    

    somewhere in the AndroidActivity

    AND ALSO DO NOT use the community toolkit status behavior, because it sets the color above the content, that now should be placed in the unsafe area!
    From there it is then a lot easier to remove the content back to the SafeArea when it is actually desired... If you want to change the color for Android for different pages, then you can still use the toolkit but ensure the code runs only on Android and not on iOS.

    When this would be the default behaviour, the Layout Property UseSafeArea becomes actually very useful, because now it is possible to tell any child and their children if it should only use the safe area or not. In any nested view with a few layouts, this didnt work before.

  19. added a commit that references this issue on Jul 26, 2023
    513fb27
  20. added
    fixed-in-8.0.0-preview.7.8842
    on Aug 8, 2023
  21. added a commit that references this issue on Aug 19, 2023
    d47c215
  22. ghost locked as resolved and limited conversation to collaborators on Sep 7, 2023
  23. changed the title [-][regression/net7.0] ISafeAreaView.IgnoreSafeArea isn't respected in .NET 7[/-] [+][regression/7.0.0] ISafeAreaView.IgnoreSafeArea isn't respected in .NET 7[/+] on Sep 19, 2023
  24. added
    fixed-in-7.0.96
    on Oct 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area-layoutfixed-in-7.0.100fixed-in-7.0.101fixed-in-7.0.96fixed-in-8.0.0-preview.7.8842i/regressionp/1platform/iost/bug

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions