Skip to content
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

Accessibility Scaling Doesn't Work (Android) #19056

Open
csnazell opened this issue Dec 10, 2024 · 2 comments
Open

Accessibility Scaling Doesn't Work (Android) #19056

csnazell opened this issue Dec 10, 2024 · 2 comments
Labels
difficulty/tbd Categorizes an issue for which the difficulty level needs to be defined. kind/bug Something isn't working triage/untriaged Indicates an issue requires triaging or verification

Comments

@csnazell
Copy link

Current behavior

Despite the documentation stating that Uno automatically scales text in response to accessibility configuration on Android and iOS. This is not happening on either the emulator or test device I am using.

I added the inverse of the disabling code linked above just in case it's now disabled by default to the app constructor to enable text scaling but it had no effect on observed behaviour.

Screenshots

At default text size:

Settings@Default

AppDraw@Default

TestApp@Default

At +2 text size:

Settings@+2

AppDraw@+2

TestApp@+2

Expected behavior

Displayed text should change size in response to accessibility configuration made in platform settings.

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

Steps to reproduce:

  • created a new app from template.

  • build & deployed to Android Emulator (API level 35).

  • switched to Settings > Display Size and text.

  • adjusted Font Size slider to two places larger from the default.

  • switched back to the app.

  • there was no change in the displayed text.

  • switched to app drawer to confirm OS had changed it's default text size. It had.

  • deployed to device at API level 33 & it exhibited the same behaviour.

Demo project

UnoAppTest.zip

Workaround

N/A

Works on UWP/WinUI

None

Environment

No response

NuGet package version(s)

N/A

Affected platforms

Android

IDE

Rider Windows

IDE version

JetBrains Rider 2024.3 (Build #RD-243.21565.191)

Relevant plugins

Runtime version: 21.0.5+8-b631.16 amd64 (JCEF 122.1.9)
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
Toolkit: sun.awt.windows.WToolkit
Windows 11.0
.NET Core v8.0.4 x64 (Server GC)
GC: G1 Young Generation, G1 Concurrent GC, G1 Old Generation
Memory: 2048M
Cores: 16
Registry:
ide.experimental.ui=true
i18n.locale=
Non-Bundled Plugins:
com.intellij.resharper.HeapAllocationsViewer (2024.3.0)
com.jetbrains.rider.android (243.21565.191)
unoplatform (1.2.28)

Anything else we need to know?

N / A

@csnazell csnazell added difficulty/tbd Categorizes an issue for which the difficulty level needs to be defined. kind/bug Something isn't working triage/untriaged Indicates an issue requires triaging or verification labels Dec 10, 2024
@jeromelaban
Copy link
Member

Thanks for the report. Font scaling is implemented here:

var textSize = rawTextSize * (float)FontHelper.GetFontRatio();

which gets its values from here:

_cachedScaledDensity = displayMetrics.ScaledDensity;

and
_cachedScaledDensity = displayMetrics.ScaledDensity;

it may be that some android devices don't provide that value properly, or that a change in android broke this feature.

Can you try calling the ViewHelper.RefreshFontScale() method to see if this helps? I was able to get the font size to change when restarting the app. It may be that:

private void RaiseConfigurationChanges()

does not get called when the system size changes.

@jeromelaban jeromelaban added the triage/needs-information Indicates an issue needs more information in order to work on it. label Dec 11, 2024
@csnazell
Copy link
Author

I can confirm stopping and restarting the app picks up the new scale value.

I overrode OnConfigurationChanged() on the activity as follows:

public class MainActivity : Microsoft.UI.Xaml.ApplicationActivity
{
    public override void OnConfigurationChanged(Configuration newConfig)
    {
        base.OnConfigurationChanged(newConfig);
        
        ViewHelper.RefreshFontScale();
    }
}

It's definitely getting called by Android (stops at a break point) so RaiseConfigurationChanges() should be being called. Manually calling ViewHelper.RefreshFontScale() has no effect.

The newConfig object's .fontScale property reads 1.29999995 at the +2 notch on the scale (cf 1.0 at the default) so this detail is available to the app.

Adding some additional debugging to investigate RefreshFontScale():

public class MainActivity : Microsoft.UI.Xaml.ApplicationActivity
{
    public override void OnConfigurationChanged(Configuration newConfig)
    {
        base.OnConfigurationChanged(newConfig);
        
        ViewHelper.RefreshFontScale();

        // display metrics
        
        using Android.Util.DisplayMetrics displayMetrics = Android.App.Application.Context.Resources.DisplayMetrics;
        
        var debugScaledDensity = displayMetrics.ScaledDensity;
        var debugDensity = displayMetrics.Density;

        var debugConfig = FeatureConfiguration.Font.IgnoreTextScaleFactor;
        var debugConfigMaxScale = FeatureConfiguration.Font.MaximumTextScaleFactor;

        return;
    }
}

displayMetrics.Density = 2.625

displayMetrics.ScaledDensity = 3.4124999

FeatureConfiguration.Font.IgnoreTextScaleFactor = false

FeatureConfiguration.Font.MaximumTextScaleFactor = null

So _cachedScaleDensity should be the same as displayMetrics.ScaledDensity

It looks like the UI isn't redrawing itself in response to these changes.

Side note:

There is a note in the Android docs indicating that the ScaledDensity field is deprecated as of API 34 (here}.

@github-actions github-actions bot removed the triage/needs-information Indicates an issue needs more information in order to work on it. label Dec 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
difficulty/tbd Categorizes an issue for which the difficulty level needs to be defined. kind/bug Something isn't working triage/untriaged Indicates an issue requires triaging or verification
Projects
None yet
Development

No branches or pull requests

2 participants