Skip to content

Commit 90edd78

Browse files
committed
android: fix
1 parent 1a9caa3 commit 90edd78

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

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

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

3+
import android.graphics.drawable.Drawable
34
import android.os.Build
45
import android.util.Log
56
import android.widget.TextView
@@ -8,6 +9,9 @@ import androidx.core.graphics.drawable.DrawableCompat
89

910
private const val TAG = "TextSelectionColors"
1011

12+
private typealias HandleGetter = (TextView) -> Drawable?
13+
private typealias HandleSetter = (TextView, Drawable) -> Unit
14+
1115
/**
1216
* Applies selection highlight and (where supported) handle tinting to a [TextView].
1317
*
@@ -29,16 +33,16 @@ private fun TextView.applySelectionHandleTint(
2933
return
3034
}
3135

32-
val handles =
36+
val handles: List<Pair<HandleGetter, HandleSetter>> =
3337
listOf(
34-
this::getTextSelectHandleLeft to this::setTextSelectHandleLeft,
35-
this::getTextSelectHandle to this::setTextSelectHandle,
36-
this::getTextSelectHandleRight to this::setTextSelectHandleRight,
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) },
3741
)
3842

3943
handles.forEach { (getter, setter) ->
4044
try {
41-
getter()?.mutate()?.also { DrawableCompat.setTint(it, color) }?.let(setter)
45+
getter(this)?.mutate()?.also { DrawableCompat.setTint(it, color) }?.let { setter(this, it) }
4246
} catch (e: LinkageError) {
4347
// Defensive: OEM TextView variants may strip individual handle accessors.
4448
Log.w(TAG, "Selection handle tint skipped: ${e.message}")

0 commit comments

Comments
 (0)