Accessibility - Font and Layout Scaling RRS feed

  • Question

  • User398843 posted


    We are considering to use Xamarin.Forms to be used for our project in the future, and while testing accessibility features, I we have noticed that "system font scale" is not applied on each platform in the same way. (UWP - whole interface scales, Android - Only fonts/buttons scale...)

    I done some research on how XF converts "sizes". github.com/xamarin/Xamarin.Forms/blob/master/Xamarin.Forms.Core/DeviceInfo.cs (sorry, cannot post direct links yet)

    XF: units of measurement are custom calculated "dp/dip" and translate to : * UWP: Effective pixels * github.com/xamarin/Xamarin.Forms/blob/d99264507dc1623aecb83daf81aadd2effae62ae/Xamarin.Forms.Platform.UAP/WindowsDeviceInfo.cs#L27 * iOS: Points * github.com/xamarin/Xamarin.Forms/blob/d99264507dc1623aecb83daf81aadd2effae62ae/Xamarin.Forms.Platform.iOS/IOSDeviceInfo.cs#L31 * Android: Density independent pixels ? * github.com/xamarin/Xamarin.Forms/blob/d99264507dc1623aecb83daf81aadd2effae62ae/Xamarin.Forms.Platform.Android/Forms.cs#L555

    The reccomended way to support system scaling is to use Points on iOS, and SP on Android when layouts are desired to scale with fonts. Android is the only platform that doesn's support this "out of the box" as it internally doesn't use sp units.

    The workaround solution for now seems to be: 1. Create XAML Extension which would multiply provided size by "font scale factor". 2. Use autosizing layouts where possible so that labels won't get clipped when they scale.

    I am not sure however if this is "good practice". How should I approach this ? Is there something I am missing?

    Thursday, January 7, 2021 10:44 AM

All replies

  • User89714 posted


    The easiest thing to do is to limit the font sizes that your app uses to the following (using Device.GetNamedSize), as these will also scale on iOS using Dynamic Text support:

    NamedSize.Body NamedSize.Caption NamedSize.Header NamedSize.Subtitle NamedSize.Title

    That's a very restrictive list though, so not ideal for creating a nice looking UI whilst still supporting accessibility. I raised an enhancement request a while ago to have this list extended to improve things. See https://github.com/xamarin/Xamarin.Forms/issues/12842

    As a general comment, accessibility support in Xamarin.Forms 4.8 (and having just read the release notes, 5.0 as well) is IMHO extremely poor. I added a lot of accessibility support to my own code last year, sometimes calling platform-specific code directly, but sometimes hitting complete brick walls because of the way XF is currently implemented. There are a lot of issues logged in GitHub to get it improved, but there isn't an obviously visible head of steam about getting them resolved (maybe somebody is busy in a backroom out of sight?). Understanding of accessibility seems to still be pretty poor among many involved in XF, as can be seen by how questions about accessibility have been responded to in these forums, with the respondent often completely missing the point of what the questioner is asking.

    Thursday, January 7, 2021 12:45 PM