react-native-advanced-text 0.1.33 → 0.1.34
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/AdvancedTextView.mm +35 -9
- package/package.json +1 -1
package/ios/AdvancedTextView.mm
CHANGED
|
@@ -277,9 +277,11 @@ using namespace facebook::react;
|
|
|
277
277
|
NSCharacterSet *whitespaceSet = [NSCharacterSet whitespaceAndNewlineCharacterSet];
|
|
278
278
|
|
|
279
279
|
NSInteger wordIndex = 0;
|
|
280
|
+
NSMutableArray *allMatches = [NSMutableArray array];
|
|
281
|
+
|
|
280
282
|
while (searchRange.location < text.length) {
|
|
281
283
|
while (searchRange.location < text.length &&
|
|
282
|
-
|
|
284
|
+
[whitespaceSet characterIsMember:[text characterAtIndex:searchRange.location]]) {
|
|
283
285
|
searchRange.location++;
|
|
284
286
|
searchRange.length = text.length - searchRange.location;
|
|
285
287
|
}
|
|
@@ -288,14 +290,14 @@ using namespace facebook::react;
|
|
|
288
290
|
|
|
289
291
|
NSUInteger wordStart = searchRange.location;
|
|
290
292
|
while (searchRange.location < text.length &&
|
|
291
|
-
|
|
293
|
+
![whitespaceSet characterIsMember:[text characterAtIndex:searchRange.location]]) {
|
|
292
294
|
searchRange.location++;
|
|
293
295
|
}
|
|
294
296
|
|
|
295
297
|
NSRange wordRange = NSMakeRange(wordStart, searchRange.location - wordStart);
|
|
296
298
|
NSString *word = [text substringWithRange:wordRange];
|
|
297
299
|
|
|
298
|
-
[
|
|
300
|
+
[allMatches addObject:@{
|
|
299
301
|
@"word": word,
|
|
300
302
|
@"range": [NSValue valueWithRange:wordRange],
|
|
301
303
|
@"index": @(wordIndex)
|
|
@@ -305,6 +307,25 @@ using namespace facebook::react;
|
|
|
305
307
|
searchRange.length = text.length - searchRange.location;
|
|
306
308
|
}
|
|
307
309
|
|
|
310
|
+
for (NSInteger i = 0; i < allMatches.count; i++) {
|
|
311
|
+
NSMutableDictionary *wordInfo = [allMatches[i] mutableCopy];
|
|
312
|
+
NSRange wordRange = [wordInfo[@"range"] rangeValue];
|
|
313
|
+
|
|
314
|
+
NSUInteger extendedEnd;
|
|
315
|
+
if (i + 1 < allMatches.count) {
|
|
316
|
+
NSRange nextRange = [allMatches[i + 1][@"range"] rangeValue];
|
|
317
|
+
extendedEnd = nextRange.location;
|
|
318
|
+
} else {
|
|
319
|
+
extendedEnd = text.length;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
NSRange extendedRange = NSMakeRange(wordRange.location, extendedEnd - wordRange.location);
|
|
323
|
+
wordInfo[@"extendedRange"] = [NSValue valueWithRange:extendedRange];
|
|
324
|
+
|
|
325
|
+
[_wordRanges addObject:[wordInfo copy]];
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
|
|
308
329
|
NSLog(@"[AdvancedTextView] Parsed %ld words", (long)_wordRanges.count);
|
|
309
330
|
[self updateTextAppearance];
|
|
310
331
|
} @catch (NSException *exception) {
|
|
@@ -382,7 +403,7 @@ using namespace facebook::react;
|
|
|
382
403
|
value:paragraphStyle
|
|
383
404
|
range:NSMakeRange(0, attributedString.length)];
|
|
384
405
|
}
|
|
385
|
-
|
|
406
|
+
|
|
386
407
|
UIFont *font = nil;
|
|
387
408
|
|
|
388
409
|
if (_fontFamily && _fontFamily.length > 0) {
|
|
@@ -421,16 +442,21 @@ using namespace facebook::react;
|
|
|
421
442
|
|
|
422
443
|
UIColor *highlightColor = _highlightColors[index];
|
|
423
444
|
if (highlightColor) {
|
|
424
|
-
[
|
|
425
|
-
|
|
426
|
-
|
|
445
|
+
NSValue *extendedRangeValue = wordInfo[@"extendedRange"];
|
|
446
|
+
NSRange extendedRange = extendedRangeValue ? [extendedRangeValue rangeValue] : range;
|
|
447
|
+
|
|
448
|
+
if (extendedRange.location + extendedRange.length <= attributedString.length) {
|
|
449
|
+
[attributedString addAttribute:NSBackgroundColorAttributeName
|
|
450
|
+
value:highlightColor
|
|
451
|
+
range:extendedRange];
|
|
452
|
+
}
|
|
427
453
|
}
|
|
428
454
|
|
|
429
455
|
if (_indicatorWordIndex >= 0 && [index integerValue] == _indicatorWordIndex) {
|
|
430
456
|
UIColor *indicatorColor = [[UIColor systemBlueColor] colorWithAlphaComponent:0.3];
|
|
431
457
|
[attributedString addAttribute:NSBackgroundColorAttributeName
|
|
432
|
-
|
|
433
|
-
|
|
458
|
+
value:indicatorColor
|
|
459
|
+
range:range];
|
|
434
460
|
}
|
|
435
461
|
}
|
|
436
462
|
|
package/package.json
CHANGED