-
Notifications
You must be signed in to change notification settings - Fork 24.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Android TextInput font family incorrect after switching secureTextEntry
#30123
Comments
I'm also facing this issue after upgrading from 0.62.2 to 0.63.3 |
Having the same issue after upgrading, any progress resolving this? |
I'm also facing same issue in "react-native": "0.63.3". |
i'sorry to hear you'all are having the same issue, but glad to know i'm not crazy or doing something silly. i ended up doing something like this: this overrides one of the system fonts so that when RN fails to render the font in the style, the system font it does render is actually the same font. |
Hi @timomeara . |
I have the same issue regarding font family with placeholders. It also is an issue (for me) if I change secure text entry with |
Unfortunately, the original problem still persists for me. |
Do you try with Building from source? |
I mentioned this in the PR. I can't be 100% certain though but:
@Override
public void setInputType(int type) {
Typeface tf = super.getTypeface();
super.setInputType(type);
mStagedInputType = type;
// Input type password defaults to monospace font, so we need to re-apply the font
super.setTypeface(tf);
/**
* If set forces multiline on input, because of a restriction on Android source that enables
* multiline only for inputs of type Text and Multiline on method {@link
* android.widget.TextView#isMultilineInputType(int)}} Source: {@Link <a
* href='https://android.googlesource.com/platform/frameworks/base/+/jb-release/core/java/android/widget/TextView.java'>TextView.java</a>}
*/
if (isMultiline()) {
setSingleLine(false);
}
// We override the KeyListener so that all keys on the soft input keyboard as well as hardware
// keyboards work. Some KeyListeners like DigitsKeyListener will display the keyboard but not
// accept all input from it
mKeyListener.setInputType(type);
setKeyListener(mKeyListener);
} |
Hi @AndreasA ! |
My teammates and I tested it on two Android 10 devices. It is a functional component which does not do use any
We used that component multiple times in the same form. All fields have the correct placeholder styling, except the one with and in the form we used it like this:
And in the The password/last one has the wrong font the others work fine. And as mentioned it happend on two devices so I doubt it is device specific. Interesting is that setting |
Adding the following to the
|
wow, that was quick. |
I fixed this setting font family by ref in TextInput using useEffect and useRef. So, i think is better create your Input component with this code to get easier to use. -> Edit
Any questions read #30123 (comment) or the other solutions ahead of this post. |
Did you put inputElementRef inside ref props in TextInput ? Or did you wrote 'setNativeprops' instead of 'setNativeProps' with P in lowercase? |
I'm facing the same issue. I'd be ideal not to add extra code to something that should work natively :/. Here's the doc to the above answer: If for some reason you are obfuscating and then showing the password from an action, you could do something like this useEffect(() => {
const { fontFamily, secureTextEntry } = props;
if (textInputRef.current && fontFamily) {
textInputRef.current.setNativeProps({
secureTextEntry,
style: {
fontFamily,
},
});
}
}, [secureTextEntry]); |
@DracotMolver Thanks, just what I needed! I had a password field that rendered conditionally and used this: function Example () {
const passwordInput = useRef<TextInput>(null)
useEffect(() => {
passwordInput.current?.setNativeProps({ style: theme.input })
}, [condition])
return condition ? ... : <TextInput style={theme.input} secureTextEntry ref={passwordInput} />
} |
…ebook#30164) Summary: This pr fixes: facebook#30123 . When secureTextEntry is true, setInputType will set the inputType of textInput to password type. Password type default font-family will be monospace font, so we need to setTypeface after the setInputType. ## Changelog [Android] [Fixed] - Font family is not apply when secureTextEntry is true. Pull Request resolved: facebook#30164 Test Plan: Before this pr: ![alt text](https://i.imgur.com/mAxLhnB.png) After this pr: ![alt text](https://i.imgur.com/zoGYDxN.png) Please initiated a new project and replaced the App.js with the following code: ``` iimport React from 'react'; import {SafeAreaView, TextInput} from 'react-native'; const App = () => { return ( <SafeAreaView> <TextInput id={'email'} placeholder={'Email'} secureTextEntry={false} style={{fontFamily: 'Helvetica', fontSize: 14, fontWeight: '400'}} /> <TextInput id={'password'} placeholder={'Password'} secureTextEntry={true} style={{fontFamily: 'Helvetica', fontSize: 14, fontWeight: '400'}} /> </SafeAreaView> ); }; export default App; ``` Thanks you so much for your code review! Reviewed By: cpojer Differential Revision: D24686222 Pulled By: hramos fbshipit-source-id: 863ebe1dba36cac7d91b2735fe6e914ac839ed44
Works fine for me with 0.63.4 version |
Hey guys, Seems to be a bug. I resolved the bug based on previous comments.
|
Bug reproduced with v0.64.0... |
I can confirm that bug is back in v0.64.0 |
yeah looks like the commit with the fix landed on master after the 0.64 branch was cut so it's not there - I've added a reference to the commit in the 0.64.1 issue, thanks folks for reporting 👍 |
The problem continues to happen in React Native 0.64. It's not necessary to use useRef or useEffect to change the fontFamily. You can do this directly in the component reference. As below:
|
@everthon-carniel Thanks a lot, you saved my time, it works! |
the real answer!! thanks |
@melero2000 check if you provide a |
Helped me a lot, thanks :) |
This works, thank you, i was about to go crazy lol |
Bug reproduced with v0.64.1
|
…ebook#30164) Summary: This pr fixes: facebook#30123 . When secureTextEntry is true, setInputType will set the inputType of textInput to password type. Password type default font-family will be monospace font, so we need to setTypeface after the setInputType. ## Changelog [Android] [Fixed] - Font family is not apply when secureTextEntry is true. Pull Request resolved: facebook#30164 Test Plan: Before this pr: ![alt text](https://i.imgur.com/mAxLhnB.png) After this pr: ![alt text](https://i.imgur.com/zoGYDxN.png) Please initiated a new project and replaced the App.js with the following code: ``` iimport React from 'react'; import {SafeAreaView, TextInput} from 'react-native'; const App = () => { return ( <SafeAreaView> <TextInput id={'email'} placeholder={'Email'} secureTextEntry={false} style={{fontFamily: 'Helvetica', fontSize: 14, fontWeight: '400'}} /> <TextInput id={'password'} placeholder={'Password'} secureTextEntry={true} style={{fontFamily: 'Helvetica', fontSize: 14, fontWeight: '400'}} /> </SafeAreaView> ); }; export default App; ``` Thanks you so much for your code review! Reviewed By: cpojer Differential Revision: D24686222 Pulled By: hramos fbshipit-source-id: 863ebe1dba36cac7d91b2735fe6e914ac839ed44
…ebook#30164) Summary: This pr fixes: facebook#30123 . When secureTextEntry is true, setInputType will set the inputType of textInput to password type. Password type default font-family will be monospace font, so we need to setTypeface after the setInputType. ## Changelog [Android] [Fixed] - Font family is not apply when secureTextEntry is true. Pull Request resolved: facebook#30164 Test Plan: Before this pr: ![alt text](https://i.imgur.com/mAxLhnB.png) After this pr: ![alt text](https://i.imgur.com/zoGYDxN.png) Please initiated a new project and replaced the App.js with the following code: ``` iimport React from 'react'; import {SafeAreaView, TextInput} from 'react-native'; const App = () => { return ( <SafeAreaView> <TextInput id={'email'} placeholder={'Email'} secureTextEntry={false} style={{fontFamily: 'Helvetica', fontSize: 14, fontWeight: '400'}} /> <TextInput id={'password'} placeholder={'Password'} secureTextEntry={true} style={{fontFamily: 'Helvetica', fontSize: 14, fontWeight: '400'}} /> </SafeAreaView> ); }; export default App; ``` Thanks you so much for your code review! Reviewed By: cpojer Differential Revision: D24686222 Pulled By: hramos fbshipit-source-id: 863ebe1dba36cac7d91b2735fe6e914ac839ed44 (cherry picked from commit 00d9dea)
Hi guys, I'm getting the same result as @melero2000 with RN 0.64.1. Any idea how to fix this? |
The function 'setNativeProps' is overwriting the property 'text' to a empty string. You can see this setting: You can fix this problem setting the current value of input in the 'setNativeProps' function (remember to check if ref.props exists)
You can also fix this problem using 'useState' from react library.
|
) Summary: This pr fixes: #30123 . When secureTextEntry is true, setInputType will set the inputType of textInput to password type. Password type default font-family will be monospace font, so we need to setTypeface after the setInputType. ## Changelog [Android] [Fixed] - Font family is not apply when secureTextEntry is true. Pull Request resolved: #30164 Test Plan: Before this pr: ![alt text](https://i.imgur.com/mAxLhnB.png) After this pr: ![alt text](https://i.imgur.com/zoGYDxN.png) Please initiated a new project and replaced the App.js with the following code: ``` iimport React from 'react'; import {SafeAreaView, TextInput} from 'react-native'; const App = () => { return ( <SafeAreaView> <TextInput id={'email'} placeholder={'Email'} secureTextEntry={false} style={{fontFamily: 'Helvetica', fontSize: 14, fontWeight: '400'}} /> <TextInput id={'password'} placeholder={'Password'} secureTextEntry={true} style={{fontFamily: 'Helvetica', fontSize: 14, fontWeight: '400'}} /> </SafeAreaView> ); }; export default App; ``` Thanks you so much for your code review! Reviewed By: cpojer Differential Revision: D24686222 Pulled By: hramos fbshipit-source-id: 863ebe1dba36cac7d91b2735fe6e914ac839ed44
customs font adding after text not center showing any idea? |
<TextInput ref={ref => ref && ref.setNativeProps({ style: { fontFamily: 'FONT_NAME' } })} /> working v0.64.1 |
This is Issue isn't closed and not resolved in 0.64.2 so please re-open it! |
Still have the bug in 0.63.3.... and @everthon-carniel fix works. |
thank you so much .. this resolves my problem also. |
This is working perfectly for me:The refs can be both defined or undefined when the component is being mounted. Add the following to your component: const _inputRef = useRef(null);
const setRef = useCallback((node) => {
if (_inputRef.current) {
// Make sure to cleanup any events/references added to the last instance
}
if (node) {
// Check if a node is actually passed. Otherwise node would be null.
// You can now do what you need to, setNativeProps, addEventListeners, measure, etc.
// Important Tip: you can also hide (not unmount) the component till this part
node.setNativeProps({
style: { fontFamily: "Quicksand-Medium" },
});
}
// Save a reference to the node
_inputRef.current = node;
}, []); Make sure your TextInput has this ref assigned: <TextInput ref={setRef} ... /> |
This appears to be an old issue, but i'm seeing it now in 0.63.3
it's not occurring in IOS
#6149, #5710
Description
When secureTextEntry={true} for TextInput, the font-family for placeholder is ignored:
React Native version:
System:
OS: macOS 10.15.4
CPU: (16) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
Memory: 596.29 MB / 32.00 GB
Shell: 5.8 - /usr/local/bin/zsh
Binaries:
Node: 12.18.3 - /usr/local/bin/node
Yarn: 1.17.3 - ~/.yarn/bin/yarn
npm: 6.14.6 - /usr/local/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
Managers:
CocoaPods: 1.9.1 - /Users/timo/.rvm/rubies/ruby-2.4.1/bin/pod
SDKs:
iOS SDK:
Platforms: iOS 14.0, DriverKit 19.0, macOS 10.15, tvOS 14.0, watchOS 7.0
Android SDK:
API Levels: 22, 23, 24, 25, 26, 27, 28, 29
Build Tools: 23.0.1, 23.0.2, 23.0.3, 25.0.0, 25.0.1, 25.0.2, 25.0.3, 26.0.1, 26.0.2, 27.0.0, 27.0.1, 27.0.2, 27.0.3, 28.0.0, 28.0.2, 28.0.3, 29.0.2
System Images: a...google_apis | Google APIs Intel x86 Atom Sys..., a...-23 | Intel x86 Atom, a... | Intel x86 Atom_64, a...google_apis | Google APIs Intel x86 Atom Sys..., a...gle_apis | Google APIs Intel x86 Atom_64 ..., a...google_apis | Google APIs Intel x86 Atom Sys..., a...google_apis | Google APIs Intel x86 Atom Sys..., a...s_playstore | Google Play Intel x86 Atom Sys..., a...google_apis | Google APIs Intel x86 Atom Sys..., a...gle_apis | Google APIs Intel x86 Atom_64 ..., a...s_playstore | Google Play Intel x86 Atom Sys...
Android NDK: Not Found
IDEs:
Android Studio: Not Found
Xcode: 12.0.1/12A7300 - /usr/bin/xcodebuild
Languages:
Python: 3.8.5 - /usr/local/bin/python
npmPackages:
@react-native-community/cli: Not Found
react: 16.13.1 => 16.13.1
react-native: 0.63.3 => 0.63.3
npmGlobalPackages:
react-native: Not Found
Steps To Reproduce
Provide a detailed list of steps that reproduce the issue.
Expected Results
i expect the style rules to be applied
Snack, code example, screenshot, or link to a repository:
The text was updated successfully, but these errors were encountered: