[AC-5612] iOS: Attribute does not work ATTRIBUTE_STRIKETHROUGH_STYLE
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | n/a |
Status | Resolved |
Resolution | Not Our Bug |
Resolution Date | 2018-02-23T10:39:02.000+0000 |
Affected Version/s | n/a |
Fix Version/s | n/a |
Components | Titanium SDK & CLI |
Labels | apple-restriction, attributedString, ios |
Reporter | Christoph Eck |
Assignee | Hans Knöchel |
Created | 2018-02-22T15:02:44.000+0000 |
Updated | 2018-02-23T10:39:09.000+0000 |
Description
*Problem*
The attribute ATTRIBUTE_STRIKETHROUGH_STYLE does not work on iOS.
_actual behavior_
Run the test case
The items are not striked
_expected behavior_Run the test case
The items are striked
*Test case*
var products = [{
title: "Chips",
},
{
title: "Tomato",
},
];
var templates = {};
templates['item'] = {
properties: {
height: 45,
},
childTemplates: [
{
type: 'Ti.UI.Label',
bindId: 'title',
properties: {
color: "black",
height: 40,
}
},
],
preLayout: function (item) {
Ti.API.info(item.meta.productTitle);
var text = item.meta.productTitle;
var attr = Ti.UI.createAttributedString({
text: text,
attributes: [
{
type: Ti.UI.ATTRIBUTE_STRIKETHROUGH_STYLE,
value: Ti.UI.ATTRIBUTE_UNDERLINE_BY_WORD,
range: [0, text.length]
},
]
});
item.title.attributedString = attr;
//item.title.text = item.meta.productTitle;
return item;
}
};
var items = [];
for (var i = 0; i < products.length; i++) {
product = products[i];
items.push(templates['item'].preLayout({
properties: {
height: 40,
},
template: 'item',
meta: {
productTitle: product.title
},
title: {
},
}));
}
var section = Ti.UI.createListSection();
section.setItems(items);
var listView = Ti.UI.createListView({
backgroundColor: "white",
templates: templates,
sections: [section],
});
var win = Ti.UI.createWindow({
backgroundColor: "white",
});
win.add(listView);
win.open();
Attachments
File | Date | Size |
---|---|---|
index.js | 2018-02-22T15:01:23.000+0000 | 1241 |
test_attr_string.zip | 2018-02-23T10:35:36.000+0000 | 27379 |
Hey [~chris35], does it work with
value: ATTRIBUTE_UNDERLINE_STYLE_SINGLE
? Your example is a bit confusing, since the list-view related parts that take 3/4 of the example are unrelated to attributed strings.Hi @hknoechel The example could be shorter :-) The ATTRIBUTE_UNDERLINE_STYLE_SINGLE does work.
Alright. In that case, I feel like that might be an Apple limitation as we only pass the constants. I'll try to recreate a native example to check this, but likely not this week.
Okay, so I was just able to reproduce the same thing on the native side as well:
NSStrikethroughStyleAttributeName
(Titanium:ATTRIBUTE_STRIKETHROUGH_STYLE
) cannot be combined withNSUnderlineByWord
(Titanium:ATTRIBUTE_UNDERLINE_BY_WORD
), which looks like the expected behavior on the Apple side. If you feel different (like myself too), please file a bug report at Apple (bugreport.apple.com) and maybe they'll add it in later versions of iOS. As a workaround, you could split the text into word fragments (myText.splt(' ')
) and loop through the word fragments to apply the attributes to. Thanks!