This repository has been archived by the owner on Sep 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 26
Android: add onTextLayout
listener on the TextView component
#912
Merged
jmartinesp
merged 2 commits into
main
from
feature/jme/android-add-on-text-layout-lambda
Dec 26, 2023
Merged
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,8 +2,8 @@ package io.element.android.wysiwyg | |
|
||
import android.content.Context | ||
import android.graphics.Canvas | ||
import android.text.Layout | ||
import android.text.Spanned | ||
import android.text.style.ClickableSpan | ||
import android.text.style.URLSpan | ||
import android.util.AttributeSet | ||
import android.view.GestureDetector | ||
|
@@ -21,7 +21,6 @@ import io.element.android.wysiwyg.view.StyleConfig | |
import io.element.android.wysiwyg.view.inlinebg.SpanBackgroundHelper | ||
import io.element.android.wysiwyg.view.inlinebg.SpanBackgroundHelperFactory | ||
import io.element.android.wysiwyg.view.spans.CustomMentionSpan | ||
import io.element.android.wysiwyg.view.spans.LinkSpan | ||
import io.element.android.wysiwyg.view.spans.PillSpan | ||
import io.element.android.wysiwyg.view.spans.ReuseSourceSpannableFactory | ||
import uniffi.wysiwyg_composer.MentionDetector | ||
|
@@ -63,6 +62,8 @@ open class EditorStyledTextView : AppCompatTextView { | |
|
||
var onLinkClickedListener: ((String) -> Unit)? = null | ||
|
||
var onTextLayoutChanged: ((Layout) -> Unit)? = null | ||
|
||
/** | ||
* In some contexts, such as screenshot tests, [isInEditMode] is may be forced to be false, when we | ||
* need it to be true to disable native library loading. With this we can override this behaviour. | ||
|
@@ -158,6 +159,12 @@ open class EditorStyledTextView : AppCompatTextView { | |
htmlConverter?.fromHtmlToSpans(htmlText)?.let { setText(it, BufferType.SPANNABLE) } | ||
} | ||
|
||
override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) { | ||
super.onMeasure(widthMeasureSpec, heightMeasureSpec) | ||
|
||
layout?.let { onTextLayoutChanged?.invoke(it) } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here the text has already been measured so we can return |
||
} | ||
|
||
override fun onDraw(canvas: Canvas) { | ||
// need to draw bg first so that text can be on top during super.onDraw() | ||
if (text is Spanned && layout != null && isInit) { | ||
|
5 changes: 4 additions & 1 deletion
5
platforms/android/library/src/main/java/io/element/android/wysiwyg/utils/RustCleanerTask.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,16 @@ | ||
package io.element.android.wysiwyg.utils | ||
|
||
import io.element.android.wysiwyg.BuildConfig | ||
import timber.log.Timber | ||
import uniffi.wysiwyg_composer.Disposable | ||
|
||
internal class RustCleanerTask( | ||
private val disposable: Disposable, | ||
) : Runnable { | ||
override fun run() { | ||
Timber.d("Cleaning up disposable: $disposable") | ||
if (BuildConfig.DEBUG) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added this because the debug logs added here were being printed by the EXA app in debug mode. I could also remove the log completely. |
||
Timber.d("Cleaning up disposable: $disposable") | ||
} | ||
disposable.destroy() | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason why the parameter is not called
onTextLayoutChanged
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not really, I think I just missed the mismatch here.