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 2 commits into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -296,11 +296,15 @@ public static Bundle toSpannableInBundle(AttributedStringProxy attrString, Activ
spannableText.setSpan(urlColorSpan, range[0], range[0] + range[1],
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

final UnderlineColorSpan[] underlineSpans = spannableText.getSpans(
range[0], range[0] + range[1], UnderlineColorSpan.class);
if (underlineSpans.length > 0) {
if (TiConvert.toBoolean(attr.getProperty("underline"), true)) {
final UnderlineColorSpan[] underlineSpans = spannableText.getSpans(
range[0], range[0] + range[1], UnderlineColorSpan.class);
if (underlineSpans.length > 0) {

// Disable link underline, allow override with our underline color.
// Disable link underline, allow override with our underline color.
urlColorSpan.setUnderline(false);
}
} else {
urlColorSpan.setUnderline(false);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,10 @@ public void processProperties(KrollDict d)
}
}

if (d.containsKey("linkColor")) {
m1ga marked this conversation as resolved.
Show resolved Hide resolved
tv.setLinkTextColor(TiConvert.toColor(d.getString("linkColor"), TiApplication.getAppCurrentActivity()));
}

// This needs to be the last operation.
updateLabelText();
tv.invalidate();
Expand Down
87 changes: 47 additions & 40 deletions apidoc/Titanium/UI/Attribute.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ properties:
On Android, only the following constants are supported
Titanium.UI.ATTRIBUTE_FONT, Titanium.UI.ATTRIBUTE_FOREGROUND_COLOR,
Titanium.UI.ATTRIBUTE_BACKGROUND_COLOR, Titanium.UI.ATTRIBUTE_STRIKETHROUGH_STYLE,
Titanium.UI.ATTRIBUTE_UNDERLINES_STYLE, Titanium.UI.ATTRIBUTE_LINK,
Titanium.UI.ATTRIBUTE_UNDERLINES_STYLE, Titanium.UI.ATTRIBUTE_LINK,
Titanium.UI.ATTRIBUTE_UNDERLINE_COLOR

ON iOS, Titanium.UI.ATTRIBUTE_LINK only supported on <Titanium.UI.TextArea>, with
editable set to false and autoLink enabled.
type: Number
constants: [ Titanium.UI.ATTRIBUTE_FONT, Titanium.UI.ATTRIBUTE_FOREGROUND_COLOR,
Titanium.UI.ATTRIBUTE_BACKGROUND_COLOR, Titanium.UI.ATTRIBUTE_STRIKETHROUGH_STYLE,
Titanium.UI.ATTRIBUTE_UNDERLINES_STYLE, Titanium.UI.ATTRIBUTE_LINK,
Titanium.UI.ATTRIBUTE_UNDERLINES_STYLE, Titanium.UI.ATTRIBUTE_LINK,
Titanium.UI.ATTRIBUTE_UNDERLINE_COLOR, Titanium.UI.ATTRIBUTE_LIGATURE,
Titanium.UI.ATTRIBUTE_KERN, Titanium.UI.ATTRIBUTE_STROKE_COLOR,
Titanium.UI.ATTRIBUTE_STROKE_WIDTH, Titanium.UI.ATTRIBUTE_SHADOW,
Expand Down Expand Up @@ -91,7 +91,7 @@ properties:
}
```

On IOS, if you use the <Titanium.UI.ATTRIBUTE_PARAGRAPH_STYLE>, the `value` must be ParagraphAttribute.
On IOS, if you use the <Titanium.UI.ATTRIBUTE_PARAGRAPH_STYLE>, the `value` must be ParagraphAttribute.
E.g:
``` js
{
Expand Down Expand Up @@ -120,21 +120,28 @@ properties:
Titanium.UI.ATTRIBUTE_LETTERPRESS_STYLE ]
optional: false
- name: range
summary: Attribute range.
summary: Attribute range.
description: |
This specifies the range of text to apply the property to, as an array of two numbers: `[from, length]`.
type: Array<Number>
optional: false
- name: underline
summary: Enable or disable the `ATTRIBUTE_LINK` underline.
description: |
Default value is `true`. If set to false and you use a `ATTRIBUTE_LINK` it won't underline the link.
type: Boolean
platforms: [android]
since: "12.3.0"

---
name: ParagraphAttribute
summary: An abstract datatype for specifying an Paragraph style attribute.
description: |
Attributes are added corresponding to value to create paragraph style,
which when used with attributed string will give styled text.
Attributes are added corresponding to value to create paragraph style,
which when used with attributed string will give styled text.
platforms: [iphone, ipad, macos]
since: "7.5.0"

properties:
- name: alignment
summary: The text alignment of the receiver.
Expand All @@ -144,25 +151,25 @@ properties:
- name: firstLineHeadIndent
summary: The indentation of the first line of the receiver.
description: |
This property contains the distance (in points) from the leading margin
of a text container to the beginning of the first line of paragraph.
This property contains the distance (in points) from the leading margin
of a text container to the beginning of the first line of paragraph.
This value is always nonnegative float value or dimension string (e.g. '10px').
type: [Number,String]

- name: headIndent
summary: The indentation of the lines of lines other than the first.
description: |
This property contains the distance (in points) from the leading margin
of a text container to the beginning of lines other than the first.
This property contains the distance (in points) from the leading margin
of a text container to the beginning of lines other than the first.
This value is always nonnegative float value or dimension string (e.g. '10px').
type: [Number,String]

- name: tailIndent
summary: The trailing indentation of the receiver.
description: |
If positive, this value is the distance (in points) from the leading margin
(for example, the left margin in left-to-right text). If 0 or negative,
it is the distance (in points) from the trailing margin. This is a float value or
If positive, this value is the distance (in points) from the leading margin
(for example, the left margin in left-to-right text). If 0 or negative,
it is the distance (in points) from the trailing margin. This is a float value or
dimension string (e.g. '10px').
type: [Number,String]

Expand All @@ -176,75 +183,75 @@ properties:
- name: maximumLineHeight
summary: The maximum line height of receiver.
description: |
This property contains the maximum height in points that any line in the receiver will occupy,
regardless of the font size or size of any attached graphic. This value is always nonnegative
float value or dimension string (e.g. '10px'). The default value is 0.
Glyphs and graphics exceeding this height will overlap neighboring lines; however, a maximum
height of 0 implies no line height limit. Although this limit applies to the line itself,
This property contains the maximum height in points that any line in the receiver will occupy,
regardless of the font size or size of any attached graphic. This value is always nonnegative
float value or dimension string (e.g. '10px'). The default value is 0.
Glyphs and graphics exceeding this height will overlap neighboring lines; however, a maximum
height of 0 implies no line height limit. Although this limit applies to the line itself,
line spacing adds extra space between adjacent lines.
type: [Number,String]

- name: minimumLineHeight
summary: The minimum height of receiver.
description: |
This property contains the minimum height in points that any line in the receiver will occupy,
regardless of the font size or size of any attached graphic. This value must be nonnegative float value
This property contains the minimum height in points that any line in the receiver will occupy,
regardless of the font size or size of any attached graphic. This value must be nonnegative float value
or dimension string (e.g. '10px').
E.g. If you have set minimum height 30 and font size 10. It will make line height 30 which have
smaller text size and more vertical sapcing between text.
E.g. If you have set minimum height 30 and font size 10. It will make line height 30 which have
smaller text size and more vertical sapcing between text.
type: [Number,String]

- name: lineSpacing
summary: The distance in points between the bottom of one line fragment and the top of the next.
description: |
This value is always nonnegative float value or dimension string (e.g. '10px'). This value is
This value is always nonnegative float value or dimension string (e.g. '10px'). This value is
included in the line fragment heights in the layout manager.
type: [Number,String]

- name: paragraphSpacingAfter
summary: The space after the end of the paragraph.
description: |
This property contains the space (measured in points) added at the end of the paragraph
to separate it from the following paragraph. This value must be nonnegative float value or
dimension string (e.g. '10px'). The space between paragraphs is determined by adding the paragraphSpacingAfter
This property contains the space (measured in points) added at the end of the paragraph
to separate it from the following paragraph. This value must be nonnegative float value or
dimension string (e.g. '10px'). The space between paragraphs is determined by adding the paragraphSpacingAfter
of previous paragraph and the paragraphSpacingBefore of current paragraph.
type: [Number,String]

- name: paragraphSpacingBefore
summary: The distance between the top of paragraph and the beginning of its text content.
description: |
This property contains the space (measured in points) between the top of paragraph and
This property contains the space (measured in points) between the top of paragraph and
the beginning of its text content. This value can be float value or dimension string (e.g. '10px').
The default value of this property is 0.0.
type: [Number,String]

- name: lineHeightMultiple
summary: The line height multiple.
description: |
The natural line height of the receiver is multiplied by this factor (if positive)
before being constrained by minimum and maximum line height. The default value of
The natural line height of the receiver is multiplied by this factor (if positive)
before being constrained by minimum and maximum line height. The default value of
this property is 0.0, which means nothing multiplied.
type: Number

- name: hyphenationFactor
summary: The threshold of paragraph for hyphenation.
description: |
Valid values lie between 0.0 and 1.0 inclusive. The default value is 0.0. Hyphenation
is attempted when the ratio of the text width (as broken without hyphenation) to the
width of the line fragment is less than the hyphenation factor. When the hyphenation
factor of paragraph is 0.0, the hyphenation factor of layout manager is used instead.
When both are 0.0, hyphenation is disabled. This property detects the user-selected
Valid values lie between 0.0 and 1.0 inclusive. The default value is 0.0. Hyphenation
is attempted when the ratio of the text width (as broken without hyphenation) to the
width of the line fragment is less than the hyphenation factor. When the hyphenation
factor of paragraph is 0.0, the hyphenation factor of layout manager is used instead.
When both are 0.0, hyphenation is disabled. This property detects the user-selected
language by examining the first item in preferredLanguages.
type: Number

- name: allowsDefaultTighteningForTruncation
summary: |
A Boolean value indicating whether the system may tighten inter-character spacing
A Boolean value indicating whether the system may tighten inter-character spacing
before truncating text.
description: |
When this property is set to true, the system tries to reduce the space between characters
before truncating characters. The system performs this tightening in cases where the text
would not otherwise fit in the available space. The maximum amount of tightening performed
by the system is dependent on the font, line width, and other factors. The default value of
When this property is set to true, the system tries to reduce the space between characters
before truncating characters. The system performs this tightening in cases where the text
would not otherwise fit in the available space. The maximum amount of tightening performed
by the system is dependent on the font, line width, and other factors. The default value of
this property is false.
type: Boolean
9 changes: 9 additions & 0 deletions apidoc/Titanium/UI/Label.yml
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,15 @@ properties:
For information about color values, see the "Colors" section of <Titanium.UI>.
type: [String, Titanium.UI.Color]

- name: linkColor
summary: Color of the link inside a label, as a color name or hex triplet.
description: |
If you enable `autoLink` on Android or add an AttributedString link it will use this color.
For information about color values, see the "Colors" section of <Titanium.UI>.
type: [String, Titanium.UI.Color]
platforms: [android]
since: "12.3.0"

- name: ellipsize
summary: |
Causes words in the text that are longer than the view is wide to be ellipsized instead of broken in the middle.
Expand Down
3 changes: 3 additions & 0 deletions apidoc/Titanium/UI/UI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,9 @@ properties:
Use the Label's [link](Titanium.UI.Label.link) event to determine when the user triggers a
long press (not a click) event on the linked text.

Use the Label's `linkColor` to change the color (Android only) and your can use `underline: false`
to remove the underline from the link.

See <Attribute> for more information.
type: Number
since: "3.6.0"
Expand Down
Loading