mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-15 19:26:42 +08:00

* chore: move tns-core-modules to nativescript-core * chore: preparing compat generate script * chore: add missing definitions * chore: no need for http-request to be private * chore: packages chore * test: generate tests for tns-core-modules * chore: add anroid module for consistency * chore: add .npmignore * chore: added privateModulesWhitelist * chore(webpack): added bundle-entry-points * chore: scripts * chore: tests changed to use @ns/core * test: add scoped-packages test project * test: fix types * test: update test project * chore: build scripts * chore: update build script * chore: npm scripts cleanup * chore: make the compat pgk work with old wp config * test: generate diff friendly tests * chore: create barrel exports * chore: move files after rebase * chore: typedoc config * chore: compat mode * chore: review of barrels * chore: remove tns-core-modules import after rebase * chore: dev workflow setup * chore: update developer-workflow * docs: experiment with API extractor * chore: api-extractor and barrel exports * chore: api-extractor configs * chore: generate d.ts rollup with api-extractor * refactor: move methods inside Frame * chore: fic tests to use Frame static methods * refactor: create Builder class * refactor: use Builder class in tests * refactor: include Style in ui barrel * chore: separate compat build script * chore: fix tslint errors * chore: update NATIVESCRIPT_CORE_ARGS * chore: fix compat pack * chore: fix ui-test-app build with linked modules * chore: Application, ApplicationSettings, Connectivity and Http * chore: export Trace, Profiling and Utils * refactor: Static create methods for ImageSource * chore: fix deprecated usages of ImageSource * chore: move Span and FormattedString to ui * chore: add events-args and ImageSource to index files * chore: check for CLI >= 6.2 when building for IOS * chore: update travis build * chore: copy Pod file to compat package * chore: update error msg ui-tests-app * refactor: Apply suggestions from code review Co-Authored-By: Martin Yankov <m.i.yankov@gmail.com> * chore: typings and refs * chore: add missing d.ts files for public API * chore: adress code review FB * chore: update api-report * chore: dev-workflow for other apps * chore: api update * chore: update api-report
221 lines
7.7 KiB
TypeScript
221 lines
7.7 KiB
TypeScript
// Definitions.
|
|
import { TextBase as TextBaseDefinition, TextAlignment, TextDecoration, TextTransform, WhiteSpace } from ".";
|
|
import { FontStyle, FontWeight } from "../styling/font";
|
|
import { PropertyChangeData } from "../../data/observable";
|
|
|
|
// Types.
|
|
import { View, ViewBase, Property, CssProperty, InheritedCssProperty, Style, isAndroid, isIOS, Observable, makeValidator, makeParser, Length } from "../core/view";
|
|
import { FormattedString, Span } from "./formatted-string";
|
|
|
|
export { FormattedString, Span };
|
|
export * from "../core/view";
|
|
|
|
const CHILD_SPAN = "Span";
|
|
const CHILD_FORMATTED_TEXT = "formattedText";
|
|
const CHILD_FORMATTED_STRING = "FormattedString";
|
|
|
|
export abstract class TextBaseCommon extends View implements TextBaseDefinition {
|
|
public _isSingleLine: boolean;
|
|
public text: string;
|
|
public formattedText: FormattedString;
|
|
|
|
get nativeTextViewProtected() {
|
|
return this.nativeViewProtected;
|
|
}
|
|
|
|
get fontFamily(): string {
|
|
return this.style.fontFamily;
|
|
}
|
|
set fontFamily(value: string) {
|
|
this.style.fontFamily = value;
|
|
}
|
|
|
|
get fontSize(): number {
|
|
return this.style.fontSize;
|
|
}
|
|
set fontSize(value: number) {
|
|
this.style.fontSize = value;
|
|
}
|
|
|
|
get fontStyle(): FontStyle {
|
|
return this.style.fontStyle;
|
|
}
|
|
set fontStyle(value: FontStyle) {
|
|
this.style.fontStyle = value;
|
|
}
|
|
|
|
get fontWeight(): FontWeight {
|
|
return this.style.fontWeight;
|
|
}
|
|
set fontWeight(value: FontWeight) {
|
|
this.style.fontWeight = value;
|
|
}
|
|
|
|
get letterSpacing(): number {
|
|
return this.style.letterSpacing;
|
|
}
|
|
set letterSpacing(value: number) {
|
|
this.style.letterSpacing = value;
|
|
}
|
|
|
|
get lineHeight(): number {
|
|
return this.style.lineHeight;
|
|
}
|
|
set lineHeight(value: number) {
|
|
this.style.lineHeight = value;
|
|
}
|
|
|
|
get textAlignment(): TextAlignment {
|
|
return this.style.textAlignment;
|
|
}
|
|
set textAlignment(value: TextAlignment) {
|
|
this.style.textAlignment = value;
|
|
}
|
|
|
|
get textDecoration(): TextDecoration {
|
|
return this.style.textDecoration;
|
|
}
|
|
set textDecoration(value: TextDecoration) {
|
|
this.style.textDecoration = value;
|
|
}
|
|
|
|
get textTransform(): TextTransform {
|
|
return this.style.textTransform;
|
|
}
|
|
set textTransform(value: TextTransform) {
|
|
this.style.textTransform = value;
|
|
}
|
|
|
|
get whiteSpace(): WhiteSpace {
|
|
return this.style.whiteSpace;
|
|
}
|
|
set whiteSpace(value: WhiteSpace) {
|
|
this.style.whiteSpace = value;
|
|
}
|
|
|
|
get padding(): string | Length {
|
|
return this.style.padding;
|
|
}
|
|
set padding(value: string | Length) {
|
|
this.style.padding = value;
|
|
}
|
|
|
|
get paddingTop(): Length {
|
|
return this.style.paddingTop;
|
|
}
|
|
set paddingTop(value: Length) {
|
|
this.style.paddingTop = value;
|
|
}
|
|
|
|
get paddingRight(): Length {
|
|
return this.style.paddingRight;
|
|
}
|
|
set paddingRight(value: Length) {
|
|
this.style.paddingRight = value;
|
|
}
|
|
|
|
get paddingBottom(): Length {
|
|
return this.style.paddingBottom;
|
|
}
|
|
set paddingBottom(value: Length) {
|
|
this.style.paddingBottom = value;
|
|
}
|
|
|
|
get paddingLeft(): Length {
|
|
return this.style.paddingLeft;
|
|
}
|
|
set paddingLeft(value: Length) {
|
|
this.style.paddingLeft = value;
|
|
}
|
|
|
|
public _onFormattedTextContentsChanged(data: PropertyChangeData) {
|
|
if (this.nativeViewProtected) {
|
|
// Notifications from the FormattedString start arriving before the Android view is even created.
|
|
this[formattedTextProperty.setNative](data.value);
|
|
}
|
|
}
|
|
|
|
public _addChildFromBuilder(name: string, value: any): void {
|
|
if (name === CHILD_SPAN) {
|
|
if (!this.formattedText) {
|
|
const formattedText = new FormattedString();
|
|
formattedText.spans.push(value);
|
|
this.formattedText = formattedText;
|
|
} else {
|
|
this.formattedText.spans.push(value);
|
|
}
|
|
}
|
|
else if (name === CHILD_FORMATTED_TEXT || name === CHILD_FORMATTED_STRING) {
|
|
this.formattedText = value;
|
|
}
|
|
}
|
|
|
|
_requestLayoutOnTextChanged(): void {
|
|
this.requestLayout();
|
|
}
|
|
|
|
eachChild(callback: (child: ViewBase) => boolean): void {
|
|
let text = this.formattedText;
|
|
if (text) {
|
|
callback(text);
|
|
}
|
|
}
|
|
|
|
_setNativeText(reset: boolean = false): void {
|
|
//
|
|
}
|
|
}
|
|
|
|
TextBaseCommon.prototype._isSingleLine = false;
|
|
|
|
export function isBold(fontWeight: FontWeight): boolean {
|
|
return fontWeight === "bold" || fontWeight === "700" || fontWeight === "800" || fontWeight === "900";
|
|
}
|
|
|
|
export const textProperty = new Property<TextBaseCommon, string>({ name: "text", defaultValue: "", affectsLayout: isAndroid });
|
|
textProperty.register(TextBaseCommon);
|
|
|
|
export const formattedTextProperty = new Property<TextBaseCommon, FormattedString>({ name: "formattedText", affectsLayout: true, valueChanged: onFormattedTextPropertyChanged });
|
|
formattedTextProperty.register(TextBaseCommon);
|
|
|
|
function onFormattedTextPropertyChanged(textBase: TextBaseCommon, oldValue: FormattedString, newValue: FormattedString) {
|
|
if (oldValue) {
|
|
oldValue.off(Observable.propertyChangeEvent, textBase._onFormattedTextContentsChanged, textBase);
|
|
textBase._removeView(oldValue);
|
|
}
|
|
|
|
if (newValue) {
|
|
const oldParent = newValue.parent;
|
|
// In case formattedString is attached to new TextBase
|
|
if (oldParent) {
|
|
oldParent._removeView(newValue);
|
|
}
|
|
textBase._addView(newValue);
|
|
newValue.on(Observable.propertyChangeEvent, textBase._onFormattedTextContentsChanged, textBase);
|
|
}
|
|
}
|
|
|
|
const textAlignmentConverter = makeParser<TextAlignment>(makeValidator<TextAlignment>("initial", "left", "center", "right"));
|
|
export const textAlignmentProperty = new InheritedCssProperty<Style, TextAlignment>({ name: "textAlignment", cssName: "text-align", defaultValue: "initial", valueConverter: textAlignmentConverter });
|
|
textAlignmentProperty.register(Style);
|
|
|
|
const textTransformConverter = makeParser<TextTransform>(makeValidator<TextTransform>("initial", "none", "capitalize", "uppercase", "lowercase"));
|
|
export const textTransformProperty = new CssProperty<Style, TextTransform>({ name: "textTransform", cssName: "text-transform", defaultValue: "initial", valueConverter: textTransformConverter });
|
|
textTransformProperty.register(Style);
|
|
|
|
const whiteSpaceConverter = makeParser<WhiteSpace>(makeValidator<WhiteSpace>("initial", "normal", "nowrap"));
|
|
export const whiteSpaceProperty = new CssProperty<Style, WhiteSpace>({ name: "whiteSpace", cssName: "white-space", defaultValue: "initial", affectsLayout: isIOS, valueConverter: whiteSpaceConverter });
|
|
whiteSpaceProperty.register(Style);
|
|
|
|
const textDecorationConverter = makeParser<TextDecoration>(makeValidator<TextDecoration>("none", "underline", "line-through", "underline line-through"));
|
|
export const textDecorationProperty = new CssProperty<Style, TextDecoration>({ name: "textDecoration", cssName: "text-decoration", defaultValue: "none", valueConverter: textDecorationConverter });
|
|
textDecorationProperty.register(Style);
|
|
|
|
export const letterSpacingProperty = new CssProperty<Style, number>({ name: "letterSpacing", cssName: "letter-spacing", defaultValue: 0, affectsLayout: isIOS, valueConverter: v => parseFloat(v) });
|
|
letterSpacingProperty.register(Style);
|
|
|
|
export const lineHeightProperty = new CssProperty<Style, number>({ name: "lineHeight", cssName: "line-height", affectsLayout: isIOS, valueConverter: v => parseFloat(v) });
|
|
lineHeightProperty.register(Style);
|
|
|
|
export const resetSymbol = Symbol("textPropertyDefault");
|