How can I make all the Text children of a View element have the same style?

Luis Rizo

I want to have something similar to CSS, where you can give the 'color' style to a div and any text within it will have it.

I have multiple Text components within a View component and I would like them to all have the same text color.

If I pass a 'color' style to the view it would throw a warning.

I would like to avoid having to pass the same style to all these children when their parent can have the style for all of them.

I would like to go from this:

<View>
  <Text style={styles.Warning}>
  </Text>
  <Text style={styles.Warning}>
  </Text>
  <Text style={styles.Warning}>
  </Text>
  <Text style={styles.Warning}>
  </Text>
  <Text style={styles.Warning}>
  </Text>
</View>

to this:

<View style={styles.Warning}>
  <Text>
  </Text>
  <Text>
  </Text>
  <Text>
  </Text>
  <Text>
  </Text>
  <Text>
  </Text>
</View>

With the styles being:

const styles = StyleSheet.create({
  Warning:{
    color:'#a94442'
  }
});

(It would be better if I don't have to install anything) Thank you.

Neel Gala

Yes, you can definitely do the same you want. The only part you are missing is having the Text container inside he View container.

Example:

<View>
 <Text style={{color:'red'}}>
   <Text>
     text1 // will inherit red color
   </Text>
   <Text>
     text2 // will inherit red color
   </Text>
 </Text>
</View>

For further information you can also check out the link https://facebook.github.io/react-native/docs/text.html#containers

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How can I dynamically set a style for all children of an element?

From Dev

How to make all children in a flex-container to have the same height

From Java

How do I apply a style to all children of an element

From Dev

How can I make a flexbox parent have the width of its children?

From Dev

How can I apply a style to all inputs that are text and dont have the "size" attribute?

From Dev

How to get all text children of an element in cElementTree?

From Dev

How to make a text have a "Message Style Apperance"

From Dev

How can I check if all rows have the same column value?

From Dev

How can I delete all files that have the same extension ".TMP"?

From Dev

How can I make the TextView controls which contain characters "A" have the same width with text align left and control align right?

From Dev

How can I access the children of a panel element?

From Dev

How can I access the children of a panel element?

From Java

How can I make Bootstrap columns all the same height?

From Dev

How can I make all pages in a PDF the same size?

From Dev

How can I make a shortcut to close all the windows of the same application?

From Dev

How can I make a UITextView layout text the same as a UILabel?

From Dev

How can I make the background of an li the same length as the text in it?

From Dev

How can I make the background of an li the same length as the text in it?

From Dev

How can I make a UITextView layout text the same as a UILabel?

From Dev

How can I flatten this result set to have the parents and children as all one level?

From Dev

XML(DTD): How can I make sure one of the children of an element is required, but not necessarily a specific one?

From Dev

How can I make the tap highlight show only on a parent element, not on children?

From Dev

How to make all rows have same size?

From Dev

How can I make it so the opague style only affects the outer element and not the inner element

From Dev

How can I make Span children with text to layout to fit the width of the parent div tag?

From Dev

Hide parent if all li children element have CSS style display: none

From Dev

how to make activity can be scrolled vertically if I have view pager that has recycler view in it?

From Dev

Can I have different font style/sizes in the same graphviz record?

From Dev

How can I get element:hover style?

Related Related

  1. 1

    How can I dynamically set a style for all children of an element?

  2. 2

    How to make all children in a flex-container to have the same height

  3. 3

    How do I apply a style to all children of an element

  4. 4

    How can I make a flexbox parent have the width of its children?

  5. 5

    How can I apply a style to all inputs that are text and dont have the "size" attribute?

  6. 6

    How to get all text children of an element in cElementTree?

  7. 7

    How to make a text have a "Message Style Apperance"

  8. 8

    How can I check if all rows have the same column value?

  9. 9

    How can I delete all files that have the same extension ".TMP"?

  10. 10

    How can I make the TextView controls which contain characters "A" have the same width with text align left and control align right?

  11. 11

    How can I access the children of a panel element?

  12. 12

    How can I access the children of a panel element?

  13. 13

    How can I make Bootstrap columns all the same height?

  14. 14

    How can I make all pages in a PDF the same size?

  15. 15

    How can I make a shortcut to close all the windows of the same application?

  16. 16

    How can I make a UITextView layout text the same as a UILabel?

  17. 17

    How can I make the background of an li the same length as the text in it?

  18. 18

    How can I make the background of an li the same length as the text in it?

  19. 19

    How can I make a UITextView layout text the same as a UILabel?

  20. 20

    How can I flatten this result set to have the parents and children as all one level?

  21. 21

    XML(DTD): How can I make sure one of the children of an element is required, but not necessarily a specific one?

  22. 22

    How can I make the tap highlight show only on a parent element, not on children?

  23. 23

    How to make all rows have same size?

  24. 24

    How can I make it so the opague style only affects the outer element and not the inner element

  25. 25

    How can I make Span children with text to layout to fit the width of the parent div tag?

  26. 26

    Hide parent if all li children element have CSS style display: none

  27. 27

    how to make activity can be scrolled vertically if I have view pager that has recycler view in it?

  28. 28

    Can I have different font style/sizes in the same graphviz record?

  29. 29

    How can I get element:hover style?

HotTag

Archive