Skip to content

Commit 4cf6f67

Browse files
committed
fix: properly interpolate linear gradient
1 parent 8b9f7ee commit 4cf6f67

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

package/native-package/android/src/main/java/com/streamchatreactnative/StreamShimmerFrameLayout.kt

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,13 +162,33 @@ class StreamShimmerFrameLayout @JvmOverloads constructor(
162162
}
163163

164164
val shimmerWidth = (viewWidth * SHIMMER_STRIP_WIDTH_RATIO).coerceAtLeast(1f)
165+
val softBase = colorWithAlpha(highlightColor, EDGE_HIGHLIGHT_ALPHA_FACTOR)
166+
val mediumBase = colorWithAlpha(highlightColor, MID_HIGHLIGHT_ALPHA_FACTOR)
165167
shimmerShader = LinearGradient(
166168
0f,
167169
0f,
168170
shimmerWidth,
169171
0f,
170-
intArrayOf(baseColor, highlightColor, baseColor),
171-
floatArrayOf(0f, 0.5f, 1f),
172+
intArrayOf(
173+
baseColor,
174+
softBase,
175+
mediumBase,
176+
highlightColor,
177+
highlightColor,
178+
mediumBase,
179+
softBase,
180+
baseColor,
181+
),
182+
floatArrayOf(
183+
0f,
184+
0.2f,
185+
0.34f,
186+
0.44f,
187+
0.56f,
188+
0.66f,
189+
0.8f,
190+
1f,
191+
),
172192
Shader.TileMode.CLAMP,
173193
)
174194
}
@@ -207,7 +227,9 @@ class StreamShimmerFrameLayout @JvmOverloads constructor(
207227
private const val DEFAULT_HIGHLIGHT_COLOR = 0x59FFFFFF
208228
private const val DEFAULT_GRADIENT_COLOR = Color.WHITE
209229
private const val SHIMMER_DURATION_MS = 1200L
210-
private const val SHIMMER_STRIP_WIDTH_RATIO = 0.35f
230+
private const val SHIMMER_STRIP_WIDTH_RATIO = 1.1f
231+
private const val EDGE_HIGHLIGHT_ALPHA_FACTOR = 0.45f
232+
private const val MID_HIGHLIGHT_ALPHA_FACTOR = 0.75f
211233
private const val GRADIENT_CENTER_ALPHA = 0.35f
212234
}
213235
}

0 commit comments

Comments
 (0)