question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

AndroidTextInput throws error when color style is set to null

See original GitHub issue

Description

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:closed
  • Created 7 years ago
  • Comments:13 (6 by maintainers)

github_iconTop GitHub Comments

3reactions
brentvatnecommented, Oct 31, 2016

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.

// After entering the first letter, a, we apply the "special" style and the text color becomes red
10-30 13:35:19.623 20202 20379 I ReactNativeJS: JS->N : UIManager.updateView([4,"AndroidTextInput",{"color":-65536,"text":"a"}])
// After entering the second letter, a again, we remove the "special" style and the text color becomes null
10-30 13:35:25.447 20202 20379 I ReactNativeJS: JS->N : UIManager.updateView([4,"AndroidTextInput",{"color":null,"text":"aa"}])

So, the easiest repro case is just to set the color on TextInput to null

1reaction
grabcodecommented, Apr 19, 2018

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

<TextInput
  { ...someProps }
  style={[
    styles.address,
    !editable && { color: '#fff' }
  ]}
/>

Working

<TextInput
  { ...someProps }
  style={[
    styles.address,
    { color: !editable ? '#fff' : '#000' }
  ]}
/>
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found