Essentials: Can't get screen real size

Created on 21 Mar 2019  路  9Comments  路  Source: xamarin/Essentials

Description

In Android, with DeviceDisplay.MainDisplayInfo, I can't get the real screen size (without navigation controls). It would be nice to have another property (like RealSizeDisplayInfo) that returns the real size by calling service?.JavaCast<IWindowManager>()?.DefaultDisplay.GetRealMetrics(outMetrics);

Steps to Reproduce

Just look at DeviceDisplay.MainDisplayInfo, it doesn't return the full screen real size.

Expected Behavior

Either return the real size of the screen, or have another property to get that real size.

Actual Behavior

It returns the screen size less the navigation controls size.

bug

All 9 comments

So, it is a good question as to what should be returned.

There is probably the app size and then device size. So for instance if I am in a split view on android i get half the size for the app and for device size i get the full screen size of the Android device.

We had a requirement similar to this as well. From memory, Essentials was returning the physical device size. I think in UWP this was the size of the display, on iOS it felt random was probably related to the hardware of the actual phone (see the specs for the iPhone).

What we needed was the "viewport" for the app. Much like you'd get from a browser.

I'll double check on Monday.

Ok, I checked with the team and there were two things:

1 - The width we got from essentials needed to be divided by the density. This was noticable on ios "plus" devices especially. This was for a request to a web service to get an image (more/less) the right size. It is also used to size the placeholder in the listview so it didn't jump/resize when the actual image arrived.

2 - on UWP the width was the monitor width and not the app window width.

This issue is related to #385. We should have two sizes, one for the application, one for the device screen size. And currently, DeviceDisplay.MainDisplayInfo does not return any of the two. If we had to have only one, the most useful would be certainly the size of the application.

So, @mattleibow can verify, but we documented it as:

Gets the height of the screen for the current orientation.
Gets the width of the screen for the current orientation.

They are returned in pixels too, so density is not take into consideration and has a different property.

So it should be for the actual device screen based on orientation.

Today it returns:

  • UWP: DisplayInformation.GetForCurrentView (correct)
  • iOS: MainScreen (correct)
  • Android: Platform.AppContext.Resources?.DisplayMetrics (incorrect)

After I fix this we should open a new one for "App DisplayMetrics" inside of app info probably.

PR is in

@jamesmontemagno
did this get created?

After I fix this we should open a new one for "App DisplayMetrics" inside of app info probably.

PR was just merged and will go out in 1.1.1

After I fix this we should open a new one for "App DisplayMetrics" inside of app info probably.

Did this available app size version (taking into account soft nav bars on Android) ever get added? We are having a lot of trouble correctly sizing on Android phones that put the soft navbar on the right in landscape orientation.

Was this page helpful?
0 / 5 - 0 ratings