mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-17 04:41:36 +08:00

recycleNativeView filed now accepts: "always" | "never" | "auto". Always will recycle the nativeView no matter if its nativeView or android proprties are accessed. Never will disable recycling. Auto will recycle it only if nativeView and android properties are not accessed.
46 lines
1.4 KiB
TypeScript
46 lines
1.4 KiB
TypeScript
import { Label as LabelDefinition } from ".";
|
|
import { TextBase, WhiteSpace, whiteSpaceProperty, booleanConverter } from "../text-base";
|
|
import { profile } from "../../profiling";
|
|
|
|
export * from "../text-base";
|
|
|
|
let TextView: typeof android.widget.TextView;
|
|
|
|
export class Label extends TextBase implements LabelDefinition {
|
|
nativeViewProtected: android.widget.TextView;
|
|
|
|
get textWrap(): boolean {
|
|
return this.style.whiteSpace === "normal";
|
|
}
|
|
set textWrap(value: boolean) {
|
|
if (typeof value === "string") {
|
|
value = booleanConverter(value)
|
|
}
|
|
|
|
this.style.whiteSpace = value ? "normal" : "nowrap";
|
|
}
|
|
|
|
@profile
|
|
public createNativeView() {
|
|
if (!TextView) {
|
|
TextView = android.widget.TextView;
|
|
}
|
|
return new TextView(this._context);
|
|
}
|
|
|
|
public initNativeView(): void {
|
|
super.initNativeView();
|
|
const textView = this.nativeViewProtected;
|
|
textView.setSingleLine(true);
|
|
textView.setEllipsize(android.text.TextUtils.TruncateAt.END);
|
|
}
|
|
|
|
[whiteSpaceProperty.setNative](value: WhiteSpace) {
|
|
// Label initial value is no-wrap. set in initNativeView
|
|
const newValue = value === "initial" ? "nowrap" : value;
|
|
super[whiteSpaceProperty.setNative](newValue);
|
|
}
|
|
}
|
|
|
|
Label.prototype._isSingleLine = true;
|
|
Label.prototype.recycleNativeView = "auto"; |