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.

Android <Text> color becomes invisible when switching back to initial state

See original GitHub issue

Description

This happens on react-native: 0.63.2 on Android.

<Text> color is visible initially, however, when you dynamically update a state to change the color of <Text> and then revert it back by changing the state, the text will become invisible. This did not happen on react-native: 0.62.2 and previous versions. Android forgets what its initial color was unless you explicitly set the default color.

I also thought it might be my default Android theme, but here is what I have for that: /android/app/main/res/values/styles.xml

<resources>
    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <!-- Customize your theme here. -->
        <item name="android:textColor">#000000</item>
    </style>
</resources>

React Native version:

System:
    OS: Windows 10 10.0.18363
    CPU: (12) x64 Intel(R) Core(TM) i7-8086K CPU @ 4.00GHz
    Memory: 33.62 GB / 63.93 GB
  Binaries:
    Node: 12.16.3 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.12.3 - C:\Program Files (x86)\Yarn\bin\yarn.CMD
    npm: 6.14.5 - ~\AppData\Roaming\npm\npm.CMD
    Watchman: Not Found
  SDKs:
    Android SDK: Not Found
  IDEs:
    Android Studio: Version  4.0.0.0 AI-193.6911.18.40.6626763
  Languages:
    Java: 12.0.2 - /c/Program Files (x86)/Java/jdk-12.0.2/bin/javac
    Python: 2.7.14 - /c/Users/Steven/.windows-build-tools/python27/python
  npmPackages:
    @react-native-community/cli: Not Found
    react: 16.13.1 => 16.13.1
    react-native: 0.63.2 => 0.63.2
  npmGlobalPackages:
    *react-native*: Not Found

Steps To Reproduce

Example code:

let active = false;
<Text style={active ? { color: 'green' } : null}>Example</Text>
  1. “Example” text is initially black (default color) and visible since active is false
  2. Set active state to true to toggle text color to green.
  3. Then set active state back to false, the text color is now invisible.

Expected Results

What I expect to happen is for the text to return back to its original color before the state was changed.

Snack, code example, screenshot, or link to a repository:

react-native (0.63.2):

import * as React from 'react';
import { Text, View, TouchableOpacity, StyleSheet } from 'react-native';

export default function App() {
  const [active, setActive] = React.useState(false);

  return (
    <View >
      <Text style={active ? {color: 'green'} : null}>Example</Text>

      <TouchableOpacity onPress={() => setActive(!active)}>
        <Text>Toggle Active</Text>
      </TouchableOpacity>
    </View>
  );
}

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:4
  • Comments:12 (4 by maintainers)

github_iconTop GitHub Comments

6reactions
preflowercommented, Dec 9, 2020

Is there any progress on this issue

1reaction
safaiyehcommented, Sep 3, 2020

Awesome @hank121314! I’ll check this out tomorrow. @ me if I don’t give an update as I promised

Read more comments on GitHub >

github_iconTop Results From Across the Web

Change the text color of a single ClickableSpan when pressed ...
The spans always keep the color of the default state in the color state list and never enter the pressed state. Does anyone...
Read more >
androidx.compose.material - Android Developers
Represents the colors used by a Switch in different states ... will not show the app bar when the back layer is revealed;...
Read more >
TextInputLayout Styling - Medium
Styling of each element of the TextInputLayout. Change the EditText bubble color. Change default outline border color for TextInputLayout.
Read more >
Working with the EditText | CodePath Android Cliffnotes
Check out the official text fields guide for even more input field details. Usage. An EditText is added to a layout with all...
Read more >
background-color - CSS: Cascading Style Sheets | MDN
Accessibility concerns. It is important to ensure that the contrast ratio between the background color and the color of the text placed over...
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