react-native-arabic-autoheight-text
Version:
Smart Arabic/RTL text renderer for React Native using WebView: auto height, proper justification, line clamp, and skeleton loading.
201 lines (141 loc) โข 6.21 kB
Markdown
# ๐ธ๐ฆ react-native-arabic-autoheight-text
**Beautiful Arabic & RTL text inside WebView โ Auto Height + Proper Typography**
[](https://www.npmjs.com/package/react-native-arabic-autoheight-text)
[](./LICENSE)
[]()
[]()
A tiny, drop-in React Native component for **Arabic / RTL text rendering** with:
* ๐ Auto height inside WebView (no scrolling)
* ๐ Perfect RTL direction + proper justification
* โ๏ธ Line clamping using CSS (`-webkit-line-clamp`)
* ๐จ Converts `TextStyle` โ WebView CSS
* ๐ฆด Built-in / custom Skeleton loader
* ๐ Adaptive skeleton for dark mode
* ๐ Supports fixed or dynamic layout with accuracy
Designed for:
**News, corporate content, About screens, product descriptions, long Arabic articlesโฆ**
## ๐ฅ Demo

## ๐ฆ Installation
```bash
yarn add react-native-arabic-autoheight-text react-native-webview react-native-skeleton-placeholder
# OR
npm install react-native-arabic-autoheight-text react-native-webview react-native-skeleton-placeholder
```
iOS
```bash
cd ios && pod install
```
## ๐งฉ Usage
### Basic Example
```tsx
<RtlTextView
text="ูุฐุง ุงููุต ุณูุชู
ุถุจุท ุงุฑุชูุงุนู ุชููุงุฆูุงู ุญุณุจ ุงูู
ุญุชูู"
textStyle={{ fontSize: 18, color: '#333' }}
/>
```
### Line Clamping
```tsx
<RtlTextView
text="ูุต ุนุฑุจู ุทููู ุณูุชู
ูุตู ุจุนุฏ ุซูุงุซุฉ ุฃุณุทุฑ ููุท..."
numberOfLines={3}
textStyle={{ fontSize: 16 }}
/>
```
### Custom Skeleton
```tsx
<RtlTextView
text="ุฌุงุฑู ุชุญู
ูู ุงูู
ุญุชูู..."
textStyle={{ fontSize: 16 }}
renderSkeleton={() => (
<View style={{ height: 80, backgroundColor: '#DDD', borderRadius: 8 }} />
)}
/>
```
### ๐ฅ Skeleton padding behavior (Recommended)
> Skeleton auto-matches **horizontal text padding**
> โ perfect alignment during loading
```tsx
<RtlTextView
text={longArabicText}
textStyle={{ fontSize: 16, marginHorizontal: 20 }}
/>
```
๐ก Skeleton width = `full width โ horizontal text margins`
### Full-width Skeleton (no margin)
```tsx
<RtlTextView
text={longArabicText}
textStyle={{ marginHorizontal: 20 }}
matchTextHorizontalPadding={false}
/>
```
### WebView custom props
```tsx
<RtlTextView
text="Arabic Text"
textStyle={{ fontSize: 16 }}
webviewProps={{ showsVerticalScrollIndicator: false }}
/>
```
## ๐ง Props
| Prop | Type | Default | Description |
| ---------------------------- | ------------------------------------------------ | -------------- | ------------------------------------------ |
| `text` | `string` | โ | Arabic text content |
| `textStyle` | `StyleProp<TextStyle> \| StyleProp<TextStyle>[]` | โ | Converted to CSS inside WebView |
| `numberOfLines` | `number` | `undefined` | Max visible lines using CSS clamp |
| `isDark` | `boolean` | `false` | Changes skeleton theme |
| `fontFamily` | `string` | from textStyle | Override web font |
| `renderSkeleton` | `() => React.ReactNode` | default | Custom skeleton UI |
| `skeletonHeight` | `number` | `100` | Height during loading |
| `skeletonProps` | `Record<string, any>` | `{}` | Props forwarded to Skeleton |
| `webviewProps` | `WebViewProps` | `{}` | Forwarded to WebView |
| `containerStyle` | `StyleProp<ViewStyle>` | `{}` | Outer wrapper styling |
| `matchTextHorizontalPadding` | `boolean` | `true` | Copy textโs horizontal padding to skeleton |
## ๐จ Styling Details
Extracted CSS from last-defined `textStyle` value:
* `color`, `backgroundColor`
* `fontSize`, `fontWeight`, `lineHeight`, `fontFamily`
* `textAlign`, RTL alignment enhancements
* Margins: `marginStart`, `marginEnd`, `marginHorizontal`, `marginVertical`
* WebView auto background transparency while loading
> ๐ก `marginStart` + `marginEnd` recommended for RTL UI
## ๐ง Why WebView?
React Native `<Text>` still suffers with:
โ Justified Arabic glyph shaping
โ Broken connections in RTL
โ Poor multi-line rendering
โ No CSS multi-line clamp
This component fixes all of the above โ๏ธ
## ๐ Troubleshooting
| Issue | Fix |
| ------------------------------ | ------------------------------------------- |
| Skeleton too skinny | remove `matchTextHorizontalPadding={false}` |
| Wrong first height | Font loader will update automatically |
| Background shows while loading | WebView background auto-hidden |
## ๐บ Roadmap
๐น Mixed LTR/RTL detection
๐น โRead moreโ collapsed text
๐น Full custom CSS styles
๐น Accessibility enhancements
PRs welcome โจ
## ๐ค Author
Built with โค๏ธ by **Ahmed Hegazy**
๐ง [ahmedmhegazy.eg@gmail.com](mailto:ahmedmhegazy.eg@gmail.com)
๐ GitHub: @ahmedhegazydev
## ๐ License
MIT โ Free for commercial & open-source use