react-native-highlight-text-view 0.1.28 → 0.1.30
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/ios/HighlightTextView.mm +23 -10
- package/package.json +1 -1
package/ios/HighlightTextView.mm
CHANGED
|
@@ -28,20 +28,29 @@ using namespace facebook::react;
|
|
|
28
28
|
NSRange glyphRange = [self glyphRangeForCharacterRange:charRange actualCharacterRange:NULL];
|
|
29
29
|
|
|
30
30
|
if (glyphRange.length > 0) {
|
|
31
|
-
// Get the actual character to ensure it's not a whitespace or control character
|
|
32
31
|
unichar character = [textStorage.string characterAtIndex:i];
|
|
33
32
|
if (character == '\n' || character == '\r' || character == ' ' || character == '\t') {
|
|
34
33
|
continue;
|
|
35
34
|
}
|
|
36
35
|
|
|
37
|
-
|
|
36
|
+
CGPoint glyphLocation = [self locationForGlyphAtIndex:glyphRange.location];
|
|
37
|
+
NSUInteger lineIndex = [self lineFragmentRectForGlyphAtIndex:glyphRange.location effectiveRange:NULL].origin.y;
|
|
38
|
+
CGRect lineRect = [self lineFragmentRectForGlyphAtIndex:glyphRange.location effectiveRange:NULL];
|
|
38
39
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
40
|
+
NSDictionary *attributes = [textStorage attributesAtIndex:i effectiveRange:NULL];
|
|
41
|
+
UIFont *font = attributes[NSFontAttributeName];
|
|
42
|
+
NSString *charString = [textStorage.string substringWithRange:NSMakeRange(i, 1)];
|
|
43
|
+
CGSize charSize = [charString sizeWithAttributes:@{NSFontAttributeName: font}];
|
|
44
|
+
|
|
45
|
+
CGRect boundingRect = CGRectMake(
|
|
46
|
+
glyphLocation.x,
|
|
47
|
+
lineRect.origin.y,
|
|
48
|
+
charSize.width,
|
|
49
|
+
lineRect.size.height
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
if (boundingRect.size.width > 1.0 && boundingRect.size.height > 1.0) {
|
|
43
53
|
|
|
44
|
-
// Apply background insets first (shrinks from line box)
|
|
45
54
|
boundingRect.origin.y += self.backgroundInsetTop;
|
|
46
55
|
boundingRect.size.height -= (self.backgroundInsetTop + self.backgroundInsetBottom);
|
|
47
56
|
boundingRect.origin.x += self.backgroundInsetLeft;
|
|
@@ -272,9 +281,13 @@ using namespace facebook::react;
|
|
|
272
281
|
_currentVerticalAlignment = verticalPart;
|
|
273
282
|
[self updateVerticalAlignment:verticalPart];
|
|
274
283
|
} else if (!verticalPart && horizontalPart) {
|
|
275
|
-
//
|
|
276
|
-
_currentVerticalAlignment
|
|
277
|
-
|
|
284
|
+
// Preserve existing vertical alignment when only horizontal alignment is specified
|
|
285
|
+
if (_currentVerticalAlignment) {
|
|
286
|
+
[self updateVerticalAlignment:_currentVerticalAlignment];
|
|
287
|
+
} else {
|
|
288
|
+
// Default vertical centering only if no vertical alignment was previously set
|
|
289
|
+
_textView.textContainerInset = UIEdgeInsetsMake(10, 10, 10, 10);
|
|
290
|
+
}
|
|
278
291
|
}
|
|
279
292
|
|
|
280
293
|
[self applyCharacterBackgrounds]; // Reapply to update alignment
|
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.30",
|
|
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",
|