Skip to content

Commit

Permalink
feat: add support for text input - old arch
Browse files Browse the repository at this point in the history
  • Loading branch information
matinzd committed May 30, 2024
1 parent e3ee626 commit 9dd41dd
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public class TextAttributeProps {
* mFontVariationSettings can be used for variable font features e.g: 'wght' 850
* This works for Android 8.1 and above.
*/
protected String mFontVariationSettings = null;
protected @Nullable String mFontVariationSettings = null;

/**
* @see android.graphics.Paint#setFontFeatureSettings
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ public class ReactEditText extends AppCompatEditText {
private TextAttributes mTextAttributes;
private boolean mTypefaceDirty = false;
private @Nullable String mFontFamily = null;
private @Nullable String mFontVariationSettings = null;
private int mFontWeight = ReactConstants.UNSET;
private int mFontStyle = ReactConstants.UNSET;
private boolean mAutoFocus = false;
Expand Down Expand Up @@ -556,6 +557,18 @@ public void setFontFamily(String fontFamily) {
mTypefaceDirty = true;
}

@Override
public boolean setFontVariationSettings(@Nullable String fontVariationSettings) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
if (!Objects.equals(fontVariationSettings, getFontVariationSettings())) {
mTypefaceDirty = true;
mFontVariationSettings = fontVariationSettings;
return super.setFontVariationSettings(fontVariationSettings);
}
}
return false;
}

public void setFontWeight(String fontWeightString) {
int fontWeight = ReactTypefaceUtils.parseFontWeight(fontWeightString);
if (fontWeight != mFontWeight) {
Expand Down Expand Up @@ -770,6 +783,7 @@ private void stripStyleEquivalentSpans(SpannableStringBuilder sb) {
return span.getStyle() == mFontStyle
&& Objects.equals(span.getFontFamily(), mFontFamily)
&& span.getWeight() == mFontWeight
&& Objects.equals(span.getFontVariationSettings(), mFontVariationSettings)
&& Objects.equals(span.getFontFeatureSettings(), getFontFeatureSettings());
});
}
Expand Down Expand Up @@ -835,7 +849,7 @@ private void addSpansFromStyleAttributes(SpannableStringBuilder workingText) {
mFontWeight,
getFontFeatureSettings(),
mFontFamily,
null,
mFontVariationSettings,
getContext().getAssets()),
0,
workingText.length(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,11 @@ public void setFontFamily(ReactEditText view, String fontFamily) {
view.setFontFamily(fontFamily);
}

@ReactProp(name = ViewProps.FONT_VARIATION_SETTINGS)
public void setFontVariationSettings(ReactEditText view, String fontVariationSettings) {
view.setFontVariationSettings(fontVariationSettings);
}

@ReactProp(name = ViewProps.MAX_FONT_SIZE_MULTIPLIER, defaultFloat = Float.NaN)
public void setMaxFontSizeMultiplier(ReactEditText view, float maxFontSizeMultiplier) {
view.setMaxFontSizeMultiplier(maxFontSizeMultiplier);
Expand Down

0 comments on commit 9dd41dd

Please sign in to comment.