Android TextInput: Support `allowFontScaling` on placeholder (#22992)
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: https://github.com/facebook/react-native/pull/22992 Differential Revision: D13671400 Pulled By: cpojer fbshipit-source-id: 40bae3cfb0ca6298e91a81c05211538935f5a0e8
This commit is contained in:
Родитель
63038500a2
Коммит
e6057095ad
|
@ -644,6 +644,13 @@ public class ReactEditText extends EditText {
|
|||
applyTextAttributes();
|
||||
}
|
||||
|
||||
public void setAllowFontScaling(boolean allowFontScaling) {
|
||||
if (mTextAttributes.getAllowFontScaling() != allowFontScaling) {
|
||||
mTextAttributes.setAllowFontScaling(allowFontScaling);
|
||||
applyTextAttributes();
|
||||
}
|
||||
}
|
||||
|
||||
public void setFontSize(float fontSize) {
|
||||
mTextAttributes.setFontSize(fontSize);
|
||||
applyTextAttributes();
|
||||
|
|
|
@ -319,6 +319,11 @@ public class ReactTextInputManager extends BaseViewManager<ReactEditText, Layout
|
|||
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);
|
||||
|
|
Загрузка…
Ссылка в новой задаче