2222
2323public class RNMeasureTextModule extends ReactContextBaseJavaModule {
2424
25- public static void setAssetManager (AssetManager assetManager ) {
25+ static void setAssetManager (AssetManager assetManager ) {
2626 sAssetManager = assetManager ;
2727 }
2828
29- public RNMeasureTextModule (ReactApplicationContext reactContext ) {
29+ RNMeasureTextModule (ReactApplicationContext reactContext ) {
3030 super (reactContext );
3131 setAssetManager (reactContext .getAssets ());
3232 }
@@ -50,7 +50,7 @@ public void measure(ReadableMap options, Promise promise) {
5050 TextPaint textPaint = sTextPaintInstance ;
5151 @ Nullable Layout layout = null ;
5252
53- final boolean allowFontScaling = true ;
53+ // final boolean allowFontScaling = true;
5454 final int style = 0 ;
5555
5656 // width (optional)
@@ -72,7 +72,7 @@ public void measure(ReadableMap options, Promise promise) {
7272 if (options .hasKey ("fontFamily" )) {
7373 fontFamily = options .getString ("fontFamily" );
7474 }
75- if (fontFamily != null && fontFamily != "" ) {
75+ if (fontFamily != null && ! fontFamily . isEmpty () ) {
7676 Typeface typeface = getTypeface (fontFamily , style );
7777 textPaint .setTypeface (typeface );
7878 } else {
@@ -88,8 +88,6 @@ public void measure(ReadableMap options, Promise promise) {
8888 final boolean unconstrainedWidth = width <= 0 ;
8989 final float spacingMultiplier = 1 ;
9090 final float spacingAddition = 0 ;
91- final int textBreakStrategy =
92- (Build .VERSION .SDK_INT < Build .VERSION_CODES .M ) ? 0 : Layout .BREAK_STRATEGY_HIGH_QUALITY ;
9391
9492 int hintWidth = 0 ;
9593
@@ -134,13 +132,16 @@ public void measure(ReadableMap options, Promise promise) {
134132 includeFontPadding
135133 );
136134 } else {
137- layout = StaticLayout .Builder .obtain (text , 0 , text .length (), textPaint , hintWidth )
135+ StaticLayout . Builder builder = StaticLayout .Builder .obtain (text , 0 , text .length (), textPaint , hintWidth )
138136 .setAlignment (Layout .Alignment .ALIGN_NORMAL )
139137 .setLineSpacing (spacingAddition , spacingMultiplier )
140138 .setIncludePad (includeFontPadding )
141- .setBreakStrategy (textBreakStrategy )
142- .setHyphenationFrequency (Layout .HYPHENATION_FREQUENCY_NORMAL )
143- .build ();
139+ .setHyphenationFrequency (Layout .HYPHENATION_FREQUENCY_NORMAL );
140+
141+ if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .M ) {
142+ builder .setBreakStrategy (Layout .BREAK_STRATEGY_HIGH_QUALITY );
143+ }
144+ layout = builder .build ();
144145 }
145146 }
146147
0 commit comments