question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

iOS Thickness should be multiple to 2

See original GitHub issue

Description

I discovered that, for example, to change the SafeArea in iOS, the values must be multiplied by 2. This is probably because of the retina.

But in large iPads there is a factor of 3x.

Maybe we should add some property that will depend on the system and we can multiply by it without worrying about compatibility?

https://developer.apple.com/documentation/uikit/uiscreen/1617836-scale

swift:

UIScreen.main.scale

cs:

UIKit.UIScreen.MainScreen.Scale

Steps to Reproduce

var scene = UIKit.UIApplication.SharedApplication.ConnectedScenes.ToArray<UIKit.UIWindowScene>().FirstOrDefault();
if (scene != null)
{
    var windowScene = (UIKit.UIWindowScene)scene;
    var safeArea = windowScene.Windows.FirstOrDefault()?.SafeAreaInsets;
    Padding =  new Thickness(
        -(safeArea.Value.Left * 2), //left
        Padding.Top, //safeArea.Value.Top, //-(safeArea.Value.Top * 2),// top, 
        -(safeArea.Value.Right * 2), //right
        -(safeArea.Value.Bottom * 2)); //bottom
}

Link to public reproduction project repository

no

Version with bug

7.0 (current)

Last version that worked well

Unknown/Other

Affected platforms

iOS

Affected platform versions

iOS

Did you find any workaround?

No response

Relevant log output

No response

Issue Analytics

  • State:closed
  • Created 10 months ago
  • Reactions:1
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
hartezcommented, Dec 13, 2022

also I found DeviceDisplay.Current.MainDisplayInfo.Density wich is scale. but for me it’s 3 with some reason.

Yes, if you are using a higher density display, the density will be higher: https://learn.microsoft.com/en-us/dotnet/api/microsoft.maui.devices.displayinfo.density?view=net-maui-7.0#remarks

But you really only need to know this if you are doing platform-specific work. For anything cross-platform, the density scaling is accounted for automatically. If you set the Padding for a Grid to 10, that value will be multiplied by the screen density for you by the layout engine; you don’t need to worry about it.

If you’re doing some sort of layout work in platform-specific code (e.g., in UISceneDelegate), and you need to account for the density yourself, then use DisplayInfo.Density.

1reaction
KSemenenkocommented, Dec 1, 2022

You multiplied by 2 and got the right size, I just think it would be nice to have some kind of constant for this.

because in case Apple releases new size screens, I’m afraid to imagine how many of these “multiply by 2” are in the production code. even in the maui code base there is such a thing.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Should the dimensions (height/width) of the retina images ...
Currently that scale factor is 2 for iPhone 4 and iPhone 4s. This means that the backing stores on retina displays will always...
Read more >
Layout | Apple Developer Documentation
As a general rule, display no more than three buttons that contain glyphs — or two buttons that contain text — in a...
Read more >
How to make two views the same width or height
On iOS, the key is to give each view you want to size an infinite maximum height or width, which will automatically make...
Read more >
iPhone 12 mini - Technical Specifications
Size and Weight2. Width: 2.53 inches (64.2 mm); Height: 5.18 inches (131.5 mm); Depth: 0.29 inch (7.4 mm); Weight: 4.76 ounces (135 grams) ......
Read more >
iOS 16 - Master the NEW Lock Screen & Home Screen!
These features include widgets from first-party and third-party apps, depth effect on the Lock Screen, live activities, customizing the ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found