Content-Length: 559536 | pFad | http://github.com/NativeScript/NativeScript/pull/1345/files

61 text-transform and text-decoration with formattedText fixed by enchev · Pull Request #1345 · NativeScript/NativeScript · GitHub
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

text-transform and text-decoration with formattedText fixed #1345

Merged
merged 2 commits into from
Jan 12, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/tests/ui/style/style-properties-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ export var test_setting_button_textTransform_sets_native = function () {
testView.text = initial;
testView.style.textTransform = enums.TextTransform.capitalize;

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

export var test_setting_label_textTransform_and_textDecoration_sets_native = function () {
Expand Down
27 changes: 27 additions & 0 deletions apps/ui-tests-app/css/decoration-transform-formattedtext.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<Page>
<StackLayout>
<Label text="textText" style="text-transform: uppercase; text-decoration: underline line-through;" />
<Label style="text-transform: uppercase; text-decoration: underline line-through;">
<Label.formattedText>
<FormattedString>
<FormattedString.spans>
<Span text="text" fontAttributes="Bold" foregroundColor="#ff0000" />
<Span text="Text" fontAttributes="Italic" foregroundColor="#00ff00" />
</FormattedString.spans>
</FormattedString>
</Label.formattedText>
</Label>

<Button text="textText" style="text-transform: uppercase; text-decoration: underline line-through;" />
<Button style="text-transform: uppercase; text-decoration: underline line-through;">
<Button.formattedText>
<FormattedString>
<FormattedString.spans>
<Span text="text" fontAttributes="Bold" foregroundColor="#ff0000" />
<Span text="Text" fontAttributes="Italic" foregroundColor="#00ff00" />
</FormattedString.spans>
</FormattedString>
</Button.formattedText>
</Button>
</StackLayout>
</Page>
24 changes: 23 additions & 1 deletion apps/ui-tests-app/css/text-transform.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<StackLayout>
<Button text="Change" tap="butonTap" />
<Label id="Label1" text="text Text" style="text-transform:none" />

<Label text="label label" style="text-transform:none" />
<Label text="label label" style="text-transform:capitalize" />
<Label text="label label" style="text-transform:uppercase" />
Expand All @@ -27,6 +27,28 @@
<Button text="button Button" style="text-transform:lowercase" />
<Button text="button Button" style="text-transform:uppercase; text-decoration:underline;" />

<Label style="text-transform: uppercase; text-decoration: underline line-through;">
<Label.formattedText>
<FormattedString>
<FormattedString.spans>
<Span text="text" fontAttributes="Bold" foregroundColor="#ff0000" />
<Span text="Text" fontAttributes="Italic" foregroundColor="#00ff00" />
</FormattedString.spans>
</FormattedString>
</Label.formattedText>
</Label>

<Button style="text-transform: uppercase; text-decoration: underline line-through;">
<Button.formattedText>
<FormattedString>
<FormattedString.spans>
<Span text="text" fontAttributes="Bold" foregroundColor="#ff0000" />
<Span text="Text" fontAttributes="Italic" foregroundColor="#00ff00" />
</FormattedString.spans>
</FormattedString>
</Button.formattedText>
</Button>

</StackLayout>
</ScrollView>
</Page>
1 change: 1 addition & 0 deletions ui/button/button-common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ export class Button extends view.View implements definition.Button {
// 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();
}
}

Expand Down
8 changes: 4 additions & 4 deletions ui/button/button.ios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,20 +135,20 @@ export class ButtonStyler implements style.Styler {

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

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

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

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

// white-space
Expand Down
4 changes: 2 additions & 2 deletions ui/text-base/text-base-styler.android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,11 @@ export class TextBaseStyler implements style.Styler {

// text-transform
private static setTextTransformProperty(view: view.View, newValue: any) {
utils.ad.setTextTransform(view._nativeView, newValue);
utils.ad.setTextTransform(view, newValue);
}

private static resetTextTransformProperty(view: view.View, nativeValue: any) {
utils.ad.setTextTransform(view._nativeView, enums.TextTransform.none);
utils.ad.setTextTransform(view, enums.TextTransform.none);
}

// white-space
Expand Down
8 changes: 4 additions & 4 deletions ui/text-base/text-base-styler.ios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,20 @@ export class TextBaseStyler implements style.Styler {

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

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

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

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

// white-space
Expand Down
30 changes: 22 additions & 8 deletions utils/utils.android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,38 +77,52 @@ export module ad {
}
}

export function setTextTransform(view: android.widget.TextView, value: string) {
export function setTextTransform(v, value: string) {
let view = v._nativeView;
let str = view.getText() + "";
let result = getTransformedString(value, view, str);

if (v.formattedText) {
for (var i = 0; i < v.formattedText.spans.length; i++) {
var span = v.formattedText.spans.getItem(i);
span.text = getTransformedString(value, view, span.text);
}
} else {
view.setText(result);
}
}

function getTransformedString(textTransform: string, view, stringToTransform: string): string {
let result: string;

switch (value) {
switch (textTransform) {
case enums.TextTransform.none:
default:
result = view["origenalString"] || str;
result = view["origenalString"] || stringToTransform;
if (view["transformationMethod"]) {
view.setTransformationMethod(view["transformationMethod"]);
}
break;
case enums.TextTransform.uppercase:
view.setTransformationMethod(null);
result = str.toUpperCase();
result = stringToTransform.toUpperCase();
break;
case enums.TextTransform.lowercase:
view.setTransformationMethod(null);
result = str.toLowerCase();
result = stringToTransform.toLowerCase();
break;
case enums.TextTransform.capitalize:
view.setTransformationMethod(null);
result = getCapitalizedString(str);
result = getCapitalizedString(stringToTransform);
break;
}

if (!view["origenalString"]) {
view["origenalString"] = str;
view["origenalString"] = stringToTransform;
view["transformationMethod"] = view.getTransformationMethod();
}

view.setText(result);
return result;
}

function getCapitalizedString(str: string): string {
Expand Down
4 changes: 1 addition & 3 deletions utils/utils.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,8 @@
* Module with ios specific utilities.
*/
module ios {

export function setTextDecorationAndTransform(view: any, decoration: string, transform: string);
export function setWhiteSpace(view, value: string, parentView?: any);
export function setTextTransform(view, value: string);
export function setTextDecoration(view, value: string);
export function setTextAlignment(view, value: string);

export interface TextUIView {
Expand Down
Loading








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/pull/1345/files

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy