How to achieve textAlign style?
This is just a question. I have some HTML code that includes a <td style="text-align: right"><div>...</div></td>. It seems to render some stuff right aligned on IOS, but not on android. When inspecting the td component, the styles are not there. Do they get propagated/moved into the inner most children? I suspect textAlign should actually be translated into alignSelf or alignItems if using flex.
I realized the text-align does not render / accept by the component, even I tried to do it with
Fail path:
With tag, <div style="text-align:center">
Without tag, I pass value to props **baseFontStyle**={{ textAlign:'center' }}
Success path:
At last I gave up using <div> tag and replace with <p>. Hooray, it's now center aligned 😄
Could we get a response from the developers whether this is something they intend to fix? The text-align prop does nothing on android (works fine on iOS). It seems that the prop is never used as the text will align center if it can fit on 1 line within the width, but as soon as the text needs 2 or more lines then it will always left-align. Changing all <div> elements to <p> like @TommyLeong suggest above is not a viable solution.
Hi,
Temporary solution worked on IOS and Android:
render() {
const defaultRenderer = {
renderers: {
p: (htmlAttribs, children, convertedCSSStyles, passProps) => {
return <Text style={{textAlign: 'center'}}>{children}</Text>;
},
},
};
<HTML {...defaultRenderer} html={content} />
@vvusts Thanks, I will give this a try and report back if it works in my solution aswell. I assume you can switch the 'p'-element to a 'div'-element if needed, right? like so:
renderers: {
div: (htmlAttribs, children, convertedCSSStyles, passProps) => {
return <Text style={{textAlign: 'center'}}>{children}</Text>;
},
Yes this way you can implement how each element should render.
I use it to render centered small clickable images for and etc.
We are in the process of cleaning the issue tracker to make it manageable. I suggest you continue the discussion in #347, as this seems to be a duplicate.