mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
Re-apply TextBase.formattedText after a style property change
Resolves #1078
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
import definition = require("ui/text-base");
|
||||
import view = require("ui/core/view");
|
||||
import types = require("utils/types");
|
||||
import observable = require("data/observable");
|
||||
import dependencyObservable = require("ui/core/dependency-observable");
|
||||
import proxy = require("ui/core/proxy");
|
||||
@@ -97,37 +96,22 @@ export class TextBase extends view.View implements definition.TextBase, formatte
|
||||
}
|
||||
|
||||
private onFormattedTextChanged(eventData: observable.PropertyChangeData) {
|
||||
this.setFormattedTextPropertyToNative(eventData.value);
|
||||
this._setFormattedTextPropertyToNative(eventData.value);
|
||||
}
|
||||
|
||||
public _onTextPropertyChanged(data: dependencyObservable.PropertyChangeData) {
|
||||
var newValue = types.isNullOrUndefined(data.newValue) ? "" : data.newValue + "";
|
||||
if (this.android) {
|
||||
this.android.setText(newValue);
|
||||
}
|
||||
else if (this.ios) {
|
||||
this.ios.text = newValue;
|
||||
this.style._updateTextDecoration();
|
||||
this.style._updateTextTransform();
|
||||
}
|
||||
//
|
||||
}
|
||||
|
||||
private setFormattedTextPropertyToNative(value) {
|
||||
if (this.android) {
|
||||
this.android.setText(value._formattedText);
|
||||
} else if (this.ios) {
|
||||
this.ios.attributedText = value._formattedText;
|
||||
this.style._updateTextDecoration();
|
||||
this.style._updateTextTransform();
|
||||
this.requestLayout();
|
||||
}
|
||||
public _setFormattedTextPropertyToNative(value) {
|
||||
//
|
||||
}
|
||||
|
||||
public _onFormattedTextPropertyChanged(data: dependencyObservable.PropertyChangeData) {
|
||||
if (data.newValue) {
|
||||
(<formattedString.FormattedString>data.newValue).parent = this;
|
||||
}
|
||||
this.setFormattedTextPropertyToNative(data.newValue);
|
||||
this._setFormattedTextPropertyToNative(data.newValue);
|
||||
}
|
||||
|
||||
public _addChildFromBuilder(name: string, value: any): void {
|
||||
17
ui/text-base/text-base.android.ts
Normal file
17
ui/text-base/text-base.android.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
import common = require("./text-base-common");
|
||||
import types = require("utils/types");
|
||||
import dependencyObservable = require("ui/core/dependency-observable");
|
||||
|
||||
export class TextBase extends common.TextBase {
|
||||
public _onTextPropertyChanged(data: dependencyObservable.PropertyChangeData) {
|
||||
if (this.android) {
|
||||
var newValue = types.isNullOrUndefined(data.newValue) ? "" : data.newValue + "";
|
||||
this.android.setText(newValue);
|
||||
}
|
||||
}
|
||||
public _setFormattedTextPropertyToNative(value) {
|
||||
if (this.android) {
|
||||
this.android.setText(value._formattedText);
|
||||
}
|
||||
}
|
||||
}
|
||||
7
ui/text-base/text-base.d.ts
vendored
7
ui/text-base/text-base.d.ts
vendored
@@ -40,8 +40,6 @@
|
||||
*/
|
||||
formattedText: formattedString.FormattedString;
|
||||
|
||||
_onTextPropertyChanged(data: dependencyObservable.PropertyChangeData);
|
||||
|
||||
/**
|
||||
* Called for every child element declared in xml.
|
||||
* This method will add a child element (value) to current element.
|
||||
@@ -49,6 +47,11 @@
|
||||
* @param value - Value of the element.
|
||||
*/
|
||||
_addChildFromBuilder(name: string, value: any): void;
|
||||
|
||||
//@private
|
||||
_onTextPropertyChanged(data: dependencyObservable.PropertyChangeData): void;
|
||||
_setFormattedTextPropertyToNative(value: any): void;
|
||||
//@endprivate
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
27
ui/text-base/text-base.ios.ts
Normal file
27
ui/text-base/text-base.ios.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import common = require("./text-base-common");
|
||||
import types = require("utils/types");
|
||||
import dependencyObservable = require("ui/core/dependency-observable");
|
||||
|
||||
export class TextBase extends common.TextBase {
|
||||
public _onTextPropertyChanged(data: dependencyObservable.PropertyChangeData) {
|
||||
var newValue = types.isNullOrUndefined(data.newValue) ? "" : data.newValue + "";
|
||||
this.ios.text = newValue;
|
||||
this.style._updateTextDecoration();
|
||||
this.style._updateTextTransform();
|
||||
}
|
||||
|
||||
public _setFormattedTextPropertyToNative(value) {
|
||||
this.ios.attributedText = value._formattedText;
|
||||
this.style._updateTextDecoration();
|
||||
this.style._updateTextTransform();
|
||||
this.requestLayout();
|
||||
}
|
||||
|
||||
public _onStylePropertyChanged(property: dependencyObservable.Property): void {
|
||||
if (this.formattedText) {
|
||||
// Re-apply the formatted text to override style changes if needed.
|
||||
// https://github.com/NativeScript/NativeScript/issues/1078
|
||||
this._setFormattedTextPropertyToNative(this.formattedText);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user