-
-
Notifications
You must be signed in to change notification settings - Fork 591
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issue with bullet RTL #286
Comments
I just had this problem, my solution is below. The issue stems from the way the For the example below (lifted lazily from my own code), I've wrapped the import {_constructStyles} from 'react-native-render-html/src/HTMLStyles'
import HTML from 'react-native-render-html'
import React, { Component } from 'react'
import { Text, Linking, View } from 'react-native'
class HTMLRenderer extends Component {
render() {
return (
<HTML
html={this.props.html}
renderers={{
ul: (htmlAttribs, children, convertedCSSStyles, passProps) => {
const style = _constructStyles({
tagName: 'ul',
htmlAttribs,
passProps,
styleSet: 'VIEW'
});
const { allowFontScaling, rawChildren, nodeIndex, key, baseFontStyle, listsPrefixesRenderers } = passProps;
const baseFontSize = baseFontStyle.fontSize || 14;
children = children && children.map((child, index) => {
const rawChild = rawChildren[index];
let prefix = false;
const rendererArgs = [
htmlAttribs,
children,
convertedCSSStyles,
{
...passProps,
index
}
];
if (rawChild) {
if (rawChild.parentTag === 'ul' && rawChild.tagName === 'li') {
prefix = listsPrefixesRenderers && listsPrefixesRenderers.ul ? listsPrefixesRenderers.ul(...rendererArgs) : (
<View style={{
marginRight: 10,
width: baseFontSize / 2.8,
height: baseFontSize / 2.8,
marginTop: baseFontSize / 2,
borderRadius: baseFontSize / 2.8,
backgroundColor: 'black',
marginLeft: this.props.RTL ? 10 : 0
}} />
);
} else if (rawChild.parentTag === 'ol' && rawChild.tagName === 'li') {
prefix = listsPrefixesRenderers && listsPrefixesRenderers.ol ? listsPrefixesRenderers.ol(...rendererArgs) : (
<Text allowFontScaling={allowFontScaling} style={{
marginRight: 5,
fontSize: baseFontSize,
marginLeft: this.props.RTL ? 10 : 0 }}>{ index + 1 })</Text>
);
}
}
return (
this.props.RTL ? (
<View key={`list-${nodeIndex}-${index}-${key}`} style={{ flexDirection: 'row', marginBottom: 10 }}>
<View style={{ flex: 1 }}>{ child }</View>
{ prefix }
</View>
) : (
<View key={`list-${nodeIndex}-${index}-${key}`} style={{ flexDirection: 'row', marginBottom: 10 }}>
{ prefix }
<View style={{ flex: 1 }}>{ child }</View>
</View>
)
);
});
return (
<View style={style} key={key}>
{ children }
</View>
);
}
}}
></HTML>
)
}
} I hope that makes sense. Most of the code is directly from HTMLRenderers.js, ctrl+f for My heartfelt thanks to the author of this amazing library, it's really great. |
I've been exploring this issue a little bit for the foundry release (see #430), below are my findings. I. RTL in the WebThe Web standards offer basically two ways to handle RTL typography.
When direction is set to
In CSS, the box model of an element can be direction and writing-mode dependent thanks to the below shorthand properties and their longhand equivalents:
The set of all these properties is referred to as CSS logical properties. Back to lists now... This is how the style of UL elements is defined in Firefox stylesheet: ul,
menu,
dir {
display: block;
list-style-type: disc;
margin-block-start: 1em;
margin-block-end: 1em;
padding-inline-start: 40px;
} Notice the II. RTL in React NativeUnfortunately, RTL support in React Native is yet limited. As of React Native 0.64.0, I know three features:
III. Foreseeable solutionsShort term: configurable lists layoutA new prop would force lists layouts to display RTL. When this prop is set to Long term: featured support in
|
Good news folks, I have made great progress regarding lists in general, and RTL in particular. I've just released a standalone component, Lower LatinshowDiscshowArabic + RTLshowDisc + RTLshow |
🚀 Experimental support for import React from 'react';
import { ScrollView } from 'react-native';
import RenderHTML from 'react-native-render-html';
const html = `
<ul dir="rtl">
<li>يقوم اتحاد شبكة الويب العالمية (W3C)
بتطوير معايير دولية للويب و HTML و
CSS وغير ذلك الكثير.</li>
<li>يقوم اتحاد شبكة الويب العالمية (W3C)
بتطوير معايير دولية للويب و HTML و
CSS وغير ذلك الكثير.</li>
<li>يقوم اتحاد شبكة الويب العالمية (W3C)
بتطوير معايير دولية للويب و HTML و
CSS وغير ذلك الكثير.</li>
<li>يقوم اتحاد شبكة الويب العالمية (W3C)
بتطوير معايير دولية للويب و HTML و
CSS وغير ذلك الكثير.</li>
</ul>
`;
const renderersProps = {
// Experimental RTL support is only available for list elements.
ol: { enableExperimentalRtl: true },
ul: { enableExperimentalRtl: true }
};
const tagsStyles = {
// We need to reverse default styles for RTL
ul: { paddingLeft: 0, paddingRight: 30 },
ol: { paddingLeft: 0, paddingRight: 30 }
};
export default function App() {
return (
<ScrollView style={{ flexGrow: 1 }}>
<RenderHTML
source={{ html }}
tagsStyles={tagsStyles}
renderersProps={renderersProps}
/>
</ScrollView>
);
} Remarks:
Now, just to show you the new capabilities of this version, let's implement arabic-indic support: import React from 'react';
import { ScrollView } from 'react-native';
import RenderHTML from 'react-native-render-html';
import arabicIndic from '@jsamr/counter-style/presets/arabicIndic';
const html = `
<ol dir="rtl" style="list-style-type: arabic-indic;">
<li>يقوم اتحاد شبكة الويب العالمية (W3C)
بتطوير معايير دولية للويب و HTML و
CSS وغير ذلك الكثير.</li>
<li>يقوم اتحاد شبكة الويب العالمية (W3C)
بتطوير معايير دولية للويب و HTML و
CSS وغير ذلك الكثير.</li>
<li>يقوم اتحاد شبكة الويب العالمية (W3C)
بتطوير معايير دولية للويب و HTML و
CSS وغير ذلك الكثير.</li>
<li>يقوم اتحاد شبكة الويب العالمية (W3C)
بتطوير معايير دولية للويب و HTML و
CSS وغير ذلك الكثير.</li>
</ol>
`;
const renderersProps = {
// Experimental RTL support is only available for list elements.
ol: { enableExperimentalRtl: true },
ul: { enableExperimentalRtl: true }
};
const tagsStyles = {
// We need to reverse default styles for RTL
ul: { paddingLeft: 0, paddingRight: 30 },
ol: { paddingLeft: 0, paddingRight: 30 }
};
const customListStyleSpecs = {
'arabic-indic': {
type: 'textual',
counterStyleRenderer: arabicIndic
}
};
export default function App() {
return (
<ScrollView style={{ flexGrow: 1 }}>
<RenderHTML
source={{ html }}
tagsStyles={tagsStyles}
renderersProps={renderersProps}
customListStyleSpecs={customListStyleSpecs}
/>
</ScrollView>
);
} Check @jsamr/counter-style library for more presets and guides to implement arbitrary counter styles |
Closing now since the stable beta which fixes this issue has just been released. |
setting textAlign: "left" on base style fixes other kind of problems with other tags e.g. span, ... |
@Stevemoretz would be very helpful if you shared an example of those issues ; perhaps on Discord? |
Try to add (Work only in IOS):
in |
I first off want to say, great package! I ran in to a bit of a problem and I am not sure how to resolve it.
I have an RTL layout with an RTL language. As React-Native auto aligns RTL languages to the right, my parsed HTML is aligned to the right. But the bullets seems to stay on the left. I have tried
alignText: 'right'
on thebaseFontStyle
with no luck.Here is the screenshot of what I am getting.
https://ibb.co/NZyCkjM
Thanks
The text was updated successfully, but these errors were encountered: