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.

TextInput dynamic color

See original GitHub issue

Environment

React Native Environment Info: System: OS: macOS Sierra 10.12.6 CPU: x64 Intel® Core™ i7-4770HQ CPU @ 2.20GHz Memory: 208.05 MB / 16.00 GB Shell: 3.2.57 - /bin/bash Binaries: Node: 10.6.0 - /usr/local/bin/node Yarn: 1.3.2 - /usr/local/bin/yarn npm: 6.1.0 - /usr/local/bin/npm Watchman: 4.9.0 - /usr/local/bin/watchman SDKs: iOS SDK: Platforms: iOS 11.2, macOS 10.13, tvOS 11.2, watchOS 4.2 IDEs: Android Studio: 3.1 AI-173.4819257 Xcode: 9.2/9C40b - /usr/bin/xcodebuild npmPackages: react: ^16.4.1 => 16.4.1 react-native: ^0.56.0 => 0.56.0 npmGlobalPackages: create-react-native-app: 1.0.0 react-native-cli: 2.0.1 react-native-git-upgrade: 0.2.7

Description

I have TextInput with dynamic changing color based on state.

<TextInput
                        style={[styles.input, {color: this.state.color}]}
                        value={this.props.value}
                        placeholder={this.props.inputProps.name}
                        onChangeText={(value) => {
                                if (this.props.onChangeText) {
                                    this.props.onChangeText(value);
                                }
                                this.setState({
                                    value: value
                                });
                                this.validate(value);
                            }
                        }
                    />

so when state changed textinput color not changing

 return this.setState({
            icon: valid ? "ios-checkmark-circle" : "ios-close-circle",
            color: valid ? SC_MAIN_COLOR : SC_ERROR_COLOR,
            valid: valid
        }, this.props.inputProps.onChangeValidity);

this worked before i upgraded from 0.49.5 to 0.56.0 If i manually change color on text input all is ok, so issue in dynamic color changing.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:9
  • Comments:26 (4 by maintainers)

github_iconTop GitHub Comments

5reactions
evasyukcommented, Jul 10, 2018

Have you tried to use Stylesheet.flatten(…) in order to find some workaround?

<Text style={StyleSheet.flatten([styles.textStyle,{color: 'red'}])}> Hello </Text>

const styles = StyleSheet.create({
   textStyle :{
      textAlign: 'center',   
      fontFamily: 'Arial',
      fontSize: 16
  }
  });

https://facebook.github.io/react-native/docs/stylesheet.html https://stackoverflow.com/questions/29363671/can-i-make-dynamic-styles-in-react-native

3reactions
SK-DNS-NETcommented, Aug 24, 2018

Same issue here. The Inspector of the Expo app displays the correct color attribute value of the TextInput component, but the rendering shows only the first color set.

Properties and style attributes of the TextInput component taken from react developer tools when text color is rendering in red:

{
  "placeholder": "000000.0",
   "value": "",
   "fontColor": "white",
   "placeholderColor": "#535353",
   "maxLength": 8,
   "fontSize": 34,
   "onChangeText": "[function onChangeText]",
   "style": [
     206,
     208,
     {
       "color": "white"
     }
   ],
   "allowFontScaling": true
 }

The screenshot of expo app on iOS simulator with inspector shows the TextInput component with the corresponding style attributes - red vs. white, style attributes vs. rendering.

simulator screen shot - iphone 8 - 2018-08-24 at 16 23 33

Edit The dynamically set of attributes is running only one time.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to change the textColor of TextInput in react native ...
hi guys i want to change textcolor of input dynamically. for example initially in CSS placed as color:'#fff',then i want to change the...
Read more >
React Native how set dynamic color on TextInput
React Native how set dynamic color on TextInput. ... import React, {useState} from 'react'; import { SafeAreaView, TextInput,Text, ...
Read more >
RN20131 - TextInput Dynamic Color - Expo Snack
Try this project on your phone! Use Expo's online editor to make changes and save your own copy.
Read more >
Change border color to text input node - Dashboard
Hi, I've been working on a home project using the dashboard ui nodes. I've been able to change dynamically the text and background...
Read more >
Formula if text change the color to be change in a textlabel
I have solved this by using the COLOR from the Formula bar for the textbox i wanted to change the color dynamically. coloer:...
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