Skip to content

Commit

Permalink
Extract animations durations to variables
Browse files Browse the repository at this point in the history
  • Loading branch information
mahozad committed Jan 12, 2024
1 parent 4cf4eca commit 21697a6
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package ir.mahozad.multiplatform.wavyslider

import androidx.compose.ui.input.key.KeyEvent
import androidx.compose.ui.unit.dp
import kotlin.time.Duration.Companion.seconds

/**
* The direction of wave movement.
Expand All @@ -25,8 +26,9 @@ enum class WaveAnimationDirection {
}

internal val defaultTrackThickness = 4.dp

internal val defaultWaveSize = 16.dp
internal val defaultWavePeriod = 2.seconds
internal val defaultWaveHeightChangeDuration = 1.seconds

internal expect val KeyEvent.isDirectionUp: Boolean

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,10 @@ private fun Track(
waveThicknessPx = waveThickness.toPx()
trackThicknessPx = trackThickness?.toPx() ?: 0f
}
val waveHeightAnimated by animateFloatAsState(waveHeightPx, tween(1000, easing = LinearEasing))
val waveHeightAnimated by animateFloatAsState(
waveHeightPx,
tween(defaultWaveHeightChangeDuration.inWholeMilliseconds.toInt(), easing = LinearEasing)
)
val wavePosition by rememberInfiniteTransition()
.animateFloat(
initialValue = 0f,
Expand All @@ -381,7 +384,7 @@ private fun Track(
-waveWidthPx
},
animationSpec = infiniteRepeatable(
animation = tween(durationMillis = 2000, easing = LinearEasing),
animation = tween(defaultWavePeriod.inWholeMilliseconds.toInt(), easing = LinearEasing),
repeatMode = RepeatMode.Restart
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,10 @@ object WavySliderDefaults {
waveThicknessPx = waveThickness.toPx()
trackThicknessPx = trackThickness?.toPx() ?: 0f
}
val waveHeightAnimated by animateFloatAsState(waveHeightPx, tween(1000, easing = LinearEasing))
val waveHeightAnimated by animateFloatAsState(
waveHeightPx,
tween(defaultWaveHeightChangeDuration.inWholeMilliseconds.toInt(), easing = LinearEasing)
)
val wavePosition by rememberInfiniteTransition()
.animateFloat(
initialValue = 0f,
Expand All @@ -500,7 +503,7 @@ object WavySliderDefaults {
-waveLengthPx
},
animationSpec = infiniteRepeatable(
animation = tween(durationMillis = 2000, easing = LinearEasing),
animation = tween(defaultWavePeriod.inWholeMilliseconds.toInt(), easing = LinearEasing),
repeatMode = RepeatMode.Restart
)
)
Expand Down

0 comments on commit 21697a6

Please sign in to comment.