react-native-highlight-text-view 0.1.7 → 0.1.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -47,11 +47,11 @@ export default function App() {
47
47
  | `color` | `string` | `#FFFF00` | Background highlight color (hex format) |
48
48
  | `textColor` | `string` | - | Text color (hex format) |
49
49
  | `textAlign` | `string` | `left` | Text alignment. Supports: `'left'`, `'center'`, `'right'`, `'justify'`, `'flex-start'`, `'flex-end'`, `'top'`, `'bottom'`, `'top-left'`, `'top-center'`, `'top-right'`, `'bottom-left'`, `'bottom-center'`, `'bottom-right'` |
50
- | `verticalAlign` | `'top' \| 'center' \| 'middle' \| 'bottom'` | - | Vertical alignment (iOS only). Alternative to using combined `textAlign` values |
50
+ | `verticalAlign` | `'top' \| 'center' \| 'middle' \| 'bottom'` | - | Vertical alignment (iOS only). Alternative to using combined `textAlign` values. **Note:** Android does not support vertical alignment and will use default vertical positioning. |
51
51
  | `fontFamily` | `string` | - | Font family name |
52
52
  | `fontSize` | `string` | `32` | Font size in points |
53
- | `lineHeight` | `string` | - | Line height override |
54
- | `highlightBorderRadius` | `string` | `4` | Border radius for the highlight background |
53
+ | `lineHeight` | `string` | `0` | Line height override (0 means use default line height) |
54
+ | `highlightBorderRadius` | `string` | `0` | Border radius for the highlight background |
55
55
  | `padding` | `string` | `4` | Padding around each character highlight (expands background outward) |
56
56
  | `paddingLeft` | `string` | - | Left padding for character highlight |
57
57
  | `paddingRight` | `string` | - | Right padding for character highlight |
@@ -87,6 +87,25 @@ export default function App() {
87
87
  />
88
88
  ```
89
89
 
90
+ **Example with touching backgrounds (tight line spacing):**
91
+ To make backgrounds touch vertically across multiple lines, combine `lineHeight` with `backgroundInset`:
92
+ ```jsx
93
+ <HighlightTextView
94
+ fontSize="32"
95
+ lineHeight="36" // Slightly larger than fontSize for tight spacing
96
+ paddingLeft="8"
97
+ paddingRight="8"
98
+ paddingTop="4"
99
+ paddingBottom="4"
100
+ backgroundInsetTop="14" // Large inset reduces background height
101
+ backgroundInsetBottom="14" // Creates room for lines to touch
102
+ highlightBorderRadius="4"
103
+ text="Multiple lines with touching backgrounds create smooth vertical flow"
104
+ />
105
+ ```
106
+
107
+ **Tip:** Set `lineHeight` to approximately `fontSize + 4` to `fontSize + 8`, then adjust `backgroundInsetTop` and `backgroundInsetBottom` until backgrounds touch smoothly.
108
+
90
109
  **Note:** Vertical alignment is currently supported on iOS only. On Android, text will use default vertical positioning.
91
110
 
92
111
 
@@ -154,6 +154,7 @@ class HighlightTextView : AppCompatEditText {
154
154
  private var backgroundInsetBottom: Float = 0f
155
155
  private var backgroundInsetLeft: Float = 0f
156
156
  private var backgroundInsetRight: Float = 0f
157
+ private var customLineHeight: Float = 0f
157
158
  private var isUpdatingText: Boolean = false
158
159
 
159
160
  var onTextChangeListener: ((String) -> Unit)? = null
@@ -261,6 +262,11 @@ class HighlightTextView : AppCompatEditText {
261
262
  backgroundInsetRight = inset
262
263
  applyCharacterBackgrounds()
263
264
  }
265
+
266
+ fun setCustomLineHeight(lineHeight: Float) {
267
+ customLineHeight = lineHeight
268
+ applyCharacterBackgrounds()
269
+ }
264
270
 
265
271
  fun setTextProp(text: String) {
266
272
  if (this.text?.toString() != text) {
@@ -277,6 +283,12 @@ class HighlightTextView : AppCompatEditText {
277
283
 
278
284
  val spannable = SpannableString(text)
279
285
 
286
+ // Apply line height if specified
287
+ if (customLineHeight > 0) {
288
+ val lineSpacingMultiplier = customLineHeight / textSize
289
+ setLineSpacing(0f, lineSpacingMultiplier)
290
+ }
291
+
280
292
  // Apply character-by-character for proper line wrapping
281
293
  for (i in text.indices) {
282
294
  val char = text[i]
@@ -147,8 +147,9 @@ class HighlightTextViewManager : SimpleViewManager<HighlightTextView>(),
147
147
 
148
148
  @ReactProp(name = "lineHeight")
149
149
  override fun setLineHeight(view: HighlightTextView?, value: String?) {
150
- // Line height is handled differently on Android - this is a placeholder
151
- // Android EditText doesn't directly support line height like iOS
150
+ value?.toFloatOrNull()?.let { lineHeight ->
151
+ view?.setCustomLineHeight(lineHeight)
152
+ }
152
153
  }
153
154
 
154
155
  @ReactProp(name = "highlightBorderRadius")
@@ -476,20 +476,17 @@ Class<RCTComponentViewProtocol> HighlightTextViewCls(void)
476
476
  NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
477
477
  paragraphStyle.alignment = _textView.textAlignment;
478
478
 
479
- // Apply line height if specified
479
+ // Apply line height if specified (allows tight line spacing for touching backgrounds)
480
480
  if (_lineHeight > 0) {
481
- CGFloat fontSize = _textView.font.pointSize;
481
+ // Always use absolute line height for precise control
482
+ paragraphStyle.minimumLineHeight = _lineHeight;
483
+ paragraphStyle.maximumLineHeight = _lineHeight;
484
+ paragraphStyle.lineHeightMultiple = 0;
482
485
 
483
- // If lineHeight is smaller than fontSize, use lineHeightMultiple for better centering
484
- if (_lineHeight < fontSize) {
485
- paragraphStyle.lineHeightMultiple = _lineHeight / fontSize;
486
- paragraphStyle.minimumLineHeight = 0;
487
- paragraphStyle.maximumLineHeight = 0;
488
- } else {
489
- // For larger line heights, use absolute values
490
- paragraphStyle.minimumLineHeight = _lineHeight;
491
- paragraphStyle.maximumLineHeight = _lineHeight;
492
- paragraphStyle.lineHeightMultiple = 0;
486
+ // For tight line spacing, reduce line spacing to bring lines closer
487
+ if (_lineHeight <= _textView.font.pointSize * 1.2) {
488
+ // Negative line spacing brings lines closer together
489
+ paragraphStyle.lineSpacing = -(_textView.font.pointSize * 0.1);
493
490
  }
494
491
  }
495
492
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-highlight-text-view",
3
- "version": "0.1.7",
3
+ "version": "0.1.9",
4
4
  "description": "A native text input for React Native that supports inline text highlighting",
5
5
  "main": "./lib/module/index.js",
6
6
  "types": "./lib/typescript/src/index.d.ts",