Skip to content

Commit

Permalink
Fix the problem with slider tail having enough length with LTR animation
Browse files Browse the repository at this point in the history
  • Loading branch information
mahozad committed Jan 12, 2024
1 parent 21697a6 commit ad28597
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import kotlin.math.abs
* [0f, 0f, 0.25f, 0.5f, 0.75f, 1f, 1f]
* ```
*
* Note that the first wave and the last wave are extra but required
* Note that the first two waves and the last two waves are extra but required
* which will be taken advantage of in edge slider values.
*/
internal fun generateHeightFactors(count: Int) = FloatArray(count) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -415,8 +415,8 @@ private fun Track(
)
}
val wave = Path().apply {
val startX = sliderStart.x + /* One extra required wave at the start */ waveWidthPx * if (isRtl) 1 else -1
val length = (sliderValueOffset.x - startX).absoluteValue + /* One extra required wave at the end */ waveWidthPx
val startX = sliderStart.x + /* Two extra required padding waves at the start */ (2 * waveWidthPx) * if (isRtl) 1 else -1
val length = (sliderValueOffset.x - startX).absoluteValue + /* Two extra required padding waves at the end */ (2 * waveWidthPx)
val totalWaveCount = ceil(length / waveWidthPx).toInt()
val heightFactors = if (shouldFlatten) {
generateHeightFactors(totalWaveCount)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -534,8 +534,8 @@ object WavySliderDefaults {
)
}
val wave = Path().apply {
val startX = sliderStart.x + /* One extra required wave at the start */ waveLengthPx * if (isRtl) 1 else -1
val length = (sliderValueOffset.x - startX).absoluteValue + /* One extra required wave at the end */ waveLengthPx
val startX = sliderStart.x + /* Two extra required padding waves at the start */ (2 * waveLengthPx) * if (isRtl) 1 else -1
val length = (sliderValueOffset.x - startX).absoluteValue + /* Two extra required padding waves at the end */ (2 * waveLengthPx)
val totalWaveCount = ceil(length / waveLengthPx).toInt()
val heightFactors = if (shouldFlatten) {
generateHeightFactors(totalWaveCount)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -437,4 +437,17 @@ class VisualTest {
}
assert(isPassed)
}

@Test
fun `Test 23`() {
val isPassed = testApp(
name = object {}.javaClass.enclosingMethod.name,
given = "LTR animation",
expected = "The wave start (tail of the slider) should be long enough all the time\n" +
"(keep looking at the slider start for a few seconds and ensure the tail does not shrink)",
wavySlider2 = { value, onChange -> WavySlider2(value, onChange, waveHeight = 0.dp, animationDirection = LTR) },
wavySlider3 = { value, onChange -> WavySlider3(value, onChange, waveHeight = 0.dp, animationDirection = LTR) }
)
assert(isPassed)
}
}

0 comments on commit ad28597

Please sign in to comment.