DeviceInfo screen dimensions broken on Android

According to the documentation, the screenWidth and screenHeight properties of the DeviceInfo Object are supposed to take the orientation of the device into account at the time of query.

screenWidth: Specifies the screen width of the device by considering the device orientation at the time of query. The returned value is in device independent pixels (Dp). This attribute is supported in iOS, Android, Windows, and SPA platforms.

However, they do not. At least not on Android.

Steps to reproduce this:

  1. Create a new native project
  2. Open Form1 in DESIGN view
  3. Enter the PROPERTIES tab and select the Action menu
  4. In the Android section, edit the onOrientationChange Action
  5. Add an Add Snippet node
  6. Paste the following code:
  7. alert(`${voltmx.os.deviceInfo().screenWidth} x ${voltmx.os.deviceInfo().screenHeight}`);
  8. Click save
  9. Go to the Form tab
  10. Under Orientation select Both
  11. Build the project and run it on an Android device or emulator
  12. Change the orientation a few times
  13. The alert messages will always have the same value
  14. (See the attached screenshots for the results on my device)

Is there any other way of querying the current device dimensions?

Or is there perhaps a way to query the current orientation of the device?

Thanks for your help!

Cheers

Hi Marcel

Thanks for posting your question in this forum.

Can you kindly let us know the VoltMX iris version and also the Android OS version in which this scenario was tested.

Hello Murali,

certainly I can:

I am using Volt MX Iris Version 9 SP 2 FP 38, which is the latest version from my understanding.

I've tested this on three emulators, running Android 5.1, 10.0 and 11.0 resprectively. I've also tested this on my physical Mi 11 Ultra which currently runs Android 11. Using the Volt MX Preview App yields the same results.

I would provide you with the sample project I used, but I'm unsure which files and folders would be minimally required.

Hi Marcel

Thanks for the update.
We are checking this internally and will get back to you.

Hello again Murali,

thank you very much!

There is one more thing I found out: The function does return the correct values at the time of query, but only the first time. After that it always returns the same values until the application is closed. In other words, if you start the example application I described above in landscape mode and change the orientation to portrait, deviceInfo() will always yield values for the portrait orientation, because that's when it was first queried. If you instead start the application in portrait mode and switch the orientation to landscape (again, this is when deviceInfo() is first called), it will always return the screen dimensions of the landscape orientation.

@Marcel Wittrin looks like the device width is cached on device once it is queried and returned from cache henceforth.

Since most applications are set to work in portrait or landscape mode only, that behavior helps with performance.

What is your usecase that needs the device width to be queried multiple times in same app session?

We can try to provide alternative ways to achieve your usecase, if we know what it is.

@Suhas Bhat I agree that it does make sense to cache the device information, such as the device ID, name, dimensions of the device itself, supported features, etc. because those are constants.

However, screenWidth and screenHeight are not constants. And they should not be treated as such.

Changing orientation is not the only reason why they might change either. Nowadays Android supports having multiple apps on screen at the same time (split screen).

So for whatever purpose the current screen dimensions are required, they should actually represent the current screen dimensions when queried.

Simply put, my use-case revolves around having a dashboard-form that supports both orientations, since some sub-forms require landsape orientation and most require portrait orientation. The reason why I need to query the screen dimensions in the first place, is having an overlay on top of the dashboard that can be swiped up and down at any time. To be able to swipe it down from the top edge of the screen, I need to know the size of the overlay, which is as big as the screen. Basically, I'm doing this: top: calc(-100% + dy) and I need to calculate, what "100%" is in device independant pixels. Well, it's the screenHeight.

Unfortunately, due to the caching, the overlay is sometimes swiped down from two thirds of the screen or from way outside the screen when in a different orientation than when originally queried.