-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
library: Optimize Popup Animation (#26)
- Loading branch information
1 parent
6bcce1a
commit 52130a6
Showing
3 changed files
with
100 additions
and
21 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
miuix/src/commonMain/kotlin/top/yukonga/miuix/kmp/anim/AccelerateEasing.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package top.yukonga.miuix.kmp.anim | ||
|
||
import androidx.compose.animation.core.Easing | ||
import androidx.compose.runtime.Immutable | ||
import kotlin.math.pow | ||
|
||
/** | ||
* This is equivalent to the Android [AccelerateInterpolator](https://cs.android.com/search?q=file:androidx/core/animation/AccelerateInterpolator.java+class:androidx.core.animation.AccelerateInterpolator) | ||
* | ||
* @param factor Degree to which the animation should be eased. Setting | ||
* factor to 1.0f produces a y=x^2 parabola. Increasing factor above | ||
* 1.0f exaggerates the ease-in effect (i.e., it starts even | ||
* slower and ends evens faster) | ||
*/ | ||
@Immutable | ||
class AccelerateEasing( | ||
private val factor: Float = 1.0f | ||
) : Easing { | ||
private val doubleFactor: Float = 2 * factor | ||
|
||
override fun transform(fraction: Float): Float { | ||
return if (factor == 1.0f) { | ||
fraction * fraction | ||
} else { | ||
fraction.pow(doubleFactor) | ||
} | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
miuix/src/commonMain/kotlin/top/yukonga/miuix/kmp/anim/DecelerateEasing.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
|
||
|
||
package top.yukonga.miuix.kmp.anim | ||
|
||
import androidx.compose.animation.core.Easing | ||
import androidx.compose.runtime.Immutable | ||
import kotlin.math.pow | ||
|
||
/** | ||
* This is equivalent to the Android [DecelerateInterpolator](https://cs.android.com/search?q=file:androidx/core/animation/DecelerateInterpolator.java+class:androidx.core.animation.DecelerateInterpolator) | ||
* | ||
* @param factor Degree to which the animation should be eased. Setting factor to 1.0f produces | ||
* an upside-down y=x^2 parabola. Increasing factor above 1.0f makes exaggerates the | ||
* ease-out effect (i.e., it starts even faster and ends evens slower) | ||
*/ | ||
@Immutable | ||
class DecelerateEasing( | ||
private val factor: Float = 1.0f | ||
) : Easing { | ||
override fun transform(fraction: Float): Float { | ||
return if (factor == 1.0f) { | ||
1.0f - (1.0f - fraction) * (1.0f - fraction) | ||
} else { | ||
1.0f - (1.0f - fraction).pow(2 * fraction) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters