1
1
import { VerticalTextAlignment , createNativeAttributedString , verticalTextAlignmentProperty } from '@nativescript-community/text' ;
2
- import { Color , CoreTypes , Font , FormattedString , View } from '@nativescript/core' ;
2
+ import { Color , CoreTypes , Font , FormattedString , Span , View } from '@nativescript/core' ;
3
3
import {
4
4
borderBottomWidthProperty ,
5
5
borderLeftWidthProperty ,
@@ -353,14 +353,40 @@ export class Label extends LabelBase {
353
353
}
354
354
// _htmlTappable = false;
355
355
// _htmlTapGestureRecognizer;
356
+ _tappable ;
357
+ _setTappableState ( tappable ) {
358
+ if ( this . _tappable !== tappable ) {
359
+ this . _tappable = tappable ;
360
+ // we dont want the label gesture recognizer for linkTap
361
+ // so we override
362
+ }
363
+ }
356
364
357
365
textViewShouldInteractWithURLInRangeInteraction ?(
358
366
textView : UITextView ,
359
- URL : NSURL ,
367
+ url : NSURL ,
360
368
characterRange : NSRange ,
361
369
interaction : UITextItemInteraction
362
370
) {
363
- this . notify ( { eventName : 'linkTap' , object : this , link : URL . toString ( ) } ) ;
371
+ for ( let i = 0 , spanStart = 0 , length = this . formattedText . spans . length ; i < length ; i ++ ) {
372
+ const span = this . formattedText . spans . getItem ( i ) ;
373
+ const text = span . text ;
374
+ const textTransform = ( this . formattedText . parent as View ) . textTransform ;
375
+ let spanText = isNullOrUndefined ( text ) ? '' : `${ text } ` ;
376
+ if ( textTransform !== 'none' && textTransform !== 'initial' ) {
377
+ spanText = getTransformedText ( spanText , textTransform ) ;
378
+ }
379
+
380
+ spanStart += spanText . length ;
381
+ if ( characterRange . location - 1 <= spanStart && characterRange . location - 1 + characterRange . length > spanStart ) {
382
+ const span : Span = this . formattedText . spans . getItem ( i ) ;
383
+ if ( span && span . tappable ) {
384
+ // if the span is found and tappable emit the linkTap event
385
+ span . notify ( { eventName : Span . linkTapEvent , link : url ?. toString ( ) } ) ;
386
+ }
387
+ break ;
388
+ }
389
+ }
364
390
return false ;
365
391
}
366
392
@@ -392,7 +418,7 @@ export class Label extends LabelBase {
392
418
this . fontSizeRatio
393
419
) as NSMutableAttributedString ;
394
420
let hasLink = false ;
395
- result &&
421
+ if ( result ) {
396
422
result . enumerateAttributeInRangeOptionsUsingBlock (
397
423
NSLinkAttributeName ,
398
424
{ location : 0 , length : result . length } ,
@@ -404,6 +430,8 @@ export class Label extends LabelBase {
404
430
}
405
431
}
406
432
) ;
433
+ }
434
+
407
435
this . nativeTextViewProtected . selectable = this . selectable === true || hasLink ;
408
436
409
437
this . attributedString = result ;
@@ -603,7 +631,7 @@ export class Label extends LabelBase {
603
631
createParagraphStyle ( ) ;
604
632
paragraphStyle . minimumLineHeight = lineHeight ;
605
633
paragraphStyle . maximumLineHeight = lineHeight ;
606
- // } else if (isTextView) {
634
+ // } else if (isTextView) {
607
635
// createParagraphStyle();
608
636
}
609
637
const source = getTransformedText ( isNullOrUndefined ( this . text ) ? '' : `${ this . text } ` , this . textTransform ) ;
0 commit comments