Skip to content

Commit 4628d7b

Browse files
committed
feedback: refactor applySelectionHandleTint
1 parent 79f23a7 commit 4628d7b

1 file changed

Lines changed: 5 additions & 12 deletions

File tree

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

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.swmansion.enriched.markdown.utils.text.view
22

3-
import android.graphics.drawable.Drawable
43
import android.os.Build
54
import android.util.Log
65
import android.widget.TextView
@@ -9,9 +8,6 @@ import androidx.core.graphics.drawable.DrawableCompat
98

109
private const val TAG = "TextSelectionColors"
1110

12-
private typealias HandleGetter = (TextView) -> Drawable?
13-
private typealias HandleSetter = (TextView, Drawable) -> Unit
14-
1511
/**
1612
* Applies selection highlight and (where supported) handle tinting to a [TextView].
1713
*
@@ -29,22 +25,19 @@ fun TextView.applySelectionColors(
2925
private fun TextView.applySelectionHandleTint(
3026
@ColorInt color: Int,
3127
) {
32-
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) {
33-
return
34-
}
28+
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) return
3529

36-
val handles: List<Pair<HandleGetter, HandleSetter>> =
30+
val handles =
3731
listOf(
38-
TextView::getTextSelectHandleLeft to { tv, d -> tv.setTextSelectHandleLeft(d) },
39-
TextView::getTextSelectHandle to { tv, d -> tv.setTextSelectHandle(d) },
40-
TextView::getTextSelectHandleRight to { tv, d -> tv.setTextSelectHandleRight(d) },
32+
TextView::getTextSelectHandleLeft to TextView::setTextSelectHandleLeft,
33+
TextView::getTextSelectHandle to TextView::setTextSelectHandle,
34+
TextView::getTextSelectHandleRight to TextView::setTextSelectHandleRight,
4135
)
4236

4337
handles.forEach { (getter, setter) ->
4438
try {
4539
getter(this)?.mutate()?.also { DrawableCompat.setTint(it, color) }?.let { setter(this, it) }
4640
} catch (e: LinkageError) {
47-
// Defensive: OEM TextView variants may strip individual handle accessors.
4841
Log.w(TAG, "Selection handle tint skipped: ${e.message}")
4942
}
5043
}

0 commit comments

Comments
 (0)