titanium-sdk icon indicating copy to clipboard operation
titanium-sdk copied to clipboard

feat(android): more attributedString link features

Open m1ga opened this issue 2 years ago • 0 comments

Currently the attributedString link is not very flexible in terms of color and removing the underline.

This PR adds two new features:

  • linkColor for the label: allows to set the color of the autoLink or attributedString link. Note: currently we can use another attribute Ti.UI.ATTRIBUTE_FOREGROUND_COLOR to color the link. This works for both Android and iOS. But there is not way to color a link with autoLink (Android only). So we won't need iOS parity for this property.

  • a new attribute underline in the attributedString that can be used in combination with type: Titanium.UI.ATTRIBUTE_LINK to remove the underline from the link

Screenshot_20231003-181037

var win = Titanium.UI.createWindow({
	layout: "vertical"
});
win.open();
var text = 'just one link';

var attr = Titanium.UI.createAttributedString({
	text: text,
	attributes: [{
		type: Titanium.UI.ATTRIBUTE_LINK,
		value: "https://titaniumsdk.com",
		range: [text.indexOf('one'), ('one').length],
		underline: false
	}]
});

// custom link color - attributedString
var label = Titanium.UI.createLabel({
	height: Titanium.UI.SIZE,
	attributedString: attr,
	linkColor: "red"
});

// custom link color - autoLink
var label2 = Titanium.UI.createLabel({
	height: Titanium.UI.SIZE,
	text: " this is a https://titaniumsdk.com test",
	linkColor: "blue",
	autoLink: true
});

// current default link color
var label3 = Titanium.UI.createLabel({
	height: Titanium.UI.SIZE,
	text: " this is a https://titaniumsdk.com test",
	autoLink: true
});

win.add([label, label2, label3]);

m1ga avatar Oct 03 '23 16:10 m1ga