diff --git a/platforms/android/library-compose/src/main/java/io/element/android/wysiwyg/compose/EditorStyledText.kt b/platforms/android/library-compose/src/main/java/io/element/android/wysiwyg/compose/EditorStyledText.kt index e132b8c5f..3f050eaea 100644 --- a/platforms/android/library-compose/src/main/java/io/element/android/wysiwyg/compose/EditorStyledText.kt +++ b/platforms/android/library-compose/src/main/java/io/element/android/wysiwyg/compose/EditorStyledText.kt @@ -1,5 +1,6 @@ package io.element.android.wysiwyg.compose +import android.text.Layout import android.text.Spanned import android.widget.TextView import androidx.compose.runtime.Composable @@ -34,6 +35,7 @@ fun EditorStyledText( resolveMentionDisplay: (text: String, url: String) -> TextDisplay = RichTextEditorDefaults.MentionDisplay, resolveRoomMentionDisplay: () -> TextDisplay = RichTextEditorDefaults.RoomMentionDisplay, onLinkClickedListener: ((String) -> Unit) = {}, + onTextLayout: (Layout) -> Unit = {}, style: RichTextEditorStyle = RichTextEditorDefaults.style(), ) { val typeface by style.text.rememberTypeface() @@ -67,6 +69,7 @@ fun EditorStyledText( view.setHtml(text.toString()) } view.onLinkClickedListener = onLinkClickedListener + view.onTextLayout = onTextLayout } ) } diff --git a/platforms/android/library/src/main/java/io/element/android/wysiwyg/EditorStyledTextView.kt b/platforms/android/library/src/main/java/io/element/android/wysiwyg/EditorStyledTextView.kt index b074e61be..f9ea6629e 100644 --- a/platforms/android/library/src/main/java/io/element/android/wysiwyg/EditorStyledTextView.kt +++ b/platforms/android/library/src/main/java/io/element/android/wysiwyg/EditorStyledTextView.kt @@ -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 onTextLayout: ((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 { onTextLayout?.invoke(it) } + } + 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) { diff --git a/platforms/android/library/src/main/java/io/element/android/wysiwyg/utils/RustCleanerTask.kt b/platforms/android/library/src/main/java/io/element/android/wysiwyg/utils/RustCleanerTask.kt index 4142a4d86..3350faec6 100644 --- a/platforms/android/library/src/main/java/io/element/android/wysiwyg/utils/RustCleanerTask.kt +++ b/platforms/android/library/src/main/java/io/element/android/wysiwyg/utils/RustCleanerTask.kt @@ -1,5 +1,6 @@ package io.element.android.wysiwyg.utils +import io.element.android.wysiwyg.BuildConfig import timber.log.Timber import uniffi.wysiwyg_composer.Disposable @@ -7,7 +8,9 @@ internal class RustCleanerTask( private val disposable: Disposable, ) : Runnable { override fun run() { - Timber.d("Cleaning up disposable: $disposable") + if (BuildConfig.DEBUG) { + Timber.d("Cleaning up disposable: $disposable") + } disposable.destroy() } } \ No newline at end of file