Update page flip animation

pull/81/head
Koitharu 4 years ago
parent f0add59f99
commit 9a65e40be1
No known key found for this signature in database
GPG Key ID: 8E861F8CE6E7CE27

@ -5,32 +5,27 @@ import androidx.viewpager2.widget.ViewPager2
class ReversedPageAnimTransformer : ViewPager2.PageTransformer { class ReversedPageAnimTransformer : ViewPager2.PageTransformer {
override fun transformPage(page: View, position: Float) { override fun transformPage(page: View, position: Float) = with(page) {
with(page) { translationX = -position * width
val pageWidth = width pivotX = width.toFloat()
when { pivotY = height / 2f
position > 1 -> alpha = 0f cameraDistance = 20000f
position >= 0 -> { when {
alpha = 1f position < -1f || position > 1f -> {
translationX = 0f alpha = 0f
translationZ = 0f rotationY = 0f
scaleX = 1 + FACTOR * position translationZ = -1f
scaleY = 1f }
} position <= 0f -> {
position >= -1 -> { alpha = 1f
alpha = 1f rotationY = 0f
translationX = pageWidth * -position translationZ = 0f
translationZ = -1f }
scaleX = 1f position > 0f -> {
scaleY = 1f alpha = 1f
} rotationY = 120 * position
else -> alpha = 0f translationZ = 2f
} }
} }
} }
private companion object {
const val FACTOR = 0.1f
}
} }

@ -5,32 +5,27 @@ import androidx.viewpager2.widget.ViewPager2
class PageAnimTransformer : ViewPager2.PageTransformer { class PageAnimTransformer : ViewPager2.PageTransformer {
override fun transformPage(page: View, position: Float) { override fun transformPage(page: View, position: Float) = with(page) {
page.apply { translationX = -position * width
val pageWidth = width pivotX = 0f
when { pivotY = height / 2f
position < -1 -> alpha = 0f cameraDistance = 20000f
position <= 0 -> { // [-1,0] when {
alpha = 1f position < -1f || position > 1f -> {
translationX = 0f alpha = 0f
translationZ = 0f rotationY = 0f
scaleX = 1 + FACTOR * position translationZ = -1f
scaleY = 1f }
} position > 0f -> {
position <= 1 -> { // (0,1] alpha = 1f
alpha = 1f rotationY = 0f
translationX = pageWidth * -position translationZ = 0f
translationZ = -1f }
scaleX = 1f position <= 0f -> {
scaleY = 1f alpha = 1f
} rotationY = 120 * position
else -> alpha = 0f translationZ = 2f
} }
} }
} }
private companion object {
const val FACTOR = 0.1f
}
} }

@ -133,6 +133,8 @@ fun View.resetTransformations() {
translationZ = 0f translationZ = 0f
scaleX = 1f scaleX = 1f
scaleY = 1f scaleY = 1f
rotationX = 0f
rotationY = 0f
} }
inline fun RecyclerView.doOnCurrentItemChanged(crossinline callback: (Int) -> Unit) { inline fun RecyclerView.doOnCurrentItemChanged(crossinline callback: (Int) -> Unit) {

Loading…
Cancel
Save