Skip to content

Commit

Permalink
fix: max scale factor works as intended on android
Browse files Browse the repository at this point in the history
  • Loading branch information
JulesEmond committed May 13, 2022
1 parent 0e09483 commit 63b2944
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
6 changes: 5 additions & 1 deletion src/Uno.UI/Controls/UIFontHelper.iOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,11 @@ private static nfloat GetScaledFontSize(nfloat size, nfloat? basePreferredSize)
}

var originalScale = (basePreferredSize / DefaultUIFontPreferredBodyFontSize) ?? (float)1.0;
return size * Math.Min((float)originalScale, (float)FeatureConfiguration.Font.MaximumTextScaleFactor);
if (FeatureConfiguration.Font.MaximumTextScaleFactor is float scaleFactor)
{
return size * Math.Min(originalScale, scaleFactor);
}
return size * originalScale;
}

private static UIFont InternalTryGetFont(nfloat size, FontWeight fontWeight, FontStyle fontStyle, FontFamily requestedFamily, nfloat? basePreferredSize)
Expand Down
4 changes: 2 additions & 2 deletions src/Uno.UI/Extensions/ViewHelper.Android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -467,9 +467,9 @@ private static void AdjustScaledDensity(Android.Util.DisplayMetrics displayMetri
// https://developer.xamarin.com/api/property/Android.Util.DisplayMetrics.ScaledDensity/
displayMetrics.ScaledDensity = displayMetrics.Density;
}
else
else if (FeatureConfiguration.Font.MaximumTextScaleFactor is float scaleFactor)
{
displayMetrics.ScaledDensity = Math.Min(displayMetrics.ScaledDensity, (float)FeatureConfiguration.Font.MaximumTextScaleFactor);
displayMetrics.ScaledDensity = Math.Min(displayMetrics.ScaledDensity, scaleFactor * displayMetrics.Density);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Uno.UI/FeatureConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ public static class Font
/// <summary>
/// Allows the user to limit the scale factor without having to ignore it.
/// </summary>
public static double? MaximumTextScaleFactor { get; set; }
public static float? MaximumTextScaleFactor { get; set; }
#endif
}

Expand Down

0 comments on commit 63b2944

Please sign in to comment.