react-native-advanced-text 0.1.41 → 0.1.43
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.
|
@@ -259,8 +259,6 @@ class AdvancedTextView : TextView {
|
|
|
259
259
|
private fun drawHighlightedWordBackgrounds(canvas: Canvas) {
|
|
260
260
|
val currentLayout = layout ?: return
|
|
261
261
|
val density = resources.displayMetrics.density
|
|
262
|
-
val horizontalPadding = 6f * density
|
|
263
|
-
val verticalPadding = 2f * density
|
|
264
262
|
val originalColor = paint.color
|
|
265
263
|
|
|
266
264
|
highlightedWords.forEach { highlightedWord ->
|
|
@@ -282,14 +280,19 @@ class AdvancedTextView : TextView {
|
|
|
282
280
|
if (lineStartOffset >= lineEndOffset) continue
|
|
283
281
|
|
|
284
282
|
val left = currentLayout.getPrimaryHorizontal(lineStartOffset)
|
|
285
|
-
val
|
|
283
|
+
val isLastWordOnLine = lineEndOffset >= currentLayout.getLineEnd(line)
|
|
284
|
+
val right = if (isLastWordOnLine) {
|
|
285
|
+
currentLayout.getLineRight(line)
|
|
286
|
+
} else {
|
|
287
|
+
currentLayout.getPrimaryHorizontal(lineEndOffset)
|
|
288
|
+
}
|
|
286
289
|
val top = currentLayout.getLineTop(line).toFloat()
|
|
287
290
|
val bottom = currentLayout.getLineBottom(line).toFloat()
|
|
288
291
|
val rect = RectF(
|
|
289
|
-
totalPaddingLeft + left
|
|
290
|
-
totalPaddingTop + top
|
|
291
|
-
totalPaddingLeft + right
|
|
292
|
-
totalPaddingTop + bottom
|
|
292
|
+
totalPaddingLeft + left,
|
|
293
|
+
totalPaddingTop + top,
|
|
294
|
+
totalPaddingLeft + right,
|
|
295
|
+
totalPaddingTop + bottom
|
|
293
296
|
)
|
|
294
297
|
val radius = highlightedWord.borderRadius * density
|
|
295
298
|
canvas.drawRoundRect(rect, radius, radius, paint)
|
|
@@ -301,7 +304,7 @@ class AdvancedTextView : TextView {
|
|
|
301
304
|
val wordPos = wordPositions.find { it.index == indicatorWordIndex }
|
|
302
305
|
if (wordPos != null) {
|
|
303
306
|
val start = wordPos.start
|
|
304
|
-
val end = wordPos.
|
|
307
|
+
val end = wordPos.end.coerceAtMost(currentText.length)
|
|
305
308
|
|
|
306
309
|
if (start < end) {
|
|
307
310
|
val startLine = currentLayout.getLineForOffset(start)
|
|
@@ -316,14 +319,19 @@ class AdvancedTextView : TextView {
|
|
|
316
319
|
if (lineStartOffset >= lineEndOffset) continue
|
|
317
320
|
|
|
318
321
|
val left = currentLayout.getPrimaryHorizontal(lineStartOffset)
|
|
319
|
-
val
|
|
322
|
+
val isLastWordOnLine = lineEndOffset >= currentLayout.getLineEnd(line)
|
|
323
|
+
val right = if (isLastWordOnLine) {
|
|
324
|
+
currentLayout.getLineRight(line)
|
|
325
|
+
} else {
|
|
326
|
+
currentLayout.getPrimaryHorizontal(lineEndOffset)
|
|
327
|
+
}
|
|
320
328
|
val top = currentLayout.getLineTop(line).toFloat()
|
|
321
329
|
val bottom = currentLayout.getLineBottom(line).toFloat()
|
|
322
330
|
val rect = RectF(
|
|
323
|
-
totalPaddingLeft + left
|
|
324
|
-
totalPaddingTop + top
|
|
325
|
-
totalPaddingLeft + right
|
|
326
|
-
totalPaddingTop + bottom
|
|
331
|
+
totalPaddingLeft + left,
|
|
332
|
+
totalPaddingTop + top,
|
|
333
|
+
totalPaddingLeft + right,
|
|
334
|
+
totalPaddingTop + bottom
|
|
327
335
|
)
|
|
328
336
|
canvas.drawRoundRect(rect, 0f, 0f, paint)
|
|
329
337
|
}
|
package/ios/AdvancedTextView.mm
CHANGED
|
@@ -513,7 +513,6 @@ using namespace facebook::react;
|
|
|
513
513
|
}];
|
|
514
514
|
}
|
|
515
515
|
|
|
516
|
-
// Draw indicator for indicatorWordIndex
|
|
517
516
|
if (_indicatorWordIndex >= 0 && _indicatorColor) {
|
|
518
517
|
for (NSDictionary *wordInfo in _wordRanges) {
|
|
519
518
|
NSNumber *index = wordInfo[@"index"];
|
|
@@ -534,7 +533,8 @@ using namespace facebook::react;
|
|
|
534
533
|
withinSelectedGlyphRange:NSMakeRange(NSNotFound, 0)
|
|
535
534
|
inTextContainer:textContainer
|
|
536
535
|
usingBlock:^(CGRect enclosingRect, BOOL *stop) {
|
|
537
|
-
|
|
536
|
+
// Changed lines here to remove padding and align exactly to glyph rect
|
|
537
|
+
CGRect adjustedRect = enclosingRect;
|
|
538
538
|
adjustedRect.origin.x += textView.textContainerInset.left;
|
|
539
539
|
adjustedRect.origin.y += textView.textContainerInset.top;
|
|
540
540
|
|
package/package.json
CHANGED