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

Add inlineContentOverride #5

Merged
merged 3 commits into from
Feb 9, 2024
Merged

Add inlineContentOverride #5

merged 3 commits into from
Feb 9, 2024

Conversation

gpeal
Copy link

@gpeal gpeal commented Feb 9, 2024

I split out content override and inline content override for overriding inline and block content independently because they have slightly different rendering paths.

I also change the way images with links works. Check my PR comments for more info.

}
) {
if (contentOverride?.invoke(this@computeRichTextString, currentNode) {} != true) {
val parentDestination = currentNode.links.firstParentOrNull<AstLink>()?.destination
Copy link
Author

Choose a reason for hiding this comment

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

I removed the one-off parent link handling for RemoteImage. It was actually fixed by the offset bug below.

@@ -50,10 +50,10 @@ public fun RichTextScope.Text(
overflow = overflow,
maxLines = maxLines,
isOffsetClickable = { offset ->
annotated.getConsumableAnnotations(text.formatObjects, offset).any()
annotated.getConsumableAnnotations(text.formatObjects, offset.coerceIn(0, annotated.length - 1)).any()
Copy link
Author

Choose a reason for hiding this comment

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

offset was 1 when clicking the right half of the image. By coercing offset into the string length, the entire child content of a link becomes clickable. @halilozercan is going to do a sanity check but I couldn't find any new issues that this caused.

Choose a reason for hiding this comment

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

This looks ok. The problem stems from getOffsetForPosition call which can return the length of the text to signify where the caret should be placed. Coercing the offset into actual character indices range should be ok in Image scenario. The only issue I can see with this approach is links that are placed at the very end of a paragraph. In that case, clicking end padding (the place where the text ends but text layout rectangle still occupies the screen) can trigger a link click. That may not be ideal.

@@ -28,7 +28,6 @@ private val DEFAULT_IMAGE_SIZE = 64.dp
internal actual fun RemoteImage(
url: String,
contentDescription: String?,
onClick: (() -> Unit)?,
Copy link
Author

Choose a reason for hiding this comment

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

See below for why this was removed.

@gpeal gpeal marked this pull request as ready for review February 9, 2024 18:08
@gpeal gpeal merged commit 5331b6d into main Feb 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants