AndroidTextInput throws error when color style is set to null
See original GitHub issueDescription
I have written a small component under “Reproduction” to describe this.
If you have a special style which is pushed onto a base style on a TextInput field, where the base style doesn’t explicitly specify a “color” attribute but the special style does, then if the component re-renders from [ baseStyle, specialStyle ]
to just [ baseStyle ]
due to a setState()
the following error is thrown. This happens only on the Android platform.
Error while updating property 'color' of a view managed by: AndroidTextInput
Reproduction
import React, { Component } from 'react'
import {
StyleSheet,
TextInput
} from 'react-native'
export default class Test extends Component {
constructor(props) {
super(props)
this.state = {
text: '',
special: false
}
}
render() {
let style = [ styles.baseStyle ]
if(this.state.special) style.push(styles.specialStyle)
return <TextInput
style={ style }
value={ this.state.text }
onChangeText={ (text) => this.setState({
text: text,
special: !this.state.special
}) } />
}
}
const styles = StyleSheet.create({
baseStyle: {
height: 50,
// color: 'blue' <-- uncomment this code to make the problem go away
},
specialStyle: {
color: 'red'
}
})
Additional Information
- React Native version: $ react-native --version react-native-cli: 1.0.0 react-native: 0.35.0
- Platform: Android
- Operating System: macOS Sierra
Issue Analytics
- State:
- Created 7 years ago
- Comments:13 (6 by maintainers)
Top Results From Across the Web
android TextInputLayout changes EditText style after setting ...
This problem occurs if we set a custom background drawable/color to the ... color back to whatever you want after setting the error...
Read more >Android TextInputLayout Example | DigitalOcean
This is a single Activity application. We'll be doing all the stuff inside the layout, activity and styles.xml and colors.xml files. Firstly, ...
Read more >EditText - Android Developers
android:autoText, If set, specifies that this TextView has a textual input method ... android:textAppearance, Base text color, typeface, size, and style.
Read more >TypeError: Reduce of empty array with no initial value
This error is raised when an empty array is provided because no initial value can be returned in that case. Examples. Invalid cases....
Read more >Working with the EditText | CodePath Android Cliffnotes
Using these properties we can define the expected input behavior for text fields. Adjusting Colors. You can adjust the highlight background color of...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I was able to reproduce with the above example. I enabled spy mode on the MessageQueue and checked logs to see what the issue was, it appears to be that the color cannot be set to null.
So, the easiest repro case is just to set the color on TextInput to
null
We’ve experienced the same issue, and the work around is to define the
color
and only conditionally change the value.Context
react-native 0.52.2 Not working on Android only
Examples
Not working
Working