xamarin / Xamarin.Forms

Xamarin.Forms is no longer supported. Migrate your apps to .NET MAUI.
https://aka.ms/xamarin-upgrade
Other
5.63k stars 1.88k forks source link

[Enhancement] Make named font size scaled for accessibility, and all numerical font sizes fixed #13543

Open abbalooga opened 3 years ago

abbalooga commented 3 years ago

Summary

I cannot find a way to keep font sizes fixed on android between devices using differing font scale settings. This makes it impossible to create a neat interface for displaying information that is fixed across devices. It would make logic that named font sizes are subject to user scaling but numbered font sizes are fixed to the developers design wishes.

API Changes

We would require an ability to set font scaling in mainactivity.cs

Intended Use Case

For users of Xamarin who desire to not have font wrapping out of view when users have system font scaling set above 1.

Tommigun1980 commented 3 years ago

This is especially important with font images.

abbalooga commented 3 years ago

A solution to this problem for APN28 and above couldn't be found. Any working work around would be appreciated.

Tommigun1980 commented 3 years ago

Fwiw I am currently sprucing up my UI to work better with accessibility font scaling and am running into this exact problem quite hard.

There really needs to be some way to tell Xamarin not to scale a specific label/whatever, for example when font icons are used. Expected would be for the app's text to become larger but not icons, and there really doesn't seem to exist any way to control this atm.

I am not 100% certain if it would be enough for Xamarin to scale named sizes and not apply scaling to numeric font sizes, as sometimes you need a value between two named sizes and are forced to use a numeric size for text. Some kind of additional property/syntax would probably be required.

Suggestion: Make all fonts scale with accessibility zoom as it currently does (to also ensure backwards compatibility), but add some kind of mechanism for preventing this for the special cases where scaling should not be applied.

abbalooga commented 3 years ago

Suggestion: Make all fonts scale with accessibility zoom as it currently does (to also ensure backwards compatibility), but add some kind of mechanism for preventing this for the special cases where scaling should not be applied.

Is there anything I can do to reach out to developers or coders to find a solution to this? Being able to prevent user scaling of text seems pretty basic and extremely necessary but for the life of me i cannot find a solution!

XamMattia83 commented 2 years ago

Suggestion: Make all fonts scale with accessibility zoom as it currently does (to also ensure backwards compatibility), but add some kind of mechanism for preventing this for the special cases where scaling should not be applied.

Is there anything I can do to reach out to developers or coders to find a solution to this? Being able to prevent user scaling of text seems pretty basic and extremely necessary but for the life of me i cannot find a solution!

I've tried to solve this by settings the display metrics manually. You can insert this call at the begin of MainActivity.cs OnCreate method:

    private void InitTextSize()
    {       
        Configuration configuration = new Configuration();
        configuration.FontScale = (float)1;
        DisplayMetrics metrics = new DisplayMetrics();
        WindowManager.DefaultDisplay.GetMetrics(metrics);
        metrics.ScaledDensity = configuration.FontScale * metrics.Density;
        BaseContext.ApplicationContext.CreateConfigurationContext(configuration);
        BaseContext.Resources.DisplayMetrics.SetTo(metrics);
    }

By the way, the "Display.GetMetrics()" method is deprecated now so i'm trying to fix it.

rudyspano commented 2 years ago

Without usage of deprecated method

        private void InitializeTextSize()
        {
            var configuration = new Configuration
            {
                FontScale = 1
            };

            var metrics = Resources.DisplayMetrics;
            metrics.ScaledDensity = configuration.FontScale * metrics.Density;

            BaseContext.ApplicationContext.CreateConfigurationContext(configuration);
            BaseContext.Resources.DisplayMetrics.SetTo(metrics);
        }