@matiks/rn-stroke-text 0.1.4 → 0.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -8,7 +8,6 @@ import android.graphics.Typeface
|
|
|
8
8
|
import android.text.Layout
|
|
9
9
|
import android.text.StaticLayout
|
|
10
10
|
import android.text.TextPaint
|
|
11
|
-
import android.text.TextUtils
|
|
12
11
|
import android.util.TypedValue
|
|
13
12
|
import android.view.View
|
|
14
13
|
import kotlin.math.ceil
|
|
@@ -51,6 +50,7 @@ class StrokeTextView(context: Context) : View(context) {
|
|
|
51
50
|
private var textLayout: StaticLayout? = null
|
|
52
51
|
private var strokeLayout: StaticLayout? = null
|
|
53
52
|
private var layoutDirty = true
|
|
53
|
+
private var lastLayoutWidth: Int = -1 // Track width used for layout
|
|
54
54
|
|
|
55
55
|
private val fontCache = HashMap<String, Typeface?>()
|
|
56
56
|
|
|
@@ -114,22 +114,11 @@ class StrokeTextView(context: Context) : View(context) {
|
|
|
114
114
|
}
|
|
115
115
|
|
|
116
116
|
private fun ensureLayout(width: Int) {
|
|
117
|
-
if (!layoutDirty && textLayout != null) return
|
|
118
|
-
|
|
119
117
|
val safeWidth = width.coerceAtLeast(1)
|
|
118
|
+
if (!layoutDirty && textLayout != null && lastLayoutWidth == safeWidth) return
|
|
120
119
|
updatePaints()
|
|
121
120
|
|
|
122
|
-
var displayText: CharSequence =
|
|
123
|
-
if (ellipsis) {
|
|
124
|
-
TextUtils.ellipsize(
|
|
125
|
-
text,
|
|
126
|
-
textPaint,
|
|
127
|
-
safeWidth.toFloat(),
|
|
128
|
-
TextUtils.TruncateAt.END
|
|
129
|
-
)
|
|
130
|
-
} else {
|
|
131
|
-
text
|
|
132
|
-
}
|
|
121
|
+
var displayText: CharSequence = text
|
|
133
122
|
|
|
134
123
|
// Use StaticLayout.Builder for API 23+
|
|
135
124
|
val builder =
|
|
@@ -182,6 +171,7 @@ class StrokeTextView(context: Context) : View(context) {
|
|
|
182
171
|
|
|
183
172
|
strokeLayout = strokeBuilder.build()
|
|
184
173
|
|
|
174
|
+
lastLayoutWidth = safeWidth // Remember the width used
|
|
185
175
|
layoutDirty = false
|
|
186
176
|
}
|
|
187
177
|
|