[iOS] adds a flag to ios if user needs to disable accessibility sizing for named...
authorShane Neuville <shane94@hotmail.com>
Thu, 13 Jun 2019 19:59:01 +0000 (13:59 -0600)
committerSamantha Houts <samhouts@users.noreply.github.com>
Thu, 13 Jun 2019 19:59:01 +0000 (12:59 -0700)
* adds a flag to ios if user needs to disable accessibility sizing for named font sizes

* move setting to platform specific

* move to mobile if defs

* move comment back

* move comment back

* invert and delete

Xamarin.Forms.Core/PlatformConfiguration/iOSSpecific/Application.cs
Xamarin.Forms.Platform.iOS/Forms.cs

index a64a821..6610eaf 100644 (file)
                        return config;
                }
                #endregion
+
+               #region EnableAccessibilityScalingForNamedFontSizes
+               public static readonly BindableProperty EnableAccessibilityScalingForNamedFontSizesProperty = BindableProperty.Create("EnableAccessibilityScalingForNamedFontSizes", typeof(bool), typeof(Application), true);
+
+               public static bool GetEnableAccessibilityScalingForNamedFontSizes(BindableObject element)
+               {
+                       return (bool)element.GetValue(EnableAccessibilityScalingForNamedFontSizesProperty);
+               }
+
+               public static void SetEnableAccessibilityScalingForNamedFontSizes(BindableObject element, bool value)
+               {
+                       element.SetValue(EnableAccessibilityScalingForNamedFontSizesProperty, value);
+               }
+
+               public static bool GetEnableAccessibilityScalingForNamedFontSizes(this IPlatformElementConfiguration<iOS, FormsElement> config)
+               {
+                       return GetEnableAccessibilityScalingForNamedFontSizes(config.Element);
+               }
+
+               public static IPlatformElementConfiguration<iOS, FormsElement> SetEnableAccessibilityScalingForNamedFontSizes(this IPlatformElementConfiguration<iOS, FormsElement> config, bool value)
+               {
+                       SetEnableAccessibilityScalingForNamedFontSizes(config.Element, value);
+                       return config;
+               }
+               #endregion
        }
 }
index 09a9938..9886cf8 100644 (file)
@@ -13,6 +13,9 @@ using System.Threading;
 using System.Threading.Tasks;
 using Xamarin.Forms.Internals;
 using Foundation;
+using Xamarin.Forms.PlatformConfiguration;
+using Xamarin.Forms.PlatformConfiguration.iOSSpecific;
+
 #if __MOBILE__
 using UIKit;
 using Xamarin.Forms.Platform.iOS;
@@ -21,7 +24,6 @@ using TNativeView = UIKit.UIView;
 using AppKit;
 using Xamarin.Forms.Platform.MacOS;
 using TNativeView = AppKit.NSView;
-
 #endif
 
 namespace Xamarin.Forms
@@ -155,7 +157,6 @@ namespace Xamarin.Forms
 
                class IOSPlatformServices : IPlatformServices
                {
-
                        readonly double _fontScalingFactor = 1;
                        public IOSPlatformServices()
                        {
@@ -199,19 +200,26 @@ namespace Xamarin.Forms
                        {
                                // We make these up anyway, so new sizes didn't really change
                                // iOS docs say default button font size is 15, default label font size is 17 so we use those as the defaults.
+                               var scalingFactor = _fontScalingFactor;
+
+                               if (Application.Current?.On<iOS>().GetEnableAccessibilityScalingForNamedFontSizes() == false)
+                               {
+                                       scalingFactor = 1;
+                               }
+
                                switch (size)
                                {
                                        //We multiply the fonts by the scale factor, and cast to an int, to make them whole numbers.
                                        case NamedSize.Default:
-                                               return (int)((typeof(Button).IsAssignableFrom(targetElementType) ? 15 : 17) * _fontScalingFactor);
+                                               return (int)((typeof(Button).IsAssignableFrom(targetElementType) ? 15 : 17) * scalingFactor);
                                        case NamedSize.Micro:
-                                               return (int)(12 * _fontScalingFactor);
+                                               return (int)(12 * scalingFactor);
                                        case NamedSize.Small:
-                                               return (int)(14 * _fontScalingFactor);
+                                               return (int)(14 * scalingFactor);
                                        case NamedSize.Medium:
-                                               return (int)(17 * _fontScalingFactor);
+                                               return (int)(17 * scalingFactor);
                                        case NamedSize.Large:
-                                               return (int)(22 * _fontScalingFactor);
+                                               return (int)(22 * scalingFactor);
 #if __IOS__
                                        case NamedSize.Body:
                                                return (double)UIFont.PreferredBody.PointSize;