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:
@@ -1666,7 +1666,13 @@
|
|||||||
<DependentUpon>builder.d.ts</DependentUpon>
|
<DependentUpon>builder.d.ts</DependentUpon>
|
||||||
</TypeScriptCompile>
|
</TypeScriptCompile>
|
||||||
<TypeScriptCompile Include="ui\text-base\text-base.d.ts" />
|
<TypeScriptCompile Include="ui\text-base\text-base.d.ts" />
|
||||||
<TypeScriptCompile Include="ui\text-base\text-base.ts">
|
<TypeScriptCompile Include="ui\text-base\text-base-common.ts">
|
||||||
|
<DependentUpon>text-base.d.ts</DependentUpon>
|
||||||
|
</TypeScriptCompile>
|
||||||
|
<TypeScriptCompile Include="ui\text-base\text-base.ios.ts">
|
||||||
|
<DependentUpon>text-base.d.ts</DependentUpon>
|
||||||
|
</TypeScriptCompile>
|
||||||
|
<TypeScriptCompile Include="ui\text-base\text-base.android.ts">
|
||||||
<DependentUpon>text-base.d.ts</DependentUpon>
|
<DependentUpon>text-base.d.ts</DependentUpon>
|
||||||
</TypeScriptCompile>
|
</TypeScriptCompile>
|
||||||
<TypeScriptCompile Include="ui\text-view\text-view-common.ts">
|
<TypeScriptCompile Include="ui\text-view\text-view-common.ts">
|
||||||
@@ -2201,7 +2207,7 @@
|
|||||||
<SaveServerSettingsInUserFile>False</SaveServerSettingsInUserFile>
|
<SaveServerSettingsInUserFile>False</SaveServerSettingsInUserFile>
|
||||||
</WebProjectProperties>
|
</WebProjectProperties>
|
||||||
</FlavorProperties>
|
</FlavorProperties>
|
||||||
<UserProperties ui_2scroll-view_2package_1json__JSONSchema="http://json.schemastore.org/package" apps_2editable-text-demo_2package_1json__JSONSchema="http://json.schemastore.org/package" apps_2absolute-layout-demo_2package_1json__JSONSchema="http://json.schemastore.org/package" apps_2gallery-app_2package_1json__JSONSchema="http://json.schemastore.org/package" ui_2content-view_2package_1json__JSONSchema="http://json.schemastore.org/package" ui_2web-view_2package_1json__JSONSchema="http://json.schemastore.org/package" ui_2layouts_2absolute-layout_2package_1json__JSONSchema="http://json.schemastore.org/package" ui_2layouts_2dock-layout_2package_1json__JSONSchema="" ui_2layouts_2grid-layout_2package_1json__JSONSchema="" ui_2layouts_2wrap-layout_2package_1json__JSONSchema="http://json.schemastore.org/package" />
|
<UserProperties ui_2layouts_2wrap-layout_2package_1json__JSONSchema="http://json.schemastore.org/package" ui_2layouts_2grid-layout_2package_1json__JSONSchema="" ui_2layouts_2dock-layout_2package_1json__JSONSchema="" ui_2layouts_2absolute-layout_2package_1json__JSONSchema="http://json.schemastore.org/package" ui_2web-view_2package_1json__JSONSchema="http://json.schemastore.org/package" ui_2content-view_2package_1json__JSONSchema="http://json.schemastore.org/package" apps_2gallery-app_2package_1json__JSONSchema="http://json.schemastore.org/package" apps_2absolute-layout-demo_2package_1json__JSONSchema="http://json.schemastore.org/package" apps_2editable-text-demo_2package_1json__JSONSchema="http://json.schemastore.org/package" ui_2scroll-view_2package_1json__JSONSchema="http://json.schemastore.org/package" />
|
||||||
</VisualStudio>
|
</VisualStudio>
|
||||||
</ProjectExtensions>
|
</ProjectExtensions>
|
||||||
</Project>
|
</Project>
|
||||||
@@ -659,11 +659,13 @@
|
|||||||
"ui/tab-view/tab-view.android.ts",
|
"ui/tab-view/tab-view.android.ts",
|
||||||
"ui/tab-view/tab-view.d.ts",
|
"ui/tab-view/tab-view.d.ts",
|
||||||
"ui/tab-view/tab-view.ios.ts",
|
"ui/tab-view/tab-view.ios.ts",
|
||||||
|
"ui/text-base/text-base-common.ts",
|
||||||
"ui/text-base/text-base-styler.android.ts",
|
"ui/text-base/text-base-styler.android.ts",
|
||||||
"ui/text-base/text-base-styler.d.ts",
|
"ui/text-base/text-base-styler.d.ts",
|
||||||
"ui/text-base/text-base-styler.ios.ts",
|
"ui/text-base/text-base-styler.ios.ts",
|
||||||
|
"ui/text-base/text-base.android.ts",
|
||||||
"ui/text-base/text-base.d.ts",
|
"ui/text-base/text-base.d.ts",
|
||||||
"ui/text-base/text-base.ts",
|
"ui/text-base/text-base.ios.ts",
|
||||||
"ui/text-field/text-field-common.ts",
|
"ui/text-field/text-field-common.ts",
|
||||||
"ui/text-field/text-field.android.ts",
|
"ui/text-field/text-field.android.ts",
|
||||||
"ui/text-field/text-field.d.ts",
|
"ui/text-field/text-field.d.ts",
|
||||||
|
|||||||
@@ -99,41 +99,22 @@ export class Button extends view.View implements definition.Button {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private onFormattedTextChanged(eventData: observable.PropertyChangeData) {
|
private onFormattedTextChanged(eventData: observable.PropertyChangeData) {
|
||||||
this.setFormattedTextPropertyToNative(eventData.value);
|
this._setFormattedTextPropertyToNative(eventData.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public _onTextPropertyChanged(data: dependencyObservable.PropertyChangeData) {
|
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) {
|
public _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 _onFormattedTextPropertyChanged(data: dependencyObservable.PropertyChangeData) {
|
public _onFormattedTextPropertyChanged(data: dependencyObservable.PropertyChangeData) {
|
||||||
if (data.newValue) {
|
if (data.newValue) {
|
||||||
(<formattedString.FormattedString>data.newValue).parent = this;
|
(<formattedString.FormattedString>data.newValue).parent = this;
|
||||||
}
|
}
|
||||||
this.setFormattedTextPropertyToNative(data.newValue);
|
this._setFormattedTextPropertyToNative(data.newValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
public _addChildFromBuilder(name: string, value: any): void {
|
public _addChildFromBuilder(name: string, value: any): void {
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import common = require("./button-common");
|
import common = require("./button-common");
|
||||||
import utils = require("utils/utils")
|
import utils = require("utils/utils")
|
||||||
|
import dependencyObservable = require("ui/core/dependency-observable");
|
||||||
|
|
||||||
global.moduleMerge(common, exports);
|
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.
|
* @param value - Value of the element.
|
||||||
*/
|
*/
|
||||||
_addChildFromBuilder(name: string, value: any): void;
|
_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 view = require("ui/core/view");
|
||||||
import utils = require("utils/utils");
|
import utils = require("utils/utils");
|
||||||
import enums = require("ui/enums");
|
import enums = require("ui/enums");
|
||||||
|
import dependencyObservable = require("ui/core/dependency-observable");
|
||||||
|
|
||||||
class TapHandlerImpl extends NSObject {
|
class TapHandlerImpl extends NSObject {
|
||||||
private _owner: WeakRef<Button>;
|
private _owner: WeakRef<Button>;
|
||||||
@@ -49,6 +50,23 @@ export class Button extends common.Button {
|
|||||||
get ios(): UIButton {
|
get ios(): UIButton {
|
||||||
return this._ios;
|
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 {
|
export class ButtonStyler implements style.Styler {
|
||||||
|
|||||||
@@ -1161,4 +1161,8 @@ export class View extends ProxyObject implements definition.View {
|
|||||||
public _setNativeViewFrame(nativeView: any, frame: any) {
|
public _setNativeViewFrame(nativeView: any, frame: any) {
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public _onStylePropertyChanged(property: Property): void {
|
||||||
|
//
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
1
ui/core/view.d.ts
vendored
1
ui/core/view.d.ts
vendored
@@ -555,6 +555,7 @@ declare module "ui/core/view" {
|
|||||||
_nativeView: any;
|
_nativeView: any;
|
||||||
_isVisible: boolean;
|
_isVisible: boolean;
|
||||||
_setNativeViewFrame(nativeView: any, frame: any): void;
|
_setNativeViewFrame(nativeView: any, frame: any): void;
|
||||||
|
_onStylePropertyChanged(property: dependencyObservable.Property): void;
|
||||||
//@endprivate
|
//@endprivate
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -861,6 +861,8 @@ export class Style extends DependencyObservable implements styling.Style {
|
|||||||
} else {
|
} else {
|
||||||
(<any>handler).applyProperty(property, this._view, newValue);
|
(<any>handler).applyProperty(property, this._view, newValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this._view._onStylePropertyChanged(property);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (ex) {
|
catch (ex) {
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
import definition = require("ui/text-base");
|
import definition = require("ui/text-base");
|
||||||
import view = require("ui/core/view");
|
import view = require("ui/core/view");
|
||||||
import types = require("utils/types");
|
|
||||||
import observable = require("data/observable");
|
import observable = require("data/observable");
|
||||||
import dependencyObservable = require("ui/core/dependency-observable");
|
import dependencyObservable = require("ui/core/dependency-observable");
|
||||||
import proxy = require("ui/core/proxy");
|
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) {
|
private onFormattedTextChanged(eventData: observable.PropertyChangeData) {
|
||||||
this.setFormattedTextPropertyToNative(eventData.value);
|
this._setFormattedTextPropertyToNative(eventData.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public _onTextPropertyChanged(data: dependencyObservable.PropertyChangeData) {
|
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) {
|
public _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 _onFormattedTextPropertyChanged(data: dependencyObservable.PropertyChangeData) {
|
public _onFormattedTextPropertyChanged(data: dependencyObservable.PropertyChangeData) {
|
||||||
if (data.newValue) {
|
if (data.newValue) {
|
||||||
(<formattedString.FormattedString>data.newValue).parent = this;
|
(<formattedString.FormattedString>data.newValue).parent = this;
|
||||||
}
|
}
|
||||||
this.setFormattedTextPropertyToNative(data.newValue);
|
this._setFormattedTextPropertyToNative(data.newValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
public _addChildFromBuilder(name: string, value: any): void {
|
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;
|
formattedText: formattedString.FormattedString;
|
||||||
|
|
||||||
_onTextPropertyChanged(data: dependencyObservable.PropertyChangeData);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called for every child element declared in xml.
|
* Called for every child element declared in xml.
|
||||||
* This method will add a child element (value) to current element.
|
* This method will add a child element (value) to current element.
|
||||||
@@ -49,6 +47,11 @@
|
|||||||
* @param value - Value of the element.
|
* @param value - Value of the element.
|
||||||
*/
|
*/
|
||||||
_addChildFromBuilder(name: string, value: any): void;
|
_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