AliSoftware / AliSoftware/OHAttributedLabel

Cannot activate link within a truncation character

Aberta
#17 0 comentários 0 reações 0 responsáveis Ver no GitHub
Issue
Linguagem predominante
Objective-C
Estrelas
1.5k
Forks
341
Métricas de merge de PRs
Nenhum PR com merge em 30d

Descrição

This may be an issue with CoreText, and probably will not affect many people. However, for our purposes it was necessary to find a workaround since we are using OHAttributedLabel to render fixed-width columns of links with truncation.

For example, tapping the … if this were in an OHAttributedLabel would not fire the link:
Visit [AliSoft…e GitHub](https://github.com/AliSoftware)!

The problem is that `CTLineGetStringIndexForPosition` gives an index of either 0 or 1 when `linkAtPoint:` is given a point corresponding to a truncation character like the ubiquitous … ellipsis. This is not entirely mysterious since the ellipsis is not actually in the string and may represent multiple character indices, but there does not seem to be any documentation specifying what output to expect and why.

Both 0 and 1 are valid indices, but only for the first line. After validating that the click is inside the current line, we added a test like this to determine if the position reported for the line is wrong based on the line's range in the attributed string:

```
CFRange range = CTLineGetStringRange(line);
CFIndex idx = CTLineGetStringIndexForPosition(line, relativePoint);
if (idx < range.location) {
// Fix invalid index
}
```

Before this workaround, all taps over a truncation character anywhere in the list would activate the link at index 0 or 1 in the string. For our purposes, I simply choose a position in the line based on its range that is guaranteed to be in the link. Another option might be to test horizontally adjacent points until a link is hit. That may not be a general-purpose solution, and this issue report is more to offer awareness of the issue than to request any general fix.

Guia de contribuição

Nenhum guia de contribuição indexado para este repositório

Avaliação

Esta issue ainda não foi avaliada.

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.