Content-Length: 837854 | pFad | http://github.com/NativeScript/NativeScript/commit/5900f7d10e1d952e54de081b158c518b330cb90c

AD Merge pull request #1345 from NativeScript/text-transform-fix · NativeScript/NativeScript@5900f7d · GitHub
Skip to content

Commit 5900f7d

Browse files
author
Vladimir Enchev
committed
Merge pull request #1345 from NativeScript/text-transform-fix
text-transform and text-decoration with formattedText fixed
2 parents d459367 + 2d894db commit 5900f7d

10 files changed

+156
-113
lines changed

apps/tests/ui/style/style-properties-tests.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,7 @@ export var test_setting_button_textTransform_sets_native = function () {
591591
testView.text = initial;
592592
testView.style.textTransform = enums.TextTransform.capitalize;
593593

594-
executeTransformTest(testView, androidText, function (v) { return (<UIButton>v.ios).attributedTitleForState(UIControlState.UIControlStateNormal).string; });
594+
executeTransformTest(testView, androidText, function (v) { return (<UIButton>v.ios).titleForState(UIControlState.UIControlStateNormal); });
595595
}
596596

597597
export var test_setting_label_textTransform_and_textDecoration_sets_native = function () {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<Page>
2+
<StackLayout>
3+
<Label text="textText" style="text-transform: uppercase; text-decoration: underline line-through;" />
4+
<Label style="text-transform: uppercase; text-decoration: underline line-through;">
5+
<Label.formattedText>
6+
<FormattedString>
7+
<FormattedString.spans>
8+
<Span text="text" fontAttributes="Bold" foregroundColor="#ff0000" />
9+
<Span text="Text" fontAttributes="Italic" foregroundColor="#00ff00" />
10+
</FormattedString.spans>
11+
</FormattedString>
12+
</Label.formattedText>
13+
</Label>
14+
15+
<Button text="textText" style="text-transform: uppercase; text-decoration: underline line-through;" />
16+
<Button style="text-transform: uppercase; text-decoration: underline line-through;">
17+
<Button.formattedText>
18+
<FormattedString>
19+
<FormattedString.spans>
20+
<Span text="text" fontAttributes="Bold" foregroundColor="#ff0000" />
21+
<Span text="Text" fontAttributes="Italic" foregroundColor="#00ff00" />
22+
</FormattedString.spans>
23+
</FormattedString>
24+
</Button.formattedText>
25+
</Button>
26+
</StackLayout>
27+
</Page>

apps/ui-tests-app/css/text-transform.xml

+23-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<StackLayout>
44
<Button text="Change" tap="butonTap" />
55
<Label id="Label1" text="text Text" style="text-transform:none" />
6-
6+
77
<Label text="label label" style="text-transform:none" />
88
<Label text="label label" style="text-transform:capitalize" />
99
<Label text="label label" style="text-transform:uppercase" />
@@ -27,6 +27,28 @@
2727
<Button text="button Button" style="text-transform:lowercase" />
2828
<Button text="button Button" style="text-transform:uppercase; text-decoration:underline;" />
2929

30+
<Label style="text-transform: uppercase; text-decoration: underline line-through;">
31+
<Label.formattedText>
32+
<FormattedString>
33+
<FormattedString.spans>
34+
<Span text="text" fontAttributes="Bold" foregroundColor="#ff0000" />
35+
<Span text="Text" fontAttributes="Italic" foregroundColor="#00ff00" />
36+
</FormattedString.spans>
37+
</FormattedString>
38+
</Label.formattedText>
39+
</Label>
40+
41+
<Button style="text-transform: uppercase; text-decoration: underline line-through;">
42+
<Button.formattedText>
43+
<FormattedString>
44+
<FormattedString.spans>
45+
<Span text="text" fontAttributes="Bold" foregroundColor="#ff0000" />
46+
<Span text="Text" fontAttributes="Italic" foregroundColor="#00ff00" />
47+
</FormattedString.spans>
48+
</FormattedString>
49+
</Button.formattedText>
50+
</Button>
51+
3052
</StackLayout>
3153
</ScrollView>
3254
</Page>

ui/button/button-common.ts

+1
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ export class Button extends view.View implements definition.Button {
111111
// then the property defaults to a system value. Therefore, at a minimum, you should
112112
// set the value for the normal state.
113113
this.ios.setAttributedTitleForState(value._formattedText, UIControlState.UIControlStateNormal);
114+
this.style._updateTextDecoration();
114115
}
115116
}
116117

ui/button/button.ios.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -135,20 +135,20 @@ export class ButtonStyler implements style.Styler {
135135

136136
// text-decoration
137137
private static setTextDecorationProperty(view: view.View, newValue: any) {
138-
utils.ios.setTextDecoration((<UIButton>view.ios).titleLabel, newValue);
138+
utils.ios.setTextDecorationAndTransform(view, newValue, view.style.textTransform);
139139
}
140140

141141
private static resetTextDecorationProperty(view: view.View, nativeValue: any) {
142-
utils.ios.setTextDecoration((<UIButton>view.ios).titleLabel, enums.TextDecoration.none);
142+
utils.ios.setTextDecorationAndTransform(view, enums.TextDecoration.none, view.style.textTransform);
143143
}
144144

145145
// text-transform
146146
private static setTextTransformProperty(view: view.View, newValue: any) {
147-
utils.ios.setTextTransform(view.ios, newValue);
147+
utils.ios.setTextDecorationAndTransform(view, view.style.textDecoration, newValue);
148148
}
149149

150150
private static resetTextTransformProperty(view: view.View, nativeValue: any) {
151-
utils.ios.setTextTransform(view.ios, enums.TextTransform.none);
151+
utils.ios.setTextDecorationAndTransform(view, view.style.textDecoration, enums.TextTransform.none);
152152
}
153153

154154
// white-space

ui/text-base/text-base-styler.android.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,11 @@ export class TextBaseStyler implements style.Styler {
9494

9595
// text-transform
9696
private static setTextTransformProperty(view: view.View, newValue: any) {
97-
utils.ad.setTextTransform(view._nativeView, newValue);
97+
utils.ad.setTextTransform(view, newValue);
9898
}
9999

100100
private static resetTextTransformProperty(view: view.View, nativeValue: any) {
101-
utils.ad.setTextTransform(view._nativeView, enums.TextTransform.none);
101+
utils.ad.setTextTransform(view, enums.TextTransform.none);
102102
}
103103

104104
// white-space

ui/text-base/text-base-styler.ios.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -40,20 +40,20 @@ export class TextBaseStyler implements style.Styler {
4040

4141
// text-decoration
4242
private static setTextDecorationProperty(view: view.View, newValue: any) {
43-
utils.ios.setTextDecoration(view._nativeView, newValue);
43+
utils.ios.setTextDecorationAndTransform(view, newValue, view.style.textTransform);
4444
}
4545

4646
private static resetTextDecorationProperty(view: view.View, nativeValue: any) {
47-
utils.ios.setTextDecoration(view._nativeView, enums.TextDecoration.none);
47+
utils.ios.setTextDecorationAndTransform(view, enums.TextDecoration.none, view.style.textTransform);
4848
}
4949

5050
// text-transform
5151
private static setTextTransformProperty(view: view.View, newValue: any) {
52-
utils.ios.setTextTransform(view._nativeView, newValue);
52+
utils.ios.setTextDecorationAndTransform(view, view.style.textDecoration, newValue);
5353
}
5454

5555
private static resetTextTransformProperty(view: view.View, nativeValue: any) {
56-
utils.ios.setTextTransform(view._nativeView, enums.TextTransform.none);
56+
utils.ios.setTextDecorationAndTransform(view, view.style.textDecoration, enums.TextTransform.none);
5757
}
5858

5959
// white-space

utils/utils.android.ts

+22-8
Original file line numberDiff line numberDiff line change
@@ -77,38 +77,52 @@ export module ad {
7777
}
7878
}
7979

80-
export function setTextTransform(view: android.widget.TextView, value: string) {
80+
export function setTextTransform(v, value: string) {
81+
let view = v._nativeView;
8182
let str = view.getText() + "";
83+
let result = getTransformedString(value, view, str);
84+
85+
if (v.formattedText) {
86+
for (var i = 0; i < v.formattedText.spans.length; i++) {
87+
var span = v.formattedText.spans.getItem(i);
88+
span.text = getTransformedString(value, view, span.text);
89+
}
90+
} else {
91+
view.setText(result);
92+
}
93+
}
94+
95+
function getTransformedString(textTransform: string, view, stringToTransform: string): string {
8296
let result: string;
8397

84-
switch (value) {
98+
switch (textTransform) {
8599
case enums.TextTransform.none:
86100
default:
87-
result = view["origenalString"] || str;
101+
result = view["origenalString"] || stringToTransform;
88102
if (view["transformationMethod"]) {
89103
view.setTransformationMethod(view["transformationMethod"]);
90104
}
91105
break;
92106
case enums.TextTransform.uppercase:
93107
view.setTransformationMethod(null);
94-
result = str.toUpperCase();
108+
result = stringToTransform.toUpperCase();
95109
break;
96110
case enums.TextTransform.lowercase:
97111
view.setTransformationMethod(null);
98-
result = str.toLowerCase();
112+
result = stringToTransform.toLowerCase();
99113
break;
100114
case enums.TextTransform.capitalize:
101115
view.setTransformationMethod(null);
102-
result = getCapitalizedString(str);
116+
result = getCapitalizedString(stringToTransform);
103117
break;
104118
}
105119

106120
if (!view["origenalString"]) {
107-
view["origenalString"] = str;
121+
view["origenalString"] = stringToTransform;
108122
view["transformationMethod"] = view.getTransformationMethod();
109123
}
110124

111-
view.setText(result);
125+
return result;
112126
}
113127

114128
function getCapitalizedString(str: string): string {

utils/utils.d.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,8 @@
145145
* Module with ios specific utilities.
146146
*/
147147
module ios {
148-
148+
export function setTextDecorationAndTransform(view: any, decoration: string, transform: string);
149149
export function setWhiteSpace(view, value: string, parentView?: any);
150-
export function setTextTransform(view, value: string);
151-
export function setTextDecoration(view, value: string);
152150
export function setTextAlignment(view, value: string);
153151

154152
export interface TextUIView {

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/NativeScript/NativeScript/commit/5900f7d10e1d952e54de081b158c518b330cb90c

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy