react-native-highlight-text-view 0.1.28 → 0.1.29

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.
@@ -34,12 +34,28 @@ using namespace facebook::react;
34
34
  continue;
35
35
  }
36
36
 
37
- CGRect boundingRect = [self boundingRectForGlyphRange:glyphRange inTextContainer:textContainer];
37
+ // Get the glyph's position and line metrics
38
+ CGPoint glyphLocation = [self locationForGlyphAtIndex:glyphRange.location];
39
+ NSUInteger lineIndex = [self lineFragmentRectForGlyphAtIndex:glyphRange.location effectiveRange:NULL].origin.y;
40
+ CGRect lineRect = [self lineFragmentRectForGlyphAtIndex:glyphRange.location effectiveRange:NULL];
38
41
 
39
- // Ensure the glyph has reasonable dimensions and isn't a line fragment artifact
40
- // Also check that it's not spanning the full container width (which indicates line wrapping issues)
41
- if (boundingRect.size.width > 1.0 && boundingRect.size.height > 1.0 &&
42
- boundingRect.size.width < (textContainer.size.width * 0.8)) {
42
+ // Calculate precise character width using the font's attributes
43
+ // This avoids the extra spacing that boundingRectForGlyphRange includes with lineHeight
44
+ NSDictionary *attributes = [textStorage attributesAtIndex:i effectiveRange:NULL];
45
+ UIFont *font = attributes[NSFontAttributeName];
46
+ NSString *charString = [textStorage.string substringWithRange:NSMakeRange(i, 1)];
47
+ CGSize charSize = [charString sizeWithAttributes:@{NSFontAttributeName: font}];
48
+
49
+ // Build the character rect with precise width
50
+ CGRect boundingRect = CGRectMake(
51
+ glyphLocation.x,
52
+ lineRect.origin.y,
53
+ charSize.width,
54
+ lineRect.size.height
55
+ );
56
+
57
+ // Ensure the glyph has reasonable dimensions
58
+ if (boundingRect.size.width > 1.0 && boundingRect.size.height > 1.0) {
43
59
 
44
60
  // Apply background insets first (shrinks from line box)
45
61
  boundingRect.origin.y += self.backgroundInsetTop;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-highlight-text-view",
3
- "version": "0.1.28",
3
+ "version": "0.1.29",
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",
@@ -18,7 +18,7 @@
18
18
  "android",
19
19
  "ios",
20
20
  "cpp",
21
- "*.podspec",
21
+ "*.podspec",
22
22
  "react-native.config.js",
23
23
  "!ios/build",
24
24
  "!android/build",