@@ -92,6 +92,31 @@ export const htmlProperty = new Property<Label, string>({ name: 'html', defaultV
92
92
93
93
type ClickableSpan = new ( owner : Span ) => android . text . style . ClickableSpan ;
94
94
95
+ function getHorizontalGravity ( textAlignment : TextAlignment ) {
96
+ switch ( textAlignment ) {
97
+ case 'initial' :
98
+ case 'left' :
99
+ return 8388611 ; //Gravity.START
100
+ case 'center' :
101
+ return 1 ; //Gravity.CENTER_HORIZONTAL
102
+ case 'right' :
103
+ return 8388613 ; //Gravity.END
104
+ }
105
+ }
106
+ function getVerticalGravity ( textAlignment : VerticalTextAlignment ) {
107
+ switch ( textAlignment ) {
108
+ case 'initial' :
109
+ case 'top' :
110
+ return 48 ; //Gravity.TOP
111
+ case 'middle' :
112
+ case 'center' :
113
+ return 16 ; //Gravity.CENTER_VERTICAL
114
+
115
+ case 'bottom' :
116
+ return 80 ; //Gravity.BOTTOM
117
+ }
118
+ }
119
+
95
120
// eslint-disable-next-line no-redeclare
96
121
let ClickableSpan : ClickableSpan ;
97
122
@@ -297,10 +322,6 @@ export class Label extends LabelBase {
297
322
return new TextView ( this . _context ) ;
298
323
}
299
324
300
- @needFormattedStringComputation
301
- [ htmlProperty . setNative ] ( value : string ) {
302
- this . _setNativeText ( ) ;
303
- }
304
325
305
326
[ maxLinesProperty . setNative ] ( value : number | string ) {
306
327
// this.nativeViewProtected.setMinLines(1);
@@ -360,57 +381,33 @@ export class Label extends LabelBase {
360
381
}
361
382
362
383
[ verticalTextAlignmentProperty . setNative ] ( value : VerticalTextAlignment ) {
363
- const horizontalGravity = this . nativeTextViewProtected . getGravity ( ) & android . view . Gravity . HORIZONTAL_GRAVITY_MASK ;
364
- switch ( value ) {
365
- case 'initial' :
366
- case 'top' :
367
- this . nativeTextViewProtected . setGravity ( android . view . Gravity . TOP | horizontalGravity ) ;
368
- break ;
369
- case 'middle' :
370
- case 'center' :
371
- this . nativeTextViewProtected . setGravity ( android . view . Gravity . CENTER_VERTICAL | horizontalGravity ) ;
372
- break ;
373
-
374
- case 'bottom' :
375
- this . nativeTextViewProtected . setGravity ( android . view . Gravity . BOTTOM | horizontalGravity ) ;
376
- break ;
377
- }
384
+ const view = this . nativeTextViewProtected ;
385
+ view . setGravity ( getHorizontalGravity ( this . textAlignment ) | getVerticalGravity ( value ) ) ;
378
386
}
379
387
380
388
[ textProperty . getDefault ] ( ) : symbol | number {
381
389
return resetSymbol ;
382
390
}
383
391
384
- @needFormattedStringComputation
385
392
[ textProperty . setNative ] ( value : string | number | symbol ) {
386
393
this . _setNativeText ( ) ;
387
394
}
388
395
389
- @needFormattedStringComputation
390
396
[ formattedTextProperty . setNative ] ( value : FormattedString ) {
391
397
this . _setNativeText ( ) ;
392
398
}
393
399
394
- @needFormattedStringComputation
395
- [ textTransformProperty . setNative ] ( value : TextTransform ) {
400
+ [ htmlProperty . setNative ] ( value : string ) {
396
401
this . _setNativeText ( ) ;
397
402
}
398
- [ textAlignmentProperty . setNative ] ( value : TextAlignment ) {
399
- const verticalGravity = this . nativeTextViewProtected . getGravity ( ) & android . view . Gravity . VERTICAL_GRAVITY_MASK ;
400
- switch ( value ) {
401
- case 'initial' :
402
- case 'left' :
403
- this . nativeTextViewProtected . setGravity ( android . view . Gravity . START | verticalGravity ) ;
404
- break ;
405
403
406
- case 'center' :
407
- this . nativeTextViewProtected . setGravity ( android . view . Gravity . CENTER_HORIZONTAL | verticalGravity ) ;
408
- break ;
404
+ [ textTransformProperty . setNative ] ( value : TextTransform ) {
405
+ this . _setNativeText ( ) ;
406
+ }
409
407
410
- case 'right' :
411
- this . nativeTextViewProtected . setGravity ( android . view . Gravity . END | verticalGravity ) ;
412
- break ;
413
- }
408
+ [ textAlignmentProperty . setNative ] ( value : TextAlignment ) {
409
+ const view = this . nativeTextViewProtected ;
410
+ view . setGravity ( getHorizontalGravity ( value ) | getVerticalGravity ( this . verticalTextAlignment ) ) ;
414
411
}
415
412
416
413
[ colorProperty . setNative ] ( value : Color | android . content . res . ColorStateList ) {
@@ -559,6 +556,10 @@ export class Label extends LabelBase {
559
556
560
557
@profile
561
558
_setNativeText ( reset : boolean = false ) : void {
559
+ if ( ! this . _canChangeText ) {
560
+ this . _needFormattedStringComputation = true ;
561
+ return ;
562
+ }
562
563
if ( reset ) {
563
564
this . nativeTextViewProtected . setText ( null ) ;
564
565
return ;
0 commit comments