@@ -230,65 +230,22 @@ 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 )
244
237
public void setMaxFontSizeMultiplier (ReactEditText view , float maxFontSizeMultiplier ) {
245
238
view .setMaxFontSizeMultiplier (maxFontSizeMultiplier );
246
239
}
247
240
248
- /**
249
- * /* This code was taken from the method setFontWeight of the class ReactTextShadowNode /* TODO:
250
- * Factor into a common place they can both use
251
- */
252
241
@ 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
- }
242
+ public void setFontWeight (ReactEditText view , @ Nullable String fontWeight ) {
243
+ view .setFontWeight (fontWeight );
270
244
}
271
245
272
- /**
273
- * /* This code was taken from the method setFontStyle of the class ReactTextShadowNode /* TODO:
274
- * Factor into a common place they can both use
275
- */
276
246
@ 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
- }
247
+ public void setFontStyle (ReactEditText view , @ Nullable String fontStyle ) {
248
+ view .setFontStyle (fontStyle );
292
249
}
293
250
294
251
@ ReactProp (name = "importantForAutofill" )
@@ -800,6 +757,7 @@ public void setBorderColor(ReactEditText view, int index, Integer color) {
800
757
@ Override
801
758
protected void onAfterUpdateTransaction (ReactEditText view ) {
802
759
super .onAfterUpdateTransaction (view );
760
+ view .maybeUpdateTypeface ();
803
761
view .commitStagedInputType ();
804
762
}
805
763
@@ -813,23 +771,6 @@ private static void checkPasswordType(ReactEditText view) {
813
771
}
814
772
}
815
773
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
774
private static void updateStagedInputTypeFlag (
834
775
ReactEditText view , int flagsToUnset , int flagsToSet ) {
835
776
view .setStagedInputType ((view .getStagedInputType () & ~flagsToUnset ) | flagsToSet );
0 commit comments