Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix animation strategies IN_EXPO and OUT_EXPO. #129

Merged
merged 2 commits into from
Nov 28, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -116,20 +116,23 @@ enum class Animations : AnimationStrategy {
},
IN_EXP {
override fun getValue(percentComplete: Float): Float {
return 2f.pow(10 * (percentComplete - 1))
return if (percentComplete <= 0f) 0f else 2f.pow(10 * (percentComplete - 1))
}
},
OUT_EXP {
override fun getValue(percentComplete: Float): Float {
return -(2f.pow(-10 * percentComplete)) + 1
return if (percentComplete >= 1f) 1f else -(2f.pow(-10 * percentComplete)) + 1
}
},
IN_OUT_EXP {
override fun getValue(percentComplete: Float): Float {
var t = percentComplete * 2
if (t < 1) return 0.5f * 2f.pow(10 * (t - 1))
t--
return 0.5f * (-(2f.pow(-10 * t)) + 2)
// We don't need the extra checks, as those are now handled by the functions we call
// multiply percentComplete by 2 to normalize range before calling getValue
// then divide by two to shrink it to 0.0-0.5
return if (percentComplete < 0.5) IN_EXP.getValue(percentComplete * 2) / 2
// multiply percentComplete by 2 and subtract one to normalize range before calling getValue
// then divide by two to shrink it and add 0.5 to move it upwards, as a continuation of the first half
else OUT_EXP.getValue((percentComplete * 2) - 1) / 2 + 0.5f
}
},
IN_CIRCULAR {
Expand Down Expand Up @@ -201,4 +204,4 @@ enum class Animations : AnimationStrategy {
return OUT_BOUNCE.getValue(percentComplete * 2 - 1) * 0.5f + 0.5f
}
}
}
}