mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Android: Add a maxFontSizeMultiplier prop to <Text> and <TextInput> (#23069)
Summary: Equivalent of this iOS PR: https://github.com/facebook/react-native/pull/20915 Motivation: ---------- Whenever a user changes the system font size to its maximum allowable setting, React Native apps that allow font scaling can become unusable because the text gets too big. Experimenting with a native app like iMessage on iOS, the font size used for non-body text (e.g. header, navigational elements) is capped while the body text (e.g. text in the message bubbles) is allowed to grow. This PR introduces a new prop on `<Text>` and `<TextInput>` called `maxFontSizeMultiplier`. This enables devs to set the maximum allowed text scale factor on a Text/TextInput. The default is 0 which means no limit. Pull Request resolved: https://github.com/facebook/react-native/pull/23069 Differential Revision: D13748513 Pulled By: mdvacca fbshipit-source-id: 8dd5d6d97bf79387d9a2236fa2e586ccb01afde9
This commit is contained in:
1 parent
5bc709d517
commit
4936d284df
6 files changed
+67
-8
No files matched your search
@@ -7,6 +7,7 @@
|
||||
|
||||
package com.facebook.react.uimanager;
|
||||
|
||||
import android.util.DisplayMetrics;
|
||||
import android.util.TypedValue;
|
||||
|
||||
/**
|
||||
@@ -42,10 +43,21 @@ public class PixelUtil {
|
||||
* Convert from SP to PX
|
||||
*/
|
||||
public static float toPixelFromSP(float value) {
|
||||
return TypedValue.applyDimension(
|
||||
TypedValue.COMPLEX_UNIT_SP,
|
||||
value,
|
||||
DisplayMetricsHolder.getWindowDisplayMetrics());
|
||||
return toPixelFromSP(value, Float.NaN);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert from SP to PX
|
||||
*/
|
||||
public static float toPixelFromSP(float value, float maxFontScale) {
|
||||
DisplayMetrics displayMetrics = DisplayMetricsHolder.getWindowDisplayMetrics();
|
||||
float scaledDensity = displayMetrics.scaledDensity;
|
||||
float currentFontScale = scaledDensity / displayMetrics.density;
|
||||
if (maxFontScale >= 1 && maxFontScale < currentFontScale) {
|
||||
scaledDensity = displayMetrics.density * maxFontScale;
|
||||
}
|
||||
|
||||
return value * scaledDensity;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user