@@ -54,10 +54,10 @@ import {
54
54
selectableProperty ,
55
55
textShadowProperty
56
56
} from './label-common' ;
57
+ import { SDK_VERSION } from '@nativescript/core/utils/constants' ;
57
58
58
59
export { createNativeAttributedString } from '@nativescript-community/text' ;
59
60
export * from './label-common' ;
60
- const sdkVersion = lazy ( ( ) => parseInt ( Device . sdkVersion , 10 ) ) ;
61
61
62
62
let TextView : typeof com . nativescript . text . TextView ;
63
63
@@ -262,6 +262,7 @@ export class Label extends LabelBase {
262
262
}
263
263
}
264
264
[ lineBreakProperty . setNative ] ( value : string ) {
265
+ // TODO move it all to native
265
266
const nativeView = this . nativeTextViewProtected ;
266
267
switch ( value ) {
267
268
case 'end' :
@@ -283,6 +284,7 @@ export class Label extends LabelBase {
283
284
}
284
285
285
286
[ whiteSpaceProperty . setNative ] ( value : CoreTypes . WhiteSpaceType ) {
287
+ // TODO move it all to native
286
288
if ( ! this . lineBreak ) {
287
289
const nativeView = this . nativeTextViewProtected ;
288
290
switch ( value ) {
@@ -299,16 +301,19 @@ export class Label extends LabelBase {
299
301
}
300
302
}
301
303
[ textShadowProperty . getDefault ] ( value : number ) {
302
- return {
303
- radius : this . nativeTextViewProtected . getShadowRadius ( ) ,
304
- offsetX : this . nativeTextViewProtected . getShadowDx ( ) ,
305
- offsetY : this . nativeTextViewProtected . getShadowDy ( ) ,
306
- color : this . nativeTextViewProtected . getShadowColor ( )
307
- } ;
304
+ let defaultValue = Label [ textShadowProperty . defaultValueKey ] ;
305
+ if ( ! defaultValue ) {
306
+ defaultValue = Label [ textShadowProperty . defaultValueKey ] = {
307
+ radius : this . nativeTextViewProtected . getShadowRadius ( ) ,
308
+ offsetX : this . nativeTextViewProtected . getShadowDx ( ) ,
309
+ offsetY : this . nativeTextViewProtected . getShadowDy ( ) ,
310
+ color : this . nativeTextViewProtected . getShadowColor ( )
311
+ } ;
312
+ }
313
+ return defaultValue ;
308
314
}
309
315
310
316
[ textShadowProperty . setNative ] ( value : CSSShadow ) {
311
- // prettier-ignore
312
317
this . nativeViewProtected . setShadowLayer (
313
318
Length . toDevicePixels ( value . blurRadius , java . lang . Float . MIN_VALUE ) ,
314
319
Length . toDevicePixels ( value . offsetX , 0 ) ,
@@ -318,6 +323,7 @@ export class Label extends LabelBase {
318
323
}
319
324
320
325
[ verticalTextAlignmentProperty . setNative ] ( value : VerticalTextAlignment ) {
326
+ // TODO move it all to native
321
327
const view = this . nativeTextViewProtected ;
322
328
view . setGravity ( getHorizontalGravity ( this . textAlignment ) | getVerticalGravity ( value ) ) ;
323
329
}
@@ -338,12 +344,13 @@ export class Label extends LabelBase {
338
344
[ textTransformProperty . setNative ] ( value : CoreTypes . TextTransformType ) { }
339
345
340
346
[ textAlignmentProperty . setNative ] ( value : CoreTypes . TextAlignmentType ) {
347
+ // TODO move it all to native
341
348
const view = this . nativeTextViewProtected ;
342
- if ( android . os . Build . VERSION . SDK_INT >= 26 ) {
349
+ if ( SDK_VERSION >= 26 ) {
343
350
if ( ( value as any ) === 'justify' ) {
344
- view . setJustificationMode ( android . text . Layout . JUSTIFICATION_MODE_INTER_WORD ) ;
351
+ view . setJustificationMode ( 1 /* android.text.Layout.JUSTIFICATION_MODE_INTER_WORD */ ) ;
345
352
} else {
346
- view . setJustificationMode ( android . text . Layout . JUSTIFICATION_MODE_NONE ) ;
353
+ view . setJustificationMode ( 0 /* android.text.Layout.JUSTIFICATION_MODE_NONE */ ) ;
347
354
view . setGravity ( getHorizontalGravity ( value ) | getVerticalGravity ( this . verticalTextAlignment ) ) ;
348
355
}
349
356
} else {
@@ -362,6 +369,7 @@ export class Label extends LabelBase {
362
369
}
363
370
}
364
371
[ fontSizeProperty . setNative ] ( value : number | { nativeSize : number } ) {
372
+ // TODO move it all to native
365
373
// setTextSize is ignored if autoFontSize is enabled
366
374
// so we need to disable autoFontSize just to set textSize
367
375
if ( this . mAutoFontSize ) {
@@ -370,15 +378,16 @@ export class Label extends LabelBase {
370
378
if ( typeof value === 'number' ) {
371
379
this . nativeTextViewProtected . setTextSize ( value ) ;
372
380
} else {
373
- this . nativeTextViewProtected . setTextSize ( android . util . TypedValue . COMPLEX_UNIT_SP , value . nativeSize ) ;
381
+ this . nativeTextViewProtected . setTextSize ( 2 /* android.util.TypedValue.COMPLEX_UNIT_SP */ , value . nativeSize ) ;
374
382
}
375
383
if ( this . mAutoFontSize ) {
376
384
this . enableAutoSize ( ) ;
377
385
}
378
386
}
379
387
380
388
[ lineHeightProperty . setNative ] ( value : number ) {
381
- if ( sdkVersion ( ) >= 28 ) {
389
+ // TODO move it all to native
390
+ if ( SDK_VERSION >= 28 ) {
382
391
this . nativeTextViewProtected . setLineHeight ( value * Utils . layout . getDisplayDensity ( ) ) ;
383
392
} else {
384
393
const fontHeight = this . nativeTextViewProtected . getPaint ( ) . getFontMetrics ( null ) ;
@@ -387,28 +396,30 @@ export class Label extends LabelBase {
387
396
}
388
397
389
398
[ fontInternalProperty . setNative ] ( value : Font | android . graphics . Typeface ) {
399
+ // TODO move it all to native
390
400
const androidFont : android . graphics . Typeface = value instanceof Font ? value . getAndroidTypeface ( ) : value ;
391
401
this . nativeTextViewProtected . setTypeface ( androidFont ) ;
392
- if ( this . lineHeight && sdkVersion ( ) < 28 ) {
402
+ if ( SDK_VERSION < 28 && this . lineHeight ) {
393
403
const fontHeight = this . nativeTextViewProtected . getPaint ( ) . getFontMetrics ( null ) ;
394
404
this . nativeTextViewProtected . setLineSpacing ( this . lineHeight * Utils . layout . getDisplayDensity ( ) - fontHeight , 1 ) ;
395
405
}
396
406
}
397
407
398
408
[ textDecorationProperty . setNative ] ( value : number | CoreTypes . TextDecorationType ) {
409
+ // TODO move it all to native
399
410
switch ( value ) {
400
411
case 'none' :
401
412
this . nativeTextViewProtected . setPaintFlags ( 0 ) ;
402
413
break ;
403
414
case 'underline' :
404
- this . nativeTextViewProtected . setPaintFlags ( android . graphics . Paint . UNDERLINE_TEXT_FLAG ) ;
415
+ this . nativeTextViewProtected . setPaintFlags ( 8 /* android.graphics.Paint.UNDERLINE_TEXT_FLAG */ ) ;
405
416
break ;
406
417
case 'line-through' :
407
- this . nativeTextViewProtected . setPaintFlags ( android . graphics . Paint . STRIKE_THRU_TEXT_FLAG ) ;
418
+ this . nativeTextViewProtected . setPaintFlags ( 16 /* android.graphics.Paint.STRIKE_THRU_TEXT_FLAG */ ) ;
408
419
break ;
409
420
case 'underline line-through' :
410
421
this . nativeTextViewProtected . setPaintFlags (
411
- android . graphics . Paint . UNDERLINE_TEXT_FLAG | android . graphics . Paint . STRIKE_THRU_TEXT_FLAG
422
+ 8 /* android.graphics.Paint.UNDERLINE_TEXT_FLAG */ | 16 /* android.graphics.Paint.STRIKE_THRU_TEXT_FLAG */
412
423
) ;
413
424
break ;
414
425
default :
@@ -466,7 +477,7 @@ export class Label extends LabelBase {
466
477
this . minFontSize || 10 ,
467
478
this . maxFontSize || 200 ,
468
479
this . autoFontSizeStep || 1 ,
469
- android . util . TypedValue . COMPLEX_UNIT_DIP
480
+ 1 /* android.util.TypedValue.COMPLEX_UNIT_DIP */
470
481
) ;
471
482
}
472
483
[ maxFontSizeProperty . setNative ] ( value ) {
@@ -482,7 +493,7 @@ export class Label extends LabelBase {
482
493
private disableAutoSize ( ) {
483
494
androidx . core . widget . TextViewCompat . setAutoSizeTextTypeWithDefaults (
484
495
this . nativeView ,
485
- androidx . core . widget . TextViewCompat . AUTO_SIZE_TEXT_TYPE_NONE
496
+ 0 /* androidx.core.widget.TextViewCompat.AUTO_SIZE_TEXT_TYPE_NONE */
486
497
) ;
487
498
}
488
499
[ autoFontSizeProperty . setNative ] ( value : boolean ) {
@@ -568,7 +579,7 @@ export class Label extends LabelBase {
568
579
this ,
569
580
this . formattedText === null || this . formattedText === undefined ? '' : this . formattedText . toString ( )
570
581
) ;
571
- } else if ( this . text instanceof java . lang . CharSequence || this . text instanceof android . text . Spannable ) {
582
+ } else if ( this . text instanceof java . lang . CharSequence || this . text instanceof android . text . Spannable ) {
572
583
transformedText = this . text ;
573
584
} else {
574
585
const text = this . text ;
0 commit comments