Skip to content

Commit bda6159

Browse files
committed
Re-apply TextBase.formattedText after a style property change
Resolves NativeScript#1078
1 parent 026ce23 commit bda6159

File tree

13 files changed

+113
-50
lines changed

13 files changed

+113
-50
lines changed

CrossPlatformModules.csproj

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1666,7 +1666,13 @@
16661666
<DependentUpon>builder.d.ts</DependentUpon>
16671667
</TypeScriptCompile>
16681668
<TypeScriptCompile Include="ui\text-base\text-base.d.ts" />
1669-
<TypeScriptCompile Include="ui\text-base\text-base.ts">
1669+
<TypeScriptCompile Include="ui\text-base\text-base-common.ts">
1670+
<DependentUpon>text-base.d.ts</DependentUpon>
1671+
</TypeScriptCompile>
1672+
<TypeScriptCompile Include="ui\text-base\text-base.ios.ts">
1673+
<DependentUpon>text-base.d.ts</DependentUpon>
1674+
</TypeScriptCompile>
1675+
<TypeScriptCompile Include="ui\text-base\text-base.android.ts">
16701676
<DependentUpon>text-base.d.ts</DependentUpon>
16711677
</TypeScriptCompile>
16721678
<TypeScriptCompile Include="ui\text-view\text-view-common.ts">
@@ -2201,7 +2207,7 @@
22012207
<SaveServerSettingsInUserFile>False</SaveServerSettingsInUserFile>
22022208
</WebProjectProperties>
22032209
</FlavorProperties>
2204-
<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" />
2210+
<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" />
22052211
</VisualStudio>
22062212
</ProjectExtensions>
22072213
</Project>

tsconfig.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -659,11 +659,13 @@
659659
"ui/tab-view/tab-view.android.ts",
660660
"ui/tab-view/tab-view.d.ts",
661661
"ui/tab-view/tab-view.ios.ts",
662+
"ui/text-base/text-base-common.ts",
662663
"ui/text-base/text-base-styler.android.ts",
663664
"ui/text-base/text-base-styler.d.ts",
664665
"ui/text-base/text-base-styler.ios.ts",
666+
"ui/text-base/text-base.android.ts",
665667
"ui/text-base/text-base.d.ts",
666-
"ui/text-base/text-base.ts",
668+
"ui/text-base/text-base.ios.ts",
667669
"ui/text-field/text-field-common.ts",
668670
"ui/text-field/text-field.android.ts",
669671
"ui/text-field/text-field.d.ts",

ui/button/button-common.ts

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -99,41 +99,22 @@ export class Button extends view.View implements definition.Button {
9999
}
100100

101101
private onFormattedTextChanged(eventData: observable.PropertyChangeData) {
102-
this.setFormattedTextPropertyToNative(eventData.value);
102+
this._setFormattedTextPropertyToNative(eventData.value);
103103
}
104104

105105
public _onTextPropertyChanged(data: dependencyObservable.PropertyChangeData) {
106-
if (this.android) {
107-
this.android.setText(data.newValue + "");
108-
}
109-
if (this.ios) {
110-
// In general, if a property is not specified for a state, the default is to use
111-
// the UIControlStateNormal value. If the value for UIControlStateNormal is not set,
112-
// then the property defaults to a system value. Therefore, at a minimum, you should
113-
// set the value for the normal state.
114-
this.ios.setTitleForState(data.newValue + "", UIControlState.UIControlStateNormal);
115-
}
106+
//
116107
}
117108

118-
private setFormattedTextPropertyToNative(value) {
119-
if (this.android) {
120-
this.android.setText(value._formattedText);
121-
}
122-
if (this.ios) {
123-
// In general, if a property is not specified for a state, the default is to use
124-
// the UIControlStateNormal value. If the value for UIControlStateNormal is not set,
125-
// then the property defaults to a system value. Therefore, at a minimum, you should
126-
// set the value for the normal state.
127-
this.ios.setAttributedTitleForState(value._formattedText, UIControlState.UIControlStateNormal);
128-
this.style._updateTextDecoration();
129-
}
109+
public _setFormattedTextPropertyToNative(value) {
110+
//
130111
}
131112

132113
public _onFormattedTextPropertyChanged(data: dependencyObservable.PropertyChangeData) {
133114
if (data.newValue) {
134115
(<formattedString.FormattedString>data.newValue).parent = this;
135116
}
136-
this.setFormattedTextPropertyToNative(data.newValue);
117+
this._setFormattedTextPropertyToNative(data.newValue);
137118
}
138119

139120
public _addChildFromBuilder(name: string, value: any): void {

ui/button/button.android.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import common = require("./button-common");
22
import utils = require("utils/utils")
3+
import dependencyObservable = require("ui/core/dependency-observable");
34

45
global.moduleMerge(common, exports);
56

@@ -36,4 +37,16 @@ export class Button extends common.Button {
3637
}
3738
}));
3839
}
40+
41+
public _onTextPropertyChanged(data: dependencyObservable.PropertyChangeData) {
42+
if (this.android) {
43+
this.android.setText(data.newValue + "");
44+
}
45+
}
46+
47+
public _setFormattedTextPropertyToNative(value) {
48+
if (this.android) {
49+
this.android.setText(value._formattedText);
50+
}
51+
}
3952
}

ui/button/button.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,5 +71,10 @@ declare module "ui/button" {
7171
* @param value - Value of the element.
7272
*/
7373
_addChildFromBuilder(name: string, value: any): void;
74+
75+
//@private
76+
_onTextPropertyChanged(data: dependencyObservable.PropertyChangeData): void;
77+
_setFormattedTextPropertyToNative(value: any): void;
78+
//@endprivate
7479
}
7580
}

ui/button/button.ios.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import font = require("ui/styling/font");
55
import view = require("ui/core/view");
66
import utils = require("utils/utils");
77
import enums = require("ui/enums");
8+
import dependencyObservable = require("ui/core/dependency-observable");
89

910
class TapHandlerImpl extends NSObject {
1011
private _owner: WeakRef<Button>;
@@ -49,6 +50,23 @@ export class Button extends common.Button {
4950
get ios(): UIButton {
5051
return this._ios;
5152
}
53+
54+
public _onTextPropertyChanged(data: dependencyObservable.PropertyChangeData) {
55+
// In general, if a property is not specified for a state, the default is to use
56+
// the UIControlStateNormal value. If the value for UIControlStateNormal is not set,
57+
// then the property defaults to a system value. Therefore, at a minimum, you should
58+
// set the value for the normal state.
59+
this.ios.setTitleForState(data.newValue + "", UIControlState.UIControlStateNormal);
60+
}
61+
62+
public _setFormattedTextPropertyToNative(value) {
63+
// In general, if a property is not specified for a state, the default is to use
64+
// the UIControlStateNormal value. If the value for UIControlStateNormal is not set,
65+
// then the property defaults to a system value. Therefore, at a minimum, you should
66+
// set the value for the normal state.
67+
this.ios.setAttributedTitleForState(value._formattedText, UIControlState.UIControlStateNormal);
68+
this.style._updateTextDecoration();
69+
}
5270
}
5371

5472
export class ButtonStyler implements style.Styler {

ui/core/view-common.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1161,4 +1161,8 @@ export class View extends ProxyObject implements definition.View {
11611161
public _setNativeViewFrame(nativeView: any, frame: any) {
11621162
//
11631163
}
1164+
1165+
public _onStylePropertyChanged(property: Property): void {
1166+
//
1167+
}
11641168
}

ui/core/view.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,7 @@ declare module "ui/core/view" {
555555
_nativeView: any;
556556
_isVisible: boolean;
557557
_setNativeViewFrame(nativeView: any, frame: any): void;
558+
_onStylePropertyChanged(property: dependencyObservable.Property): void;
558559
//@endprivate
559560
}
560561

ui/styling/style.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -861,6 +861,8 @@ export class Style extends DependencyObservable implements styling.Style {
861861
} else {
862862
(<any>handler).applyProperty(property, this._view, newValue);
863863
}
864+
865+
this._view._onStylePropertyChanged(property);
864866
}
865867
}
866868
catch (ex) {
Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import definition = require("ui/text-base");
22
import view = require("ui/core/view");
3-
import types = require("utils/types");
43
import observable = require("data/observable");
54
import dependencyObservable = require("ui/core/dependency-observable");
65
import proxy = require("ui/core/proxy");
@@ -97,37 +96,22 @@ export class TextBase extends view.View implements definition.TextBase, formatte
9796
}
9897

9998
private onFormattedTextChanged(eventData: observable.PropertyChangeData) {
100-
this.setFormattedTextPropertyToNative(eventData.value);
99+
this._setFormattedTextPropertyToNative(eventData.value);
101100
}
102101

103102
public _onTextPropertyChanged(data: dependencyObservable.PropertyChangeData) {
104-
var newValue = types.isNullOrUndefined(data.newValue) ? "" : data.newValue + "";
105-
if (this.android) {
106-
this.android.setText(newValue);
107-
}
108-
else if (this.ios) {
109-
this.ios.text = newValue;
110-
this.style._updateTextDecoration();
111-
this.style._updateTextTransform();
112-
}
103+
//
113104
}
114105

115-
private setFormattedTextPropertyToNative(value) {
116-
if (this.android) {
117-
this.android.setText(value._formattedText);
118-
} else if (this.ios) {
119-
this.ios.attributedText = value._formattedText;
120-
this.style._updateTextDecoration();
121-
this.style._updateTextTransform();
122-
this.requestLayout();
123-
}
106+
public _setFormattedTextPropertyToNative(value) {
107+
//
124108
}
125109

126110
public _onFormattedTextPropertyChanged(data: dependencyObservable.PropertyChangeData) {
127111
if (data.newValue) {
128112
(<formattedString.FormattedString>data.newValue).parent = this;
129113
}
130-
this.setFormattedTextPropertyToNative(data.newValue);
114+
this._setFormattedTextPropertyToNative(data.newValue);
131115
}
132116

133117
public _addChildFromBuilder(name: string, value: any): void {

0 commit comments

Comments
 (0)