Created
May 7, 2018 16:04
-
-
Save m-abs/7743a0aa41621a5a54a74ef9d357e41b to your computer and use it in GitHub Desktop.
NativeScript resize label on text change:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Directive, ElementRef, Input } from '@angular/core'; | |
import { Label } from 'tns-core-modules/ui/label'; | |
/** | |
* Make sure the layout is updated then the Label's text is changed. | |
*/ | |
@Directive({ | |
// tslint:disable-next-line:directive-selector | |
selector: 'Label[text]', | |
}) | |
export class UpdateLabelDirective { | |
@Input('text') | |
public set _text(text: string) { | |
const nativeView = this.nativeView; | |
if (nativeView && nativeView instanceof Label) { | |
nativeView.text = text; | |
nativeView.requestLayout(); | |
} | |
} | |
private get nativeView(): Label { | |
return this.el.nativeElement; | |
} | |
constructor(private readonly el: ElementRef) {} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment