-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
[Bug] On iOS, SafeArea returns Thickness of zero #2657
Comments
Bug repros in 17.2 Preview 1. Tested with iPhone 13 iOS 15.2. Repro project is here: |
MAUIのバグにより、現状ではSafeAreaが取得できていない dotnet/maui#2657
We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process. |
I have the same isuse, iPhone 14 Max iOS 16 On<iOS>().SetUseSafeArea(false); has no effect, On<iOS>().SetSafeAreaInsets(new Thickness(100, 100, 100, 0)); has no effect. .NET 7 |
internal static UIEdgeInsets SafeAreaInsetsForWindow
{
get
{
UIEdgeInsets safeAreaInsets;
if (!Forms.IsiOS11OrNewer)
safeAreaInsets = new UIEdgeInsets(UIApplication.SharedApplication.StatusBarFrame.Size.Height, 0, 0, 0);
else if (UIApplication.SharedApplication.GetKeyWindow() != null)
safeAreaInsets = UIApplication.SharedApplication.GetKeyWindow().SafeAreaInsets;
#pragma warning disable CA1416, CA1422 // TODO: UIApplication.Windows is unsupported on: 'ios' 15.0 and later
else if (UIApplication.SharedApplication.Windows.Length > 0)
safeAreaInsets = UIApplication.SharedApplication.Windows[0].SafeAreaInsets;
#pragma warning restore CA1416, CA1422
else
safeAreaInsets = UIEdgeInsets.Zero;
return safeAreaInsets;
}
} for me UIApplication.SharedApplication.Windows.Length is 0 |
looks like "windows" is now deprecated too. looks like for iOS 15 it shhould be like this extension UIApplication {
static var yourNameByValue: UIEdgeInsets {
let scene = UIApplication.shared.connectedScenes.first as? UIWindowScene
return scene?.windows.first?.safeAreaInsets ?? .zero
}
} |
C# version is working var scene = UIKit.UIApplication.SharedApplication.ConnectedScenes.ToArray().FirstOrDefault();
var windowScene = (UIKit.UIWindowScene)scene;
var safeArea = windowScene.Windows.FirstOrDefault()?.SafeAreaInsets; |
Adding to the previous comments, there is something wrong with SafeArea on iPhones, since if SafeArea is set to false and the phone is horizontal, the app crashes. |
and in Maui static UIWindow? GetKeyWindow()
{
// if we have scene support, use that
if (OperatingSystem.IsIOSVersionAtLeast(13) || OperatingSystem.IsMacCatalystVersionAtLeast(13))
{
try
{
using var scenes = UIApplication.SharedApplication.ConnectedScenes;
var windowScene = scenes.ToArray<UIWindowScene>().FirstOrDefault();
return windowScene?.Windows.FirstOrDefault();
}
catch (InvalidCastException)
{
// HACK: Workaround for https://github.com/xamarin/xamarin-macios/issues/13704
// This only throws if the collection is empty.
return null;
}
}
// use the windows property (up to 13.0)
return UIApplication.SharedApplication.KeyWindow;
} but for me sometime this windowScene?.Windows still is empty |
Having the same issue, setting SafeArea to false, has no response, specially in landscape mode, which is a blocker to me |
Still not working to this day on .NET 7 |
@Redth @hartez Any idea when this will get picked up? Ive just tried it again in our .NET MAUI test app with the latest Maui workload, still broken. This bug was reported 16 months ago, during Maui preview, was verified, others are reporting the same issue and yet it still isn't fixed. Why should we report bugs when they don't get fixed? You are wasting my time, Im not paid to debug .NET MAUI for you, I had enough of doing that for Xamarin Forms. I can't sell migrating to .NET MAUI from Xamarin Forms when simple bugs like this don't get picked up after reporting them over a year ago. |
Looking at the sprint board, there are 37 items planned for the current sprint. There are 2,2k issues reported, to fix them all would take 2,5 yrs at this pace (assuming no new bugs are reported during that time). I think it's safe to assume that we're on our own... |
@JohnHDev any way you have to migtate your code to MAUI in some day, because xamarin will be depricated. |
I fill this issue relatod to pages, or time of createing page or so |
@KSemenenko |
@JohnHDev I have now switched to MAUI and Blazor Mobile, and I really like C#, but at this point I'm not sure it's worth it either =( |
This is basic functionality, why is this issue still open after such a long time? I agree, we shouldn't be wasting time on these issues after MAUI GA. As KSemenenko said, calling the same code directly works, so it should be an easy fix:
|
@kramer-e i think our best case is .net8 |
Disgusting work |
I installed the 2657.zip and update the sdk version to .NET 7. |
Out of curiosity, what are folks using the SafeAreaInsets property for? |
I use this for a workaround on iOS, because of the issue that I need to show content behind the statusbar and controls below that in the safe area. I've set |
To make design good locking on iOS, especially bottom, where you no need bold line with background color. like map, you want full screen map, or the same ful screen map but with margins only on top |
It's very often that you need some layouts, or images to go beyond the safe area. |
Given:
var safeArea = On<Microsoft.Maui.Controls.PlatformConfiguration.iOS>().SafeAreaInsets();
SafeAreaInserts is returning a Thickness of zero on iPhone 11 simulator running iOS 14.5.
Steps to Reproduce
Expected Behavior
Should return correct safe area
Actual Behavior
Returns an empty safe area
Basic Information
Workaround
None
The text was updated successfully, but these errors were encountered: