react-native-highlight-text-view 0.1.6 → 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 +47 -1
- package/android/src/main/java/com/highlighttext/HighlightTextView.kt +61 -8
- package/android/src/main/java/com/highlighttext/HighlightTextViewManager.kt +42 -0
- package/ios/HighlightTextView.h +4 -0
- package/ios/HighlightTextView.mm +69 -14
- package/lib/module/HighlightTextViewNativeComponent.ts +8 -0
- package/lib/typescript/src/HighlightTextViewNativeComponent.d.ts +8 -0
- package/lib/typescript/src/HighlightTextViewNativeComponent.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/HighlightTextViewNativeComponent.ts +8 -0
package/README.md
CHANGED
|
@@ -50,15 +50,61 @@ export default function App() {
|
|
|
50
50
|
| `verticalAlign` | `'top' \| 'center' \| 'middle' \| 'bottom'` | - | Vertical alignment (iOS only). Alternative to using combined `textAlign` values |
|
|
51
51
|
| `fontFamily` | `string` | - | Font family name |
|
|
52
52
|
| `fontSize` | `string` | `32` | Font size in points |
|
|
53
|
-
| `
|
|
53
|
+
| `lineHeight` | `string` | - | Line height override |
|
|
54
|
+
| `highlightBorderRadius` | `string` | `4` | Border radius for the highlight background |
|
|
55
|
+
| `padding` | `string` | `4` | Padding around each character highlight (expands background outward) |
|
|
54
56
|
| `paddingLeft` | `string` | - | Left padding for character highlight |
|
|
55
57
|
| `paddingRight` | `string` | - | Right padding for character highlight |
|
|
56
58
|
| `paddingTop` | `string` | - | Top padding for character highlight |
|
|
57
59
|
| `paddingBottom` | `string` | - | Bottom padding for character highlight |
|
|
60
|
+
| `backgroundInsetTop` | `string` | `0` | Shrinks background from top (useful for fonts with large vertical metrics) |
|
|
61
|
+
| `backgroundInsetBottom` | `string` | `0` | Shrinks background from bottom (useful for fonts with large vertical metrics) |
|
|
62
|
+
| `backgroundInsetLeft` | `string` | `0` | Shrinks background from left |
|
|
63
|
+
| `backgroundInsetRight` | `string` | `0` | Shrinks background from right |
|
|
58
64
|
| `text` | `string` | - | Controlled text value |
|
|
59
65
|
| `isEditable` | `boolean` | `true` | Whether the text is editable |
|
|
60
66
|
| `onChange` | `(event: { nativeEvent: { text: string } }) => void` | - | Callback fired when text changes |
|
|
61
67
|
|
|
68
|
+
### Understanding Padding vs Background Insets
|
|
69
|
+
|
|
70
|
+
- **Padding props** (`paddingTop`, `paddingBottom`, etc.): Expand the background **outward** from the text, adding extra colored area around glyphs.
|
|
71
|
+
- **Background inset props** (`backgroundInsetTop`, `backgroundInsetBottom`, etc.): Shrink the background **inward** from the font's line box, creating tighter wrapping around actual glyphs.
|
|
72
|
+
|
|
73
|
+
**Use case for background insets:** Some fonts (like Eczar, Georgia, etc.) have large built-in vertical metrics (ascender/descender), making highlights appear too tall. Use `backgroundInsetTop` and `backgroundInsetBottom` to create a tighter fit around the visible glyphs.
|
|
74
|
+
|
|
75
|
+
**Example with large-metric font:**
|
|
76
|
+
```jsx
|
|
77
|
+
<HighlightTextView
|
|
78
|
+
fontFamily="Eczar"
|
|
79
|
+
fontSize="32"
|
|
80
|
+
paddingLeft="8"
|
|
81
|
+
paddingRight="8"
|
|
82
|
+
paddingTop="4"
|
|
83
|
+
paddingBottom="4"
|
|
84
|
+
backgroundInsetTop="6"
|
|
85
|
+
backgroundInsetBottom="6"
|
|
86
|
+
text="Tight Background"
|
|
87
|
+
/>
|
|
88
|
+
```
|
|
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.
|
|
62
108
|
|
|
63
109
|
**Note:** Vertical alignment is currently supported on iOS only. On Android, text will use default vertical positioning.
|
|
64
110
|
|
|
@@ -22,6 +22,10 @@ class RoundedBackgroundSpan(
|
|
|
22
22
|
private val paddingRight: Float,
|
|
23
23
|
private val paddingTop: Float,
|
|
24
24
|
private val paddingBottom: Float,
|
|
25
|
+
private val backgroundInsetTop: Float,
|
|
26
|
+
private val backgroundInsetBottom: Float,
|
|
27
|
+
private val backgroundInsetLeft: Float,
|
|
28
|
+
private val backgroundInsetRight: Float,
|
|
25
29
|
private val cornerRadius: Float,
|
|
26
30
|
private val isFirstInGroup: Boolean = false,
|
|
27
31
|
private val isLastInGroup: Boolean = false
|
|
@@ -61,7 +65,7 @@ class RoundedBackgroundSpan(
|
|
|
61
65
|
|
|
62
66
|
val width = paint.measureText(text, start, end)
|
|
63
67
|
|
|
64
|
-
// Use font metrics for consistent height
|
|
68
|
+
// Use font metrics for consistent height (matches iOS behavior)
|
|
65
69
|
val fontMetrics = paint.fontMetrics
|
|
66
70
|
val textHeight = fontMetrics.descent - fontMetrics.ascent
|
|
67
71
|
val textTop = y + fontMetrics.ascent
|
|
@@ -70,17 +74,21 @@ class RoundedBackgroundSpan(
|
|
|
70
74
|
val leftPad = if (isFirstInGroup) paddingLeft else 0f
|
|
71
75
|
val rightPad = if (isLastInGroup) paddingRight else 0f
|
|
72
76
|
|
|
73
|
-
// Extend background
|
|
74
|
-
val overlapExtension =
|
|
77
|
+
// Extend background to overlap and eliminate gaps between characters
|
|
78
|
+
val overlapExtension = 2f
|
|
75
79
|
val leftExtension = if (!isFirstInGroup) overlapExtension else 0f
|
|
76
80
|
val rightExtension = if (!isLastInGroup) overlapExtension else 0f
|
|
77
81
|
|
|
78
|
-
//
|
|
82
|
+
// Apply background insets first (shrinks from line box)
|
|
83
|
+
val insetTop = textTop + backgroundInsetTop
|
|
84
|
+
val insetHeight = textHeight - (backgroundInsetTop + backgroundInsetBottom)
|
|
85
|
+
|
|
86
|
+
// Calculate proper bounds with insets then padding
|
|
79
87
|
val rect = RectF(
|
|
80
|
-
x - leftExtension,
|
|
81
|
-
|
|
82
|
-
x + width + leftPad + rightPad + rightExtension,
|
|
83
|
-
|
|
88
|
+
x - leftExtension + backgroundInsetLeft,
|
|
89
|
+
insetTop - paddingTop,
|
|
90
|
+
x + width + leftPad + rightPad + rightExtension - backgroundInsetRight,
|
|
91
|
+
insetTop + insetHeight + paddingBottom
|
|
84
92
|
)
|
|
85
93
|
|
|
86
94
|
// Draw background with selective corner rounding
|
|
@@ -142,6 +150,11 @@ class HighlightTextView : AppCompatEditText {
|
|
|
142
150
|
private var charPaddingRight: Float = 8f
|
|
143
151
|
private var charPaddingTop: Float = 4f
|
|
144
152
|
private var charPaddingBottom: Float = 4f
|
|
153
|
+
private var backgroundInsetTop: Float = 0f
|
|
154
|
+
private var backgroundInsetBottom: Float = 0f
|
|
155
|
+
private var backgroundInsetLeft: Float = 0f
|
|
156
|
+
private var backgroundInsetRight: Float = 0f
|
|
157
|
+
private var customLineHeight: Float = 0f
|
|
145
158
|
private var isUpdatingText: Boolean = false
|
|
146
159
|
|
|
147
160
|
var onTextChangeListener: ((String) -> Unit)? = null
|
|
@@ -224,6 +237,36 @@ class HighlightTextView : AppCompatEditText {
|
|
|
224
237
|
charPaddingBottom = padding
|
|
225
238
|
applyCharacterBackgrounds()
|
|
226
239
|
}
|
|
240
|
+
|
|
241
|
+
fun setCornerRadius(radius: Float) {
|
|
242
|
+
cornerRadius = radius
|
|
243
|
+
applyCharacterBackgrounds()
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
fun setBackgroundInsetTop(inset: Float) {
|
|
247
|
+
backgroundInsetTop = inset
|
|
248
|
+
applyCharacterBackgrounds()
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
fun setBackgroundInsetBottom(inset: Float) {
|
|
252
|
+
backgroundInsetBottom = inset
|
|
253
|
+
applyCharacterBackgrounds()
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
fun setBackgroundInsetLeft(inset: Float) {
|
|
257
|
+
backgroundInsetLeft = inset
|
|
258
|
+
applyCharacterBackgrounds()
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
fun setBackgroundInsetRight(inset: Float) {
|
|
262
|
+
backgroundInsetRight = inset
|
|
263
|
+
applyCharacterBackgrounds()
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
fun setCustomLineHeight(lineHeight: Float) {
|
|
267
|
+
customLineHeight = lineHeight
|
|
268
|
+
applyCharacterBackgrounds()
|
|
269
|
+
}
|
|
227
270
|
|
|
228
271
|
fun setTextProp(text: String) {
|
|
229
272
|
if (this.text?.toString() != text) {
|
|
@@ -240,6 +283,12 @@ class HighlightTextView : AppCompatEditText {
|
|
|
240
283
|
|
|
241
284
|
val spannable = SpannableString(text)
|
|
242
285
|
|
|
286
|
+
// Apply line height if specified
|
|
287
|
+
if (customLineHeight > 0) {
|
|
288
|
+
val lineSpacingMultiplier = customLineHeight / textSize
|
|
289
|
+
setLineSpacing(0f, lineSpacingMultiplier)
|
|
290
|
+
}
|
|
291
|
+
|
|
243
292
|
// Apply character-by-character for proper line wrapping
|
|
244
293
|
for (i in text.indices) {
|
|
245
294
|
val char = text[i]
|
|
@@ -268,6 +317,10 @@ class HighlightTextView : AppCompatEditText {
|
|
|
268
317
|
charPaddingRight,
|
|
269
318
|
charPaddingTop,
|
|
270
319
|
charPaddingBottom,
|
|
320
|
+
backgroundInsetTop,
|
|
321
|
+
backgroundInsetBottom,
|
|
322
|
+
backgroundInsetLeft,
|
|
323
|
+
backgroundInsetRight,
|
|
271
324
|
cornerRadius,
|
|
272
325
|
isFirst,
|
|
273
326
|
isLast
|
|
@@ -145,6 +145,48 @@ class HighlightTextViewManager : SimpleViewManager<HighlightTextView>(),
|
|
|
145
145
|
}
|
|
146
146
|
}
|
|
147
147
|
|
|
148
|
+
@ReactProp(name = "lineHeight")
|
|
149
|
+
override fun setLineHeight(view: HighlightTextView?, value: String?) {
|
|
150
|
+
value?.toFloatOrNull()?.let { lineHeight ->
|
|
151
|
+
view?.setCustomLineHeight(lineHeight)
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
@ReactProp(name = "highlightBorderRadius")
|
|
156
|
+
override fun setHighlightBorderRadius(view: HighlightTextView?, value: String?) {
|
|
157
|
+
value?.toFloatOrNull()?.let { radius ->
|
|
158
|
+
view?.setCornerRadius(radius)
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
@ReactProp(name = "backgroundInsetTop")
|
|
163
|
+
override fun setBackgroundInsetTop(view: HighlightTextView?, value: String?) {
|
|
164
|
+
value?.toFloatOrNull()?.let { inset ->
|
|
165
|
+
view?.setBackgroundInsetTop(inset)
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
@ReactProp(name = "backgroundInsetBottom")
|
|
170
|
+
override fun setBackgroundInsetBottom(view: HighlightTextView?, value: String?) {
|
|
171
|
+
value?.toFloatOrNull()?.let { inset ->
|
|
172
|
+
view?.setBackgroundInsetBottom(inset)
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
@ReactProp(name = "backgroundInsetLeft")
|
|
177
|
+
override fun setBackgroundInsetLeft(view: HighlightTextView?, value: String?) {
|
|
178
|
+
value?.toFloatOrNull()?.let { inset ->
|
|
179
|
+
view?.setBackgroundInsetLeft(inset)
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
@ReactProp(name = "backgroundInsetRight")
|
|
184
|
+
override fun setBackgroundInsetRight(view: HighlightTextView?, value: String?) {
|
|
185
|
+
value?.toFloatOrNull()?.let { inset ->
|
|
186
|
+
view?.setBackgroundInsetRight(inset)
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
148
190
|
@ReactProp(name = "text")
|
|
149
191
|
override fun setText(view: HighlightTextView?, value: String?) {
|
|
150
192
|
view?.setTextProp(value ?: "")
|
package/ios/HighlightTextView.h
CHANGED
|
@@ -15,6 +15,10 @@ NS_ASSUME_NONNULL_BEGIN
|
|
|
15
15
|
@property (nonatomic, assign) CGFloat paddingBottom;
|
|
16
16
|
@property (nonatomic, assign) CGFloat cornerRadius;
|
|
17
17
|
@property (nonatomic, assign) CGFloat highlightBorderRadius;
|
|
18
|
+
@property (nonatomic, assign) CGFloat backgroundInsetTop;
|
|
19
|
+
@property (nonatomic, assign) CGFloat backgroundInsetBottom;
|
|
20
|
+
@property (nonatomic, assign) CGFloat backgroundInsetLeft;
|
|
21
|
+
@property (nonatomic, assign) CGFloat backgroundInsetRight;
|
|
18
22
|
@end
|
|
19
23
|
|
|
20
24
|
@interface HighlightTextView : RCTViewComponentView
|
package/ios/HighlightTextView.mm
CHANGED
|
@@ -11,7 +11,7 @@ using namespace facebook::react;
|
|
|
11
11
|
|
|
12
12
|
@implementation RoundedBackgroundLayoutManager
|
|
13
13
|
|
|
14
|
-
@synthesize backgroundColor, padding, paddingLeft, paddingRight, paddingTop, paddingBottom, cornerRadius, highlightBorderRadius;
|
|
14
|
+
@synthesize backgroundColor, padding, paddingLeft, paddingRight, paddingTop, paddingBottom, cornerRadius, highlightBorderRadius, backgroundInsetTop, backgroundInsetBottom, backgroundInsetLeft, backgroundInsetRight;
|
|
15
15
|
|
|
16
16
|
- (void)drawBackgroundForGlyphRange:(NSRange)glyphsToShow atPoint:(CGPoint)origin {
|
|
17
17
|
NSTextStorage *textStorage = self.textStorage;
|
|
@@ -41,7 +41,13 @@ using namespace facebook::react;
|
|
|
41
41
|
if (boundingRect.size.width > 1.0 && boundingRect.size.height > 1.0 &&
|
|
42
42
|
boundingRect.size.width < (textContainer.size.width * 0.8)) {
|
|
43
43
|
|
|
44
|
-
// Apply
|
|
44
|
+
// Apply background insets first (shrinks from line box)
|
|
45
|
+
boundingRect.origin.y += self.backgroundInsetTop;
|
|
46
|
+
boundingRect.size.height -= (self.backgroundInsetTop + self.backgroundInsetBottom);
|
|
47
|
+
boundingRect.origin.x += self.backgroundInsetLeft;
|
|
48
|
+
boundingRect.size.width -= (self.backgroundInsetLeft + self.backgroundInsetRight);
|
|
49
|
+
|
|
50
|
+
// Then apply padding (expands outward)
|
|
45
51
|
boundingRect.origin.x += origin.x - self.paddingLeft;
|
|
46
52
|
boundingRect.origin.y += origin.y - self.paddingTop;
|
|
47
53
|
boundingRect.size.width += self.paddingLeft + self.paddingRight;
|
|
@@ -78,6 +84,10 @@ using namespace facebook::react;
|
|
|
78
84
|
CGFloat _paddingBottom;
|
|
79
85
|
CGFloat _cornerRadius;
|
|
80
86
|
CGFloat _highlightBorderRadius;
|
|
87
|
+
CGFloat _backgroundInsetTop;
|
|
88
|
+
CGFloat _backgroundInsetBottom;
|
|
89
|
+
CGFloat _backgroundInsetLeft;
|
|
90
|
+
CGFloat _backgroundInsetRight;
|
|
81
91
|
CGFloat _lineHeight;
|
|
82
92
|
BOOL _isUpdatingText;
|
|
83
93
|
NSString * _currentVerticalAlignment;
|
|
@@ -103,6 +113,10 @@ using namespace facebook::react;
|
|
|
103
113
|
_paddingBottom = 4.0;
|
|
104
114
|
_cornerRadius = 4.0;
|
|
105
115
|
_highlightBorderRadius = 0.0;
|
|
116
|
+
_backgroundInsetTop = 0.0;
|
|
117
|
+
_backgroundInsetBottom = 0.0;
|
|
118
|
+
_backgroundInsetLeft = 0.0;
|
|
119
|
+
_backgroundInsetRight = 0.0;
|
|
106
120
|
_lineHeight = 0.0; // 0 means use default line height
|
|
107
121
|
_currentVerticalAlignment = nil;
|
|
108
122
|
_currentHorizontalAlignment = NSTextAlignmentCenter;
|
|
@@ -118,6 +132,10 @@ using namespace facebook::react;
|
|
|
118
132
|
_layoutManager.paddingBottom = _paddingBottom;
|
|
119
133
|
_layoutManager.cornerRadius = _cornerRadius;
|
|
120
134
|
_layoutManager.highlightBorderRadius = _highlightBorderRadius;
|
|
135
|
+
_layoutManager.backgroundInsetTop = _backgroundInsetTop;
|
|
136
|
+
_layoutManager.backgroundInsetBottom = _backgroundInsetBottom;
|
|
137
|
+
_layoutManager.backgroundInsetLeft = _backgroundInsetLeft;
|
|
138
|
+
_layoutManager.backgroundInsetRight = _backgroundInsetRight;
|
|
121
139
|
|
|
122
140
|
[textStorage addLayoutManager:_layoutManager];
|
|
123
141
|
|
|
@@ -339,6 +357,46 @@ using namespace facebook::react;
|
|
|
339
357
|
}
|
|
340
358
|
}
|
|
341
359
|
|
|
360
|
+
if (oldViewProps.backgroundInsetTop != newViewProps.backgroundInsetTop) {
|
|
361
|
+
NSString *insetStr = [[NSString alloc] initWithUTF8String: newViewProps.backgroundInsetTop.c_str()];
|
|
362
|
+
CGFloat inset = [insetStr floatValue];
|
|
363
|
+
if (inset >= 0) {
|
|
364
|
+
_backgroundInsetTop = inset;
|
|
365
|
+
_layoutManager.backgroundInsetTop = _backgroundInsetTop;
|
|
366
|
+
[self applyCharacterBackgrounds];
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
if (oldViewProps.backgroundInsetBottom != newViewProps.backgroundInsetBottom) {
|
|
371
|
+
NSString *insetStr = [[NSString alloc] initWithUTF8String: newViewProps.backgroundInsetBottom.c_str()];
|
|
372
|
+
CGFloat inset = [insetStr floatValue];
|
|
373
|
+
if (inset >= 0) {
|
|
374
|
+
_backgroundInsetBottom = inset;
|
|
375
|
+
_layoutManager.backgroundInsetBottom = _backgroundInsetBottom;
|
|
376
|
+
[self applyCharacterBackgrounds];
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
if (oldViewProps.backgroundInsetLeft != newViewProps.backgroundInsetLeft) {
|
|
381
|
+
NSString *insetStr = [[NSString alloc] initWithUTF8String: newViewProps.backgroundInsetLeft.c_str()];
|
|
382
|
+
CGFloat inset = [insetStr floatValue];
|
|
383
|
+
if (inset >= 0) {
|
|
384
|
+
_backgroundInsetLeft = inset;
|
|
385
|
+
_layoutManager.backgroundInsetLeft = _backgroundInsetLeft;
|
|
386
|
+
[self applyCharacterBackgrounds];
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
if (oldViewProps.backgroundInsetRight != newViewProps.backgroundInsetRight) {
|
|
391
|
+
NSString *insetStr = [[NSString alloc] initWithUTF8String: newViewProps.backgroundInsetRight.c_str()];
|
|
392
|
+
CGFloat inset = [insetStr floatValue];
|
|
393
|
+
if (inset >= 0) {
|
|
394
|
+
_backgroundInsetRight = inset;
|
|
395
|
+
_layoutManager.backgroundInsetRight = _backgroundInsetRight;
|
|
396
|
+
[self applyCharacterBackgrounds];
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
|
|
342
400
|
if (oldViewProps.text != newViewProps.text) {
|
|
343
401
|
NSString *text = [[NSString alloc] initWithUTF8String: newViewProps.text.c_str()];
|
|
344
402
|
if (![_textView.text isEqualToString:text]) {
|
|
@@ -418,20 +476,17 @@ Class<RCTComponentViewProtocol> HighlightTextViewCls(void)
|
|
|
418
476
|
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
|
|
419
477
|
paragraphStyle.alignment = _textView.textAlignment;
|
|
420
478
|
|
|
421
|
-
// Apply line height if specified
|
|
479
|
+
// Apply line height if specified (allows tight line spacing for touching backgrounds)
|
|
422
480
|
if (_lineHeight > 0) {
|
|
423
|
-
|
|
481
|
+
// Always use absolute line height for precise control
|
|
482
|
+
paragraphStyle.minimumLineHeight = _lineHeight;
|
|
483
|
+
paragraphStyle.maximumLineHeight = _lineHeight;
|
|
484
|
+
paragraphStyle.lineHeightMultiple = 0;
|
|
424
485
|
|
|
425
|
-
//
|
|
426
|
-
if (_lineHeight
|
|
427
|
-
|
|
428
|
-
paragraphStyle.
|
|
429
|
-
paragraphStyle.maximumLineHeight = 0;
|
|
430
|
-
} else {
|
|
431
|
-
// For larger line heights, use absolute values
|
|
432
|
-
paragraphStyle.minimumLineHeight = _lineHeight;
|
|
433
|
-
paragraphStyle.maximumLineHeight = _lineHeight;
|
|
434
|
-
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);
|
|
435
490
|
}
|
|
436
491
|
}
|
|
437
492
|
|
|
@@ -53,6 +53,14 @@ export interface HighlightTextViewProps extends ViewProps {
|
|
|
53
53
|
paddingRight?: string;
|
|
54
54
|
paddingTop?: string;
|
|
55
55
|
paddingBottom?: string;
|
|
56
|
+
/** Reduces background height from the top (shrinks inward from font line box) */
|
|
57
|
+
backgroundInsetTop?: string;
|
|
58
|
+
/** Reduces background height from the bottom (shrinks inward from font line box) */
|
|
59
|
+
backgroundInsetBottom?: string;
|
|
60
|
+
/** Reduces background width from the left (shrinks inward from glyph bounds) */
|
|
61
|
+
backgroundInsetLeft?: string;
|
|
62
|
+
/** Reduces background width from the right (shrinks inward from glyph bounds) */
|
|
63
|
+
backgroundInsetRight?: string;
|
|
56
64
|
text?: string;
|
|
57
65
|
isEditable?: boolean;
|
|
58
66
|
onChange?: BubblingEventHandler<OnChangeEventData>;
|
|
@@ -35,6 +35,14 @@ export interface HighlightTextViewProps extends ViewProps {
|
|
|
35
35
|
paddingRight?: string;
|
|
36
36
|
paddingTop?: string;
|
|
37
37
|
paddingBottom?: string;
|
|
38
|
+
/** Reduces background height from the top (shrinks inward from font line box) */
|
|
39
|
+
backgroundInsetTop?: string;
|
|
40
|
+
/** Reduces background height from the bottom (shrinks inward from font line box) */
|
|
41
|
+
backgroundInsetBottom?: string;
|
|
42
|
+
/** Reduces background width from the left (shrinks inward from glyph bounds) */
|
|
43
|
+
backgroundInsetLeft?: string;
|
|
44
|
+
/** Reduces background width from the right (shrinks inward from glyph bounds) */
|
|
45
|
+
backgroundInsetRight?: string;
|
|
38
46
|
text?: string;
|
|
39
47
|
isEditable?: boolean;
|
|
40
48
|
onChange?: BubblingEventHandler<OnChangeEventData>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HighlightTextViewNativeComponent.d.ts","sourceRoot":"","sources":["../../../src/HighlightTextViewNativeComponent.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AAEtF,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,MAAM,aAAa,GACrB,MAAM,GACN,QAAQ,GACR,OAAO,GACP,SAAS,GACT,YAAY,GACZ,UAAU,GACV,KAAK,GACL,QAAQ,GACR,UAAU,GACV,YAAY,GACZ,WAAW,GACX,aAAa,GACb,eAAe,GACf,cAAc,CAAC;AAEnB,MAAM,WAAW,sBAAuB,SAAQ,SAAS;IACvD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAC/B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,QAAQ,CAAC,EAAE,oBAAoB,CAAC,iBAAiB,CAAC,CAAC;CACpD;;AAED,wBAEE"}
|
|
1
|
+
{"version":3,"file":"HighlightTextViewNativeComponent.d.ts","sourceRoot":"","sources":["../../../src/HighlightTextViewNativeComponent.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AAEtF,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,MAAM,aAAa,GACrB,MAAM,GACN,QAAQ,GACR,OAAO,GACP,SAAS,GACT,YAAY,GACZ,UAAU,GACV,KAAK,GACL,QAAQ,GACR,UAAU,GACV,YAAY,GACZ,WAAW,GACX,aAAa,GACb,eAAe,GACf,cAAc,CAAC;AAEnB,MAAM,WAAW,sBAAuB,SAAQ,SAAS;IACvD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAC/B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,iFAAiF;IACjF,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,oFAAoF;IACpF,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAC/B,gFAAgF;IAChF,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,iFAAiF;IACjF,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,QAAQ,CAAC,EAAE,oBAAoB,CAAC,iBAAiB,CAAC,CAAC;CACpD;;AAED,wBAEE"}
|
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",
|
|
@@ -53,6 +53,14 @@ export interface HighlightTextViewProps extends ViewProps {
|
|
|
53
53
|
paddingRight?: string;
|
|
54
54
|
paddingTop?: string;
|
|
55
55
|
paddingBottom?: string;
|
|
56
|
+
/** Reduces background height from the top (shrinks inward from font line box) */
|
|
57
|
+
backgroundInsetTop?: string;
|
|
58
|
+
/** Reduces background height from the bottom (shrinks inward from font line box) */
|
|
59
|
+
backgroundInsetBottom?: string;
|
|
60
|
+
/** Reduces background width from the left (shrinks inward from glyph bounds) */
|
|
61
|
+
backgroundInsetLeft?: string;
|
|
62
|
+
/** Reduces background width from the right (shrinks inward from glyph bounds) */
|
|
63
|
+
backgroundInsetRight?: string;
|
|
56
64
|
text?: string;
|
|
57
65
|
isEditable?: boolean;
|
|
58
66
|
onChange?: BubblingEventHandler<OnChangeEventData>;
|