react-native-highlight-text-view 0.1.17 → 0.1.18

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.
@@ -315,12 +315,38 @@ class HighlightTextView : AppCompatEditText {
315
315
  Typeface.create(baseTypeface, style)
316
316
  }
317
317
 
318
+ // Save current text to force complete rebuild
319
+ val currentText = text?.toString() ?: ""
320
+ val currentSelection = selectionStart
321
+
318
322
  this.typeface = typeface
319
323
 
320
- // Force complete layout recalculation with new font metrics
321
- // This ensures background highlights recalculate with new ascender/descender values
324
+ // Force complete text rebuild with new font metrics
325
+ // This is crucial for fonts with different ascender/descender values like Eczar
322
326
  post {
327
+ // Clear text first to force layout recalculation
328
+ isUpdatingText = true
329
+ setText("")
330
+
331
+ // Force measure and layout with empty text
332
+ measure(
333
+ MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY),
334
+ MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY)
335
+ )
336
+
337
+ // Restore text - this triggers complete rebuild with new font metrics
338
+ setText(currentText)
339
+
340
+ // Reapply all character backgrounds with new font metrics
323
341
  applyCharacterBackgrounds()
342
+
343
+ // Restore cursor position
344
+ val safePosition = currentSelection.coerceIn(0, currentText.length)
345
+ setSelection(safePosition)
346
+
347
+ isUpdatingText = false
348
+
349
+ // Force complete layout recalculation
324
350
  requestLayout()
325
351
  invalidate()
326
352
  }
@@ -530,13 +530,27 @@ Class<RCTComponentViewProtocol> HighlightTextViewCls(void)
530
530
 
531
531
  _textView.font = newFont;
532
532
 
533
- // Force layout manager to invalidate and recalculate layout
534
- [_layoutManager invalidateLayoutForCharacterRange:NSMakeRange(0, _textView.textStorage.length) actualCharacterRange:NULL];
535
- [_layoutManager invalidateDisplayForCharacterRange:NSMakeRange(0, _textView.textStorage.length)];
533
+ // Save current text to force complete rebuild
534
+ NSString *currentText = [_textView.text copy];
536
535
 
537
- // Reapply character backgrounds with new font metrics
536
+ // Clear text storage to force complete recalculation
537
+ [_textView.textStorage beginEditing];
538
+ [_textView.textStorage replaceCharactersInRange:NSMakeRange(0, _textView.textStorage.length) withString:@""];
539
+ [_textView.textStorage endEditing];
540
+
541
+ // Force layout manager to invalidate everything
542
+ [_layoutManager invalidateLayoutForCharacterRange:NSMakeRange(0, 0) actualCharacterRange:NULL];
543
+ [_layoutManager invalidateDisplayForCharacterRange:NSMakeRange(0, 0)];
544
+
545
+ // Restore text and rebuild with new font
546
+ _textView.text = currentText;
547
+
548
+ // Reapply character backgrounds with new font metrics - this rebuilds attributed text
538
549
  [self applyCharacterBackgrounds];
539
550
 
551
+ // Force complete layout recalculation
552
+ [_textView.layoutManager ensureLayoutForTextContainer:_textView.textContainer];
553
+
540
554
  // Force the text view to redraw
541
555
  [_textView setNeedsDisplay];
542
556
  [_textView setNeedsLayout];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-highlight-text-view",
3
- "version": "0.1.17",
3
+ "version": "0.1.18",
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",