Skip to content

Instantly share code, notes, and snippets.

@pauloaapereira
Last active April 23, 2021 22:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pauloaapereira/c8086f2308dd3edec353ccd91739b42f to your computer and use it in GitHub Desktop.
Save pauloaapereira/c8086f2308dd3edec353ccd91739b42f to your computer and use it in GitHub Desktop.
Jetpack Compose - Earthquake Effect_3
class EarthquakeScope(private val state: EarthquakeState) : IEarthquakeScope {
override fun startShaking() {
if (!state.isShaking && state.earthquakeDuration > 0)
state.isShaking = true
}
override fun stopShaking() {
if (state.isShaking)
state.isShaking = false
}
override val isShaking: Boolean
get() = state.isShaking
override var shakeDuration: Long = state.earthquakeDuration
set(value) {
field = value
state.earthquakeDuration = value.coerceAtLeast(0)
}
override var shakesPerSecond: Int = state.shakesPerSecond
set(value) {
field = value
state.shakesPerSecond = value.coerceAtLeast(1)
}
override var shakeForce: Int = state.shakeForce
set(value) {
field = value
state.shakeForce = value.coerceAtLeast(1)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment