Skip to content

Commit 0e5db81

Browse files
committed
fix(android): disable smart text selection to prevent ImageSpan crash
1 parent 0977df3 commit 0e5db81

1 file changed

Lines changed: 16 additions & 2 deletions

File tree

  • android/src/main/java/com/swmansion/enriched/markdown/utils/text/view

android/src/main/java/com/swmansion/enriched/markdown/utils/text/view/TextViewSetup.kt

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,32 @@
11
package com.swmansion.enriched.markdown.utils.text.view
22

33
import android.graphics.Color
4+
import android.os.Build
5+
import android.view.textclassifier.TextClassifier
46
import androidx.appcompat.widget.AppCompatTextView
57
import androidx.core.view.ViewCompat
68
import com.swmansion.enriched.markdown.accessibility.MarkdownAccessibilityHelper
7-
import com.swmansion.enriched.markdown.utils.text.view.LinkLongPressMovementMethod
8-
import com.swmansion.enriched.markdown.utils.text.view.createSelectionActionModeCallback
99

1010
fun AppCompatTextView.setupAsMarkdownTextView(accessibilityHelper: MarkdownAccessibilityHelper) {
1111
setBackgroundColor(Color.TRANSPARENT)
1212
includeFontPadding = false
1313
movementMethod = LinkLongPressMovementMethod.createInstance()
1414
setTextIsSelectable(true)
1515
customSelectionActionModeCallback = createSelectionActionModeCallback(this)
16+
// SmartSelectSprite crashes with "Center point is not inside any of the
17+
// rectangles!" when Layout.getSelection returns empty rects near an
18+
// ImageSpan (ReplacementSpan). NO_OP makes skipTextClassification() return
19+
// true, bypassing the entire SmartSelectSprite code path. Regular text
20+
// selection (long-press, handles, copy/paste) still works; only automatic
21+
// entity detection (phone numbers, addresses) is disabled.
22+
//
23+
// TODO: Add an Android-only `enableSmartTextSelection` prop that skips this
24+
// NO_OP override. This would let users who don't render images opt in to
25+
// entity detection. The prop should default to false and its docs should
26+
// warn that enabling it with markdown containing images will crash.
27+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
28+
setTextClassifier(TextClassifier.NO_OP)
29+
}
1630
isVerticalScrollBarEnabled = false
1731
isHorizontalScrollBarEnabled = false
1832
ViewCompat.setAccessibilityDelegate(this, accessibilityHelper)

0 commit comments

Comments
 (0)