react-native-highlight-text-view 0.1.7 → 0.1.8
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
|
@@ -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
|
-
|
|
151
|
-
|
|
150
|
+
value?.toFloatOrNull()?.let { lineHeight ->
|
|
151
|
+
view?.setCustomLineHeight(lineHeight)
|
|
152
|
+
}
|
|
152
153
|
}
|
|
153
154
|
|
|
154
155
|
@ReactProp(name = "highlightBorderRadius")
|
package/ios/HighlightTextView.mm
CHANGED
|
@@ -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
|
-
|
|
481
|
+
// Always use absolute line height for precise control
|
|
482
|
+
paragraphStyle.minimumLineHeight = _lineHeight;
|
|
483
|
+
paragraphStyle.maximumLineHeight = _lineHeight;
|
|
484
|
+
paragraphStyle.lineHeightMultiple = 0;
|
|
482
485
|
|
|
483
|
-
//
|
|
484
|
-
if (_lineHeight
|
|
485
|
-
|
|
486
|
-
paragraphStyle.
|
|
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.
|
|
3
|
+
"version": "0.1.8",
|
|
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",
|