1
- import { CSSType , FormattedString , Observable , Property , PropertyChangeData , Span , View , ViewBase , booleanConverter , knownFolders , path , profile } from '@nativescript/core' ;
1
+ import { VerticalTextAlignment , verticalTextAlignmentProperty } from '@nativescript-community/text' ;
2
+ import {
3
+ CSSType ,
4
+ FormattedString ,
5
+ Observable ,
6
+ Property ,
7
+ PropertyChangeData ,
8
+ Span ,
9
+ View ,
10
+ ViewBase ,
11
+ booleanConverter ,
12
+ knownFolders ,
13
+ path ,
14
+ profile ,
15
+ } from '@nativescript/core' ;
2
16
import { android as androidApp } from '@nativescript/core/application' ;
3
17
import { Color } from '@nativescript/core/color' ;
4
18
import { Font , FontStyle , FontWeight } from '@nativescript/core/ui/styling/font' ;
@@ -24,36 +38,39 @@ import {
24
38
textTransformProperty ,
25
39
whiteSpaceProperty ,
26
40
} from '@nativescript/core/ui/text-base' ;
27
- import {
28
- lineHeightProperty
29
- } from '@nativescript/core/ui/text-base/text-base-common' ;
41
+ import { lineHeightProperty } from '@nativescript/core/ui/text-base/text-base-common' ;
30
42
import { layout } from '@nativescript/core/utils/utils' ;
31
43
import { Label as LabelViewDefinition , LineBreak , TextShadow } from './label' ;
32
44
import {
33
- VerticalTextAlignment ,
34
45
cssProperty ,
35
46
lineBreakProperty ,
36
47
maxLinesProperty ,
37
48
needFormattedStringComputation ,
38
49
textAlignmentConverter ,
39
50
textShadowProperty ,
40
- verticalTextAlignmentProperty ,
41
51
} from './label-common' ;
42
52
43
53
export function enableIOSDTCoreText ( ) { } //unused
44
54
45
55
let context ;
46
56
const fontPath = path . join ( knownFolders . currentApp ( ) . path , 'fonts' ) ;
47
57
48
- Font . prototype . getAndroidTypeface = function ( ) {
58
+ Font . prototype . getAndroidTypeface = profile ( 'getAndroidTypeface' , function ( ) {
49
59
if ( ! this . _typeface ) {
50
60
if ( ! context ) {
51
61
context = androidApp . context ;
52
62
}
53
- this . _typeface = ( com as any ) . nativescript . label . Font . createTypeface ( context , fontPath , this . fontFamily , this . fontWeight , this . isBold , this . isItalic ) ;
63
+ this . _typeface = ( com as any ) . nativescript . label . Font . createTypeface (
64
+ context ,
65
+ fontPath ,
66
+ this . fontFamily ,
67
+ this . fontWeight ,
68
+ this . isBold ,
69
+ this . isItalic
70
+ ) ;
54
71
}
55
72
return this . _typeface ;
56
- } ;
73
+ } ) ;
57
74
58
75
declare module '@nativescript/core/ui/text-base/formatted-string' {
59
76
interface FormattedString {
@@ -104,9 +121,11 @@ Span.prototype.toNativeString = function () {
104
121
text = getTransformedText ( text , textTransform ) ;
105
122
}
106
123
const delimiter = String . fromCharCode ( 0x1e ) ;
107
- const result = `${ this . fontFamily || 0 } ${ delimiter } ${ this . fontSize !== undefined ? this . fontSize : - 1 } ${ delimiter } ${ this . fontWeight || '' } ${ delimiter } ${
108
- this . fontStyle === 'italic' ? 1 : 0
109
- } ${ delimiter } ${ textDecoration || 0 } ${ delimiter } ${ this . color ? this . color . android : - 1 } ${ delimiter } ${ backgroundColor ? backgroundColor . android : - 1 } ${ delimiter } ${ this . text } `;
124
+ const result = `${ this . fontFamily || 0 } ${ delimiter } ${ this . fontSize !== undefined ? this . fontSize : - 1 } ${ delimiter } ${
125
+ this . fontWeight || ''
126
+ } ${ delimiter } ${ this . fontStyle === 'italic' ? 1 : 0 } ${ delimiter } ${ textDecoration || 0 } ${ delimiter } ${
127
+ this . color ? this . color . android : - 1
128
+ } ${ delimiter } ${ backgroundColor ? backgroundColor . android : - 1 } ${ delimiter } ${ this . text } `;
110
129
return result ;
111
130
} ;
112
131
@@ -139,7 +158,11 @@ declare module '@nativescript/core/ui/core/view-base' {
139
158
}
140
159
141
160
const textProperty = new Property < Label , string > ( { name : 'text' , defaultValue : '' , affectsLayout : true } ) ;
142
- const formattedTextProperty = new Property < Label , FormattedString > ( { name : 'formattedText' , affectsLayout : true , valueChanged : onFormattedTextPropertyChanged } ) ;
161
+ const formattedTextProperty = new Property < Label , FormattedString > ( {
162
+ name : 'formattedText' ,
163
+ affectsLayout : true ,
164
+ valueChanged : onFormattedTextPropertyChanged ,
165
+ } ) ;
143
166
export const htmlProperty = new Property < Label , string > ( { name : 'html' , defaultValue : null , affectsLayout : true } ) ;
144
167
145
168
export function buildHTMLString ( data : {
@@ -337,11 +360,17 @@ export class Label extends LabelBase {
337
360
}
338
361
}
339
362
[ textShadowProperty . setNative ] ( value : TextShadow ) {
340
- this . nativeViewProtected . setShadowLayer ( layout . toDevicePixels ( value . blurRadius ) , layout . toDevicePixels ( value . offsetX ) , layout . toDevicePixels ( value . offsetY ) , value . color . android ) ;
363
+ this . nativeViewProtected . setShadowLayer (
364
+ layout . toDevicePixels ( value . blurRadius ) ,
365
+ layout . toDevicePixels ( value . offsetX ) ,
366
+ layout . toDevicePixels ( value . offsetY ) ,
367
+ value . color . android
368
+ ) ;
341
369
}
342
370
343
371
[ verticalTextAlignmentProperty . setNative ] ( value : VerticalTextAlignment ) {
344
372
const horizontalGravity = this . nativeTextViewProtected . getGravity ( ) & android . view . Gravity . HORIZONTAL_GRAVITY_MASK ;
373
+ console . log ( 'verticalTextAlignmentProperty' , value , horizontalGravity ) ;
345
374
switch ( value ) {
346
375
case 'initial' :
347
376
case 'top' :
@@ -433,7 +462,9 @@ export class Label extends LabelBase {
433
462
this . nativeTextViewProtected . setPaintFlags ( android . graphics . Paint . STRIKE_THRU_TEXT_FLAG ) ;
434
463
break ;
435
464
case 'underline line-through' :
436
- this . nativeTextViewProtected . setPaintFlags ( android . graphics . Paint . UNDERLINE_TEXT_FLAG | android . graphics . Paint . STRIKE_THRU_TEXT_FLAG ) ;
465
+ this . nativeTextViewProtected . setPaintFlags (
466
+ android . graphics . Paint . UNDERLINE_TEXT_FLAG | android . graphics . Paint . STRIKE_THRU_TEXT_FLAG
467
+ ) ;
437
468
break ;
438
469
default :
439
470
this . nativeTextViewProtected . setPaintFlags ( value ) ;
@@ -449,28 +480,40 @@ export class Label extends LabelBase {
449
480
return { value : this . _defaultPaddingTop , unit : 'px' } ;
450
481
}
451
482
[ paddingTopProperty . setNative ] ( value : Length ) {
452
- org . nativescript . widgets . ViewHelper . setPaddingTop ( this . nativeTextViewProtected , Length . toDevicePixels ( value , 0 ) + Length . toDevicePixels ( this . style . borderTopWidth , 0 ) ) ;
483
+ org . nativescript . widgets . ViewHelper . setPaddingTop (
484
+ this . nativeTextViewProtected ,
485
+ Length . toDevicePixels ( value , 0 ) + Length . toDevicePixels ( this . style . borderTopWidth , 0 )
486
+ ) ;
453
487
}
454
488
455
489
[ paddingRightProperty . getDefault ] ( ) : Length {
456
490
return { value : this . _defaultPaddingRight , unit : 'px' } ;
457
491
}
458
492
[ paddingRightProperty . setNative ] ( value : Length ) {
459
- org . nativescript . widgets . ViewHelper . setPaddingRight ( this . nativeTextViewProtected , Length . toDevicePixels ( value , 0 ) + Length . toDevicePixels ( this . style . borderRightWidth , 0 ) ) ;
493
+ org . nativescript . widgets . ViewHelper . setPaddingRight (
494
+ this . nativeTextViewProtected ,
495
+ Length . toDevicePixels ( value , 0 ) + Length . toDevicePixels ( this . style . borderRightWidth , 0 )
496
+ ) ;
460
497
}
461
498
462
499
[ paddingBottomProperty . getDefault ] ( ) : Length {
463
500
return { value : this . _defaultPaddingBottom , unit : 'px' } ;
464
501
}
465
502
[ paddingBottomProperty . setNative ] ( value : Length ) {
466
- org . nativescript . widgets . ViewHelper . setPaddingBottom ( this . nativeTextViewProtected , Length . toDevicePixels ( value , 0 ) + Length . toDevicePixels ( this . style . borderBottomWidth , 0 ) ) ;
503
+ org . nativescript . widgets . ViewHelper . setPaddingBottom (
504
+ this . nativeTextViewProtected ,
505
+ Length . toDevicePixels ( value , 0 ) + Length . toDevicePixels ( this . style . borderBottomWidth , 0 )
506
+ ) ;
467
507
}
468
508
469
509
[ paddingLeftProperty . getDefault ] ( ) : Length {
470
510
return { value : this . _defaultPaddingLeft , unit : 'px' } ;
471
511
}
472
512
[ paddingLeftProperty . setNative ] ( value : Length ) {
473
- org . nativescript . widgets . ViewHelper . setPaddingLeft ( this . nativeTextViewProtected , Length . toDevicePixels ( value , 0 ) + Length . toDevicePixels ( this . style . borderLeftWidth , 0 ) ) ;
513
+ org . nativescript . widgets . ViewHelper . setPaddingLeft (
514
+ this . nativeTextViewProtected ,
515
+ Length . toDevicePixels ( value , 0 ) + Length . toDevicePixels ( this . style . borderLeftWidth , 0 )
516
+ ) ;
474
517
}
475
518
476
519
@profile
@@ -498,7 +541,10 @@ export class Label extends LabelBase {
498
541
textProperty . nativeValueChange ( this , this . html === null || this . html === undefined ? '' : this . html ) ;
499
542
} else if ( this . formattedText ) {
500
543
transformedText = this . createSpannableStringBuilder ( ) ;
501
- textProperty . nativeValueChange ( this , this . formattedText === null || this . formattedText === undefined ? '' : this . formattedText . toString ( ) ) ;
544
+ textProperty . nativeValueChange (
545
+ this ,
546
+ this . formattedText === null || this . formattedText === undefined ? '' : this . formattedText . toString ( )
547
+ ) ;
502
548
} else {
503
549
const text = this . text ;
504
550
const stringValue = text === null || text === undefined ? '' : text . toString ( ) ;
0 commit comments