Skip to content

Commit

Permalink
Android TextInput: Support allowFontScaling on placeholder (#22992)
Browse files Browse the repository at this point in the history
Summary:
Currently, the `TextInput's` placeholder is always sized as though `allowFontScaling` is `true`.

Note that `allowFontScaling` works fine for the content of the `TextInput`. The reason is that we set the font size in two places: in the shadow node and in the Android view. The shadow node logic determines the size of the content and the Android view logic determines the size of the placeholder. The handler for the `allowFontScaling` prop is only present in the shadow node logic. Consequently, the Android view logic always uses the default value of `true` for the `allowFontScaling` prop.

The fix is to add logic for handling the `allowFontScaling` prop to the Android view.

It would be great if we could handle all text props in one spot instead of duplicating code between the shadow node and the Android view. That would eliminate this whole class of bugs. However, I don't have enough familiarity with the history of this code to know how hard that would be or if it's even possible.

Fixes #18827.
Pull Request resolved: #22992

Differential Revision: D13671400

Pulled By: cpojer

fbshipit-source-id: 40bae3cfb0ca6298e91a81c05211538935f5a0e8
  • Loading branch information
Adam Comella authored and facebook-github-bot committed Jan 16, 2019
1 parent 6303850 commit e605709
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,13 @@ public void setLetterSpacingPt(float letterSpacingPt) {
applyTextAttributes();
}

public void setAllowFontScaling(boolean allowFontScaling) {
if (mTextAttributes.getAllowFontScaling() != allowFontScaling) {
mTextAttributes.setAllowFontScaling(allowFontScaling);
applyTextAttributes();
}
}

public void setFontSize(float fontSize) {
mTextAttributes.setFontSize(fontSize);
applyTextAttributes();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,11 @@ public void setLetterSpacing(ReactEditText view, float letterSpacing) {
view.setLetterSpacingPt(letterSpacing);
}

@ReactProp(name = ViewProps.ALLOW_FONT_SCALING, defaultBoolean = true)
public void setAllowFontScaling(ReactEditText view, boolean allowFontScaling) {
view.setAllowFontScaling(allowFontScaling);
}

@ReactProp(name = "placeholder")
public void setPlaceholder(ReactEditText view, @Nullable String placeholder) {
view.setHint(placeholder);
Expand Down

0 comments on commit e605709

Please sign in to comment.