Closed jitenderchand1 closed 7 years ago
how to style text in Htmlview, default styling !!!!! Any solution or alternative to render HTML in react native?
Just do something like this:
<HTMLView value={"<styledText>"+subHeader+"</styledText>"} stylesheet={webViewStyle} />}
and
const webViewStyle = StyleSheet.create({ styledText: { color:"red" } });
Thanks for the reply @stefan-digital-chefs ... But the solution is not working its not changing the colours for anything.:(
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.
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" } });
Ahh, working good for me now. I wasn't passing in the stylesheet correctly.
Thanks for the help.
Props can now be passed to the Text
component via textComponentProps
: see updated docs for details. This includes passing the style
prop :)
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
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} />