mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-16 11:42:04 +08:00
54 lines
1.8 KiB
TypeScript
54 lines
1.8 KiB
TypeScript
import * as textViewModule from "ui/text-view";
|
|
import * as colorModule from "color";
|
|
import * as utilsModule from "utils/utils";
|
|
import * as enums from "ui/enums";
|
|
|
|
export function getNativeText(textView: textViewModule.TextView): string {
|
|
return textView.ios.text;
|
|
}
|
|
|
|
export function getNativeHint(textView: textViewModule.TextView): string {
|
|
// There is no native hint so we use a hack and sett 22% opaque text.
|
|
if ((<any>textView.ios).isShowingHint) {
|
|
return textView.ios.text;
|
|
}
|
|
|
|
return "";
|
|
}
|
|
|
|
export function getNativeEditable(textView: textViewModule.TextView): boolean {
|
|
return textView.ios.editable;
|
|
}
|
|
|
|
export function getNativeFontSize(textView: textViewModule.TextView): number {
|
|
return textView.ios.font.pointSize;
|
|
}
|
|
|
|
export function getNativeColor(textView: textViewModule.TextView): colorModule.Color {
|
|
return utilsModule.ios.getColor(textView.ios.textColor);
|
|
}
|
|
|
|
export function getNativeBackgroundColor(textView: textViewModule.TextView): colorModule.Color {
|
|
return utilsModule.ios.getColor(textView.ios.backgroundColor);
|
|
}
|
|
|
|
export function getNativeTextAlignment(textView: textViewModule.TextView): string {
|
|
switch (textView.ios.textAlignment) {
|
|
case NSTextAlignment.Left:
|
|
return enums.TextAlignment.left;
|
|
case NSTextAlignment.Center:
|
|
return enums.TextAlignment.center;
|
|
case NSTextAlignment.Right:
|
|
return enums.TextAlignment.right;
|
|
default:
|
|
return "unexpected value";
|
|
}
|
|
}
|
|
|
|
export function typeTextNatively(textView: textViewModule.TextView, text: string): void {
|
|
textView.ios.text = text;
|
|
|
|
// Setting the text will not trigger the delegate method, so we have to do it by hand.
|
|
textView.ios.delegate.textViewDidEndEditing(textView.ios);
|
|
}
|