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:
@@ -99,41 +99,22 @@ export class Button extends view.View implements definition.Button {
|
||||
}
|
||||
|
||||
private onFormattedTextChanged(eventData: observable.PropertyChangeData) {
|
||||
this.setFormattedTextPropertyToNative(eventData.value);
|
||||
this._setFormattedTextPropertyToNative(eventData.value);
|
||||
}
|
||||
|
||||
public _onTextPropertyChanged(data: dependencyObservable.PropertyChangeData) {
|
||||
if (this.android) {
|
||||
this.android.setText(data.newValue + "");
|
||||
}
|
||||
if (this.ios) {
|
||||
// In general, if a property is not specified for a state, the default is to use
|
||||
// the UIControlStateNormal value. If the value for UIControlStateNormal is not set,
|
||||
// then the property defaults to a system value. Therefore, at a minimum, you should
|
||||
// set the value for the normal state.
|
||||
this.ios.setTitleForState(data.newValue + "", UIControlState.UIControlStateNormal);
|
||||
}
|
||||
//
|
||||
}
|
||||
|
||||
private setFormattedTextPropertyToNative(value) {
|
||||
if (this.android) {
|
||||
this.android.setText(value._formattedText);
|
||||
}
|
||||
if (this.ios) {
|
||||
// In general, if a property is not specified for a state, the default is to use
|
||||
// the UIControlStateNormal value. If the value for UIControlStateNormal is not set,
|
||||
// then the property defaults to a system value. Therefore, at a minimum, you should
|
||||
// set the value for the normal state.
|
||||
this.ios.setAttributedTitleForState(value._formattedText, UIControlState.UIControlStateNormal);
|
||||
this.style._updateTextDecoration();
|
||||
}
|
||||
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 {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import common = require("./button-common");
|
||||
import utils = require("utils/utils")
|
||||
import dependencyObservable = require("ui/core/dependency-observable");
|
||||
|
||||
global.moduleMerge(common, exports);
|
||||
|
||||
@@ -36,4 +37,16 @@ export class Button extends common.Button {
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
public _onTextPropertyChanged(data: dependencyObservable.PropertyChangeData) {
|
||||
if (this.android) {
|
||||
this.android.setText(data.newValue + "");
|
||||
}
|
||||
}
|
||||
|
||||
public _setFormattedTextPropertyToNative(value) {
|
||||
if (this.android) {
|
||||
this.android.setText(value._formattedText);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
5
ui/button/button.d.ts
vendored
5
ui/button/button.d.ts
vendored
@@ -71,5 +71,10 @@ declare module "ui/button" {
|
||||
* @param value - Value of the element.
|
||||
*/
|
||||
_addChildFromBuilder(name: string, value: any): void;
|
||||
|
||||
//@private
|
||||
_onTextPropertyChanged(data: dependencyObservable.PropertyChangeData): void;
|
||||
_setFormattedTextPropertyToNative(value: any): void;
|
||||
//@endprivate
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import font = require("ui/styling/font");
|
||||
import view = require("ui/core/view");
|
||||
import utils = require("utils/utils");
|
||||
import enums = require("ui/enums");
|
||||
import dependencyObservable = require("ui/core/dependency-observable");
|
||||
|
||||
class TapHandlerImpl extends NSObject {
|
||||
private _owner: WeakRef<Button>;
|
||||
@@ -49,6 +50,23 @@ export class Button extends common.Button {
|
||||
get ios(): UIButton {
|
||||
return this._ios;
|
||||
}
|
||||
|
||||
public _onTextPropertyChanged(data: dependencyObservable.PropertyChangeData) {
|
||||
// In general, if a property is not specified for a state, the default is to use
|
||||
// the UIControlStateNormal value. If the value for UIControlStateNormal is not set,
|
||||
// then the property defaults to a system value. Therefore, at a minimum, you should
|
||||
// set the value for the normal state.
|
||||
this.ios.setTitleForState(data.newValue + "", UIControlState.UIControlStateNormal);
|
||||
}
|
||||
|
||||
public _setFormattedTextPropertyToNative(value) {
|
||||
// In general, if a property is not specified for a state, the default is to use
|
||||
// the UIControlStateNormal value. If the value for UIControlStateNormal is not set,
|
||||
// then the property defaults to a system value. Therefore, at a minimum, you should
|
||||
// set the value for the normal state.
|
||||
this.ios.setAttributedTitleForState(value._formattedText, UIControlState.UIControlStateNormal);
|
||||
this.style._updateTextDecoration();
|
||||
}
|
||||
}
|
||||
|
||||
export class ButtonStyler implements style.Styler {
|
||||
|
||||
Reference in New Issue
Block a user