Titanium JIRA Archive
Appcelerator Community (AC)

[AC-5612] iOS: Attribute does not work ATTRIBUTE_STRIKETHROUGH_STYLE

GitHub Issuen/a
TypeBug
Priorityn/a
StatusResolved
ResolutionNot Our Bug
Resolution Date2018-02-23T10:39:02.000+0000
Affected Version/sn/a
Fix Version/sn/a
ComponentsTitanium SDK & CLI
Labelsapple-restriction, attributedString, ios
ReporterChristoph Eck
AssigneeHans Knöchel
Created2018-02-22T15:02:44.000+0000
Updated2018-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

FileDateSize
index.js2018-02-22T15:01:23.000+00001241
test_attr_string.zip2018-02-23T10:35:36.000+000027379

Comments

  1. Hans Knöchel 2018-02-22

    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.
  2. Christoph Eck 2018-02-22

    Hi @hknoechel The example could be shorter :-) The ATTRIBUTE_UNDERLINE_STYLE_SINGLE does work.
  3. Hans Knöchel 2018-02-22

    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.
  4. Hans Knöchel 2018-02-23

    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 with NSUnderlineByWord (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!

JSON Source