Skip to content

[macos][ios] Issues with ViewHelper #9027

Closed

Description

@spouliot

Current behavior

This code does not always work as expected:

#if __IOS__
		public static readonly nfloat MainScreenScale = UIScreen.MainScreen.Scale;
		public static readonly bool IsRetinaDisplay = UIScreen.MainScreen.Scale > 1.0f;
#elif __MACOS__
		public static readonly nfloat MainScreenScale = NSScreen.MainScreen.UserSpaceScaleFactor;
		public static readonly bool IsRetinaDisplay = NSScreen.MainScreen.UserSpaceScaleFactor > 1.0f;
#endif

Both fields are evaluated and assigned only when the (static) constructor is executed.
https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/readonly

Which means they will always match the then current (at execution time) screen/monitor.

IOW if the app starts on a 4K monitor and is moved to an HD monitor the (cached) values will still reflect the 4K monitor.

Note: this is also a problem for iOS / iPadOS where multiple screens are becoming more commons.

Expected behavior

Calling the fields should return the correct values for the currently used screen/monitor (at time of the call).

How to reproduce it (as minimally and precisely as possible)

No response

Workaround

Avoid using the fields and call the API.

Works on UWP/WinUI

No response

Environment

Uno.UI / Uno.UI.WebAssembly / Uno.UI.Skia

NuGet package version(s)

No response

Affected platforms

iOS, macOS

IDE

No response

IDE version

No response

Relevant plugins

No response

Anything else we need to know?

Since the fields are public removing them would be a breaking change.

However they will never work as someone would expect them since they can only be assigned inside the constructor.

Proposal

  1. Decorate the readonly fields with [Obsolete]. This avoids the breaking changes and will notify developers to use something else;

  2. Provide new properties (not fields) that can be used to replace both fields;

  3. Ensure the old fields are not used inside any calculation inside Uno;

Activity

  1. added
    difficulty/tbd
    kind/bug
    triage/untriaged
    on Jun 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

difficulty/tbdkind/bugtriage/untriaged

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions