From e6057095adfdc77ccbbff1c97b1e86b06dae340b Mon Sep 17 00:00:00 2001 From: Adam Comella Date: Wed, 16 Jan 2019 05:25:40 -0800 Subject: [PATCH] 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 --- .../com/facebook/react/views/textinput/ReactEditText.java | 7 +++++++ .../react/views/textinput/ReactTextInputManager.java | 5 +++++ 2 files changed, 12 insertions(+) diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactEditText.java b/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactEditText.java index cca7f4ad5e..1e20f0616b 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactEditText.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactEditText.java @@ -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(); diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputManager.java b/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputManager.java index 831c7e084c..26a38d6d0b 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputManager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputManager.java @@ -319,6 +319,11 @@ public class ReactTextInputManager extends BaseViewManager