jsdf / react-native-htmlview

A React Native component which renders HTML content as native views
ISC License
2.71k stars 467 forks source link

Default styling for all the text #70

Closed jitenderchand1 closed 7 years ago

jitenderchand1 commented 7 years ago

We got response in two format. Sometimes we got HTML tag within the response but sometimes we got plain string.

We do styling bases on the tags like given below. I want to apply the styling for all the text whether they are wrapped in HTML tag or not.

const webViewStyle = StyleSheet.create({ p: { color:"red", }, })

const body = "<p>Display Text</p>" const body = "Display Text"

<HTMLView style={styles.content} value={subHeader} stylesheet={webViewStyle} />

rajnikantsethiya commented 7 years ago

how to style text in Htmlview, default styling !!!!! Any solution or alternative to render HTML in react native?

Stefan-vs commented 7 years ago

Just do something like this:

<HTMLView value={"<styledText>"+subHeader+"</styledText>"} stylesheet={webViewStyle} />}

and

const webViewStyle = StyleSheet.create({ styledText: { color:"red" } });

rajnikantsethiya commented 7 years ago

Thanks for the reply @stefan-digital-chefs ... But the solution is not working its not changing the colours for anything.:(

neb-b commented 7 years ago

Any update on this? Using <styledText> doesn't work for me. I'm wrapping my text in a <p> and trying to update the color for that doesn't work either.

Stefan-vs commented 7 years ago

Weird. This works for me, just putting an element around the content string. Like this: <HTMLView value={"<newCustomElement>"+subHeader+"</newCustomElement>"} stylesheet={webViewStyle} />} And then provide a style for that element, like this: const webViewStyle = StyleSheet.create({ newCustomElement: { color:"red" } });

neb-b commented 7 years ago

Ahh, working good for me now. I wasn't passing in the stylesheet correctly.

Thanks for the help.

richchurcher commented 7 years ago

Props can now be passed to the Text component via textComponentProps: see updated docs for details. This includes passing the style prop :)

nitinnavik commented 1 year ago

what happen if value is normal text and we want to apply style for the same text . eg - value = 'The Life of Python,TEST' we can appy style to b tag but how we can apply style to all the text even it not wrap with any html tag