|
1 | 1 | package com.swmansion.enriched.markdown.utils.text.view |
2 | 2 |
|
3 | 3 | import android.graphics.Color |
| 4 | +import android.os.Build |
| 5 | +import android.view.textclassifier.TextClassifier |
4 | 6 | import androidx.appcompat.widget.AppCompatTextView |
5 | 7 | import androidx.core.view.ViewCompat |
6 | 8 | 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 |
9 | 9 |
|
10 | 10 | fun AppCompatTextView.setupAsMarkdownTextView(accessibilityHelper: MarkdownAccessibilityHelper) { |
11 | 11 | setBackgroundColor(Color.TRANSPARENT) |
12 | 12 | includeFontPadding = false |
13 | 13 | movementMethod = LinkLongPressMovementMethod.createInstance() |
14 | 14 | setTextIsSelectable(true) |
15 | 15 | 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 | + } |
16 | 30 | isVerticalScrollBarEnabled = false |
17 | 31 | isHorizontalScrollBarEnabled = false |
18 | 32 | ViewCompat.setAccessibilityDelegate(this, accessibilityHelper) |
|
0 commit comments