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

Extra space below status bar on iPhone 14 Pro Max #16617

Closed
juniorsaraviao opened this issue Aug 9, 2023 · 1 comment
Closed

Extra space below status bar on iPhone 14 Pro Max #16617

juniorsaraviao opened this issue Aug 9, 2023 · 1 comment
Labels
platform/iOS 🍎 t/bug Something isn't working

Comments

@juniorsaraviao
Copy link

juniorsaraviao commented Aug 9, 2023

Description

When running an app on iPhone 14 Pro Max (iOS 16.4), an extra space is added below the status bar.

There's a reference GitHub issue reported on Xamarin: xamarin/Xamarin.Forms#15584

I've implemented the iOS workaround in MAUI (https://developer.apple.com/forums/thread/715417) but it doesn't work the first time, but after navigating it works correctly.

The first time view is null:

var view = UIApplication.SharedApplication.Windows.FirstOrDefault(x => x.IsKeyWindow);

image

After navigating, view gets a value:

image

Video:

iPhone.14.Pro.Max.mp4

Steps to Reproduce

  1. Create a MAUI project.
  2. Add CommunityToolkit.Maui.
  3. Create a BasicContentPage that inherits from ContentPage.
  4. Add this code in BasicContentPage.
public class BasicContentPage : ContentPage
    {
        public BasicContentPage()
        {
            Padding = new Thickness(0);
            BackgroundColor = Colors.White;

            Microsoft.Maui.Controls.NavigationPage.SetHasNavigationBar(this, false);
            this.Behaviors.Add(new StatusBarBehavior()
            {
                StatusBarColor = Colors.Green,
                StatusBarStyle = StatusBarStyle.LightContent
            });
        }

        protected override void OnAppearing()
        {
            base.OnAppearing();

#if IOS
            // Workaround for iPhone 14: https://developer.apple.com/forums/thread/715417

            if (UIDevice.CurrentDevice.CheckSystemVersion(13, 0))
            {
                var window = UIKit.UIApplication.SharedApplication.Windows.FirstOrDefault();
                var topPadding = window?.SafeAreaInsets.Top ?? 0;

                var statusBar = new UIView(new CoreGraphics.CGRect(0, 0, UIScreen.MainScreen.Bounds.Size.Width, topPadding))
                {
                    BackgroundColor = Colors.Green.ToPlatform()
                };

                var view = UIApplication.SharedApplication.Windows.FirstOrDefault(x => x.IsKeyWindow);
                view?.AddSubview(statusBar);
            }

#endif
        }
  1. Make the pages use BasicContentPage.
<samplemaui:BasicContentPage xmlns:samplemaui="clr-namespace:SampleMaui"
                             xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
                             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
                             x:Class="SampleMaui.MainPage"
                             NavigationPage.HasNavigationBar="False">

    <ScrollView BackgroundColor="SkyBlue">
        <StackLayout
            Spacing="25"
            Padding="30,0"
            VerticalOptions="Center">

            <Image
                Source="dotnet_bot.png"
                SemanticProperties.Description="Cute dot net bot waving hi to you!"
                HeightRequest="200"
                HorizontalOptions="Center" />

            <Label
                Text="Hello, World!"
                SemanticProperties.HeadingLevel="Level1"
                FontSize="32"
                HorizontalOptions="Center" />

            <Label
                Text="Welcome to .NET Multi-platform App UI"
                SemanticProperties.HeadingLevel="Level2"
                SemanticProperties.Description="Welcome to dot net Multi platform App U I"
                FontSize="18"
                HorizontalOptions="Center" />

            <Button
                x:Name="CounterBtn"
                Text="Navigate to Second Page"
                SemanticProperties.Hint="Counts the number of times you click"
                Clicked="OnCounterClicked"
                HorizontalOptions="Center" />

        </StackLayout>
    </ScrollView>

</samplemaui:BasicContentPage>

Link to public reproduction project repository

https://github.com/juniorsaraviao/StatusBarIssue

Version with bug

7.0.92

Last version that worked well

Unknown/Other

Affected platforms

iOS

Affected platform versions

iPhone 14 Pro Max (iOS 16.4)

Did you find any workaround?

No

Relevant log output

@juniorsaraviao juniorsaraviao added the t/bug Something isn't working label Aug 9, 2023
@drasticactions
Copy link
Contributor

drasticactions commented Aug 9, 2023

Going by the forum topic you linked, the status bar functions seem like an initial design decision by Apple. You've implemented a "workaround" for it that has issues.

https://github.com/drasticactions/MauiRepros/blob/main/StatusBarHack/MainPage.xaml.cs#L30-L52

スクリーンショット 2023-08-09 14 04 17

If you detect when the handler changes, you can get the UIWindow and UIView based on that, which would "fix" your workaround.

Going with the original Forms issue you linked to, I am also going to close this for the same reasons: The extra space between the views seem like an initial design by Apple and to "fix" it in Forms/MAUI would require our own hacks which could break other code. If others feel different (@PureWeen? @hartez?) then we can reopen it, but IMO this would be something that would need to be addressed in UIKit rather than something we hack on top of.

@drasticactions drasticactions closed this as not planned Won't fix, can't repro, duplicate, stale Aug 9, 2023
@ghost ghost locked as resolved and limited conversation to collaborators Sep 8, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
platform/iOS 🍎 t/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants