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

feat(android): more attributedString link features #13928

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

m1ga
Copy link
Contributor

@m1ga m1ga commented Oct 3, 2023

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]);

@@ -484,6 +484,10 @@ public void processProperties(KrollDict d)
}
}

if (d.containsKey("linkColor")) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is an iOS-only attribute ATTRIBUTE_UNDERLINE_COLOR right now, the parity would be awesome here!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should already be there. The label part is for autoLink (Android only property) that will convert http links to clickable links

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants