From a10482b794d69a8cea2b6dc0e0188d665a9c2db8 Mon Sep 17 00:00:00 2001 From: k1ngsterr1 Date: Sun, 12 Apr 2026 15:05:25 +0500 Subject: [PATCH] =?UTF-8?q?feat:=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D1=82=D1=8C=20onTextLongPress=20callback=20=D0=B8=20getLayoutI?= =?UTF-8?q?nfo()=20=D0=B2=20AppleEmojiTextView?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 4.6 (1M context) --- .../ui/components/AppleEmojiEditText.kt | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/rosetta/messenger/ui/components/AppleEmojiEditText.kt b/app/src/main/java/com/rosetta/messenger/ui/components/AppleEmojiEditText.kt index 988ee82..5643d3f 100644 --- a/app/src/main/java/com/rosetta/messenger/ui/components/AppleEmojiEditText.kt +++ b/app/src/main/java/com/rosetta/messenger/ui/components/AppleEmojiEditText.kt @@ -558,6 +558,8 @@ fun AppleEmojiText( onClickableSpanPressStart: (() -> Unit)? = null, onClick: (() -> Unit)? = null, // 🔥 Обычный tap (selection mode в MessageBubble) onLongClick: (() -> Unit)? = null, // 🔥 Callback для long press (selection в MessageBubble) + onTextLongPress: ((touchX: Int, touchY: Int) -> Unit)? = null, + onViewCreated: ((com.rosetta.messenger.ui.components.AppleEmojiTextView) -> Unit)? = null, minHeightMultiplier: Float = 1.5f ) { val fontSizeValue = if (fontSize == androidx.compose.ui.unit.TextUnit.Unspecified) 15f @@ -601,6 +603,8 @@ fun AppleEmojiText( enableMentionHighlight(enableMentions) setOnMentionClickListener(onMentionClick) setOnClickableSpanPressStartListener(onClickableSpanPressStart) + onTextLongPressCallback = onTextLongPress + onViewCreated?.invoke(this) // In link/mention mode, keep span clicks exclusive to avoid parent bubble menu tap. val canUseTextViewClick = !enableLinks setOnClickListener( @@ -634,6 +638,7 @@ fun AppleEmojiText( view.enableMentionHighlight(enableMentions) view.setOnMentionClickListener(onMentionClick) view.setOnClickableSpanPressStartListener(onClickableSpanPressStart) + view.onTextLongPressCallback = onTextLongPress // In link/mention mode, keep span clicks exclusive to avoid parent bubble menu tap. val canUseTextViewClick = !enableLinks view.setOnClickListener( @@ -695,13 +700,17 @@ class AppleEmojiTextView @JvmOverloads constructor( // 🔥 Long press callback для selection в MessageBubble var onLongClickCallback: (() -> Unit)? = null + var onTextLongPressCallback: ((touchX: Int, touchY: Int) -> Unit)? = null private var downOnClickableSpan: Boolean = false private var suppressPerformClickOnce: Boolean = false // 🔥 GestureDetector для обработки long press поверх LinkMovementMethod private val gestureDetector = GestureDetector(context, object : GestureDetector.SimpleOnGestureListener() { override fun onLongPress(e: MotionEvent) { - if (!downOnClickableSpan) { + if (downOnClickableSpan) return + if (onTextLongPressCallback != null) { + onTextLongPressCallback?.invoke(e.rawX.toInt(), e.rawY.toInt()) + } else { onLongClickCallback?.invoke() } } @@ -822,6 +831,18 @@ class AppleEmojiTextView @JvmOverloads constructor( } } + fun getLayoutInfo(): com.rosetta.messenger.ui.chats.components.LayoutInfo? { + val l = layout ?: return null + val loc = IntArray(2) + getLocationInWindow(loc) + return com.rosetta.messenger.ui.chats.components.LayoutInfo( + layout = l, + windowX = loc[0] + totalPaddingLeft, + windowY = loc[1] + totalPaddingTop, + text = text ?: return null + ) + } + fun setTextWithEmojis(text: String) { val isLargeText = text.length > LARGE_TEXT_RENDER_THRESHOLD val processMentions = mentionsEnabled && !isLargeText