@@ -230,14 +230,7 @@ public void setFontSize(ReactEditText view, float fontSize) {
230
230
231
231
@ ReactProp (name = ViewProps .FONT_FAMILY )
232
232
public void setFontFamily (ReactEditText view , String fontFamily ) {
233
- int style = Typeface .NORMAL ;
234
- if (view .getTypeface () != null ) {
235
- style = view .getTypeface ().getStyle ();
236
- }
237
- Typeface newTypeface =
238
- ReactFontManager .getInstance ()
239
- .getTypeface (fontFamily , style , view .getContext ().getAssets ());
240
- view .setTypeface (newTypeface );
233
+ view .setFontFamily (fontFamily );
241
234
}
242
235
243
236
@ ReactProp (name = ViewProps .MAX_FONT_SIZE_MULTIPLIER , defaultFloat = Float .NaN )
@@ -250,45 +243,17 @@ public void setMaxFontSizeMultiplier(ReactEditText view, float maxFontSizeMultip
250
243
* Factor into a common place they can both use
251
244
*/
252
245
@ ReactProp (name = ViewProps .FONT_WEIGHT )
253
- public void setFontWeight (ReactEditText view , @ Nullable String fontWeightString ) {
254
- int fontWeightNumeric =
255
- fontWeightString != null ? parseNumericFontWeight (fontWeightString ) : -1 ;
256
- int fontWeight = UNSET ;
257
- if (fontWeightNumeric >= 500 || "bold" .equals (fontWeightString )) {
258
- fontWeight = Typeface .BOLD ;
259
- } else if ("normal" .equals (fontWeightString )
260
- || (fontWeightNumeric != -1 && fontWeightNumeric < 500 )) {
261
- fontWeight = Typeface .NORMAL ;
262
- }
263
- Typeface currentTypeface = view .getTypeface ();
264
- if (currentTypeface == null ) {
265
- currentTypeface = Typeface .DEFAULT ;
266
- }
267
- if (fontWeight != currentTypeface .getStyle ()) {
268
- view .setTypeface (currentTypeface , fontWeight );
269
- }
246
+ public void setFontWeight (ReactEditText view , @ Nullable String fontWeight ) {
247
+ view .setFontWeight (fontWeight );
270
248
}
271
249
272
250
/**
273
251
* /* This code was taken from the method setFontStyle of the class ReactTextShadowNode /* TODO:
274
252
* Factor into a common place they can both use
275
253
*/
276
254
@ ReactProp (name = ViewProps .FONT_STYLE )
277
- public void setFontStyle (ReactEditText view , @ Nullable String fontStyleString ) {
278
- int fontStyle = UNSET ;
279
- if ("italic" .equals (fontStyleString )) {
280
- fontStyle = Typeface .ITALIC ;
281
- } else if ("normal" .equals (fontStyleString )) {
282
- fontStyle = Typeface .NORMAL ;
283
- }
284
-
285
- Typeface currentTypeface = view .getTypeface ();
286
- if (currentTypeface == null ) {
287
- currentTypeface = Typeface .DEFAULT ;
288
- }
289
- if (fontStyle != currentTypeface .getStyle ()) {
290
- view .setTypeface (currentTypeface , fontStyle );
291
- }
255
+ public void setFontStyle (ReactEditText view , @ Nullable String fontStyle ) {
256
+ view .setFontStyle (fontStyle );
292
257
}
293
258
294
259
@ ReactProp (name = "importantForAutofill" )
@@ -800,6 +765,7 @@ public void setBorderColor(ReactEditText view, int index, Integer color) {
800
765
@ Override
801
766
protected void onAfterUpdateTransaction (ReactEditText view ) {
802
767
super .onAfterUpdateTransaction (view );
768
+ view .maybeUpdateTypeface ();
803
769
view .commitStagedInputType ();
804
770
}
805
771
@@ -813,23 +779,6 @@ private static void checkPasswordType(ReactEditText view) {
813
779
}
814
780
}
815
781
816
- /**
817
- * This code was taken from the method parseNumericFontWeight of the class ReactTextShadowNode
818
- * TODO: Factor into a common place they can both use
819
- *
820
- * <p>Return -1 if the input string is not a valid numeric fontWeight (100, 200, ..., 900),
821
- * otherwise return the weight.
822
- */
823
- private static int parseNumericFontWeight (String fontWeightString ) {
824
- // This should be much faster than using regex to verify input and Integer.parseInt
825
- return fontWeightString .length () == 3
826
- && fontWeightString .endsWith ("00" )
827
- && fontWeightString .charAt (0 ) <= '9'
828
- && fontWeightString .charAt (0 ) >= '1'
829
- ? 100 * (fontWeightString .charAt (0 ) - '0' )
830
- : -1 ;
831
- }
832
-
833
782
private static void updateStagedInputTypeFlag (
834
783
ReactEditText view , int flagsToUnset , int flagsToSet ) {
835
784
view .setStagedInputType ((view .getStagedInputType () & ~flagsToUnset ) | flagsToSet );
0 commit comments