Update page flip animation
This commit is contained in:
@@ -5,32 +5,27 @@ import androidx.viewpager2.widget.ViewPager2
|
||||
|
||||
class ReversedPageAnimTransformer : ViewPager2.PageTransformer {
|
||||
|
||||
override fun transformPage(page: View, position: Float) {
|
||||
with(page) {
|
||||
val pageWidth = width
|
||||
when {
|
||||
position > 1 -> alpha = 0f
|
||||
position >= 0 -> {
|
||||
alpha = 1f
|
||||
translationX = 0f
|
||||
translationZ = 0f
|
||||
scaleX = 1 + FACTOR * position
|
||||
scaleY = 1f
|
||||
}
|
||||
position >= -1 -> {
|
||||
alpha = 1f
|
||||
translationX = pageWidth * -position
|
||||
translationZ = -1f
|
||||
scaleX = 1f
|
||||
scaleY = 1f
|
||||
}
|
||||
else -> alpha = 0f
|
||||
override fun transformPage(page: View, position: Float) = with(page) {
|
||||
translationX = -position * width
|
||||
pivotX = width.toFloat()
|
||||
pivotY = height / 2f
|
||||
cameraDistance = 20000f
|
||||
when {
|
||||
position < -1f || position > 1f -> {
|
||||
alpha = 0f
|
||||
rotationY = 0f
|
||||
translationZ = -1f
|
||||
}
|
||||
position <= 0f -> {
|
||||
alpha = 1f
|
||||
rotationY = 0f
|
||||
translationZ = 0f
|
||||
}
|
||||
position > 0f -> {
|
||||
alpha = 1f
|
||||
rotationY = 120 * position
|
||||
translationZ = 2f
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private companion object {
|
||||
|
||||
const val FACTOR = 0.1f
|
||||
}
|
||||
}
|
||||
@@ -5,32 +5,27 @@ import androidx.viewpager2.widget.ViewPager2
|
||||
|
||||
class PageAnimTransformer : ViewPager2.PageTransformer {
|
||||
|
||||
override fun transformPage(page: View, position: Float) {
|
||||
page.apply {
|
||||
val pageWidth = width
|
||||
when {
|
||||
position < -1 -> alpha = 0f
|
||||
position <= 0 -> { // [-1,0]
|
||||
alpha = 1f
|
||||
translationX = 0f
|
||||
translationZ = 0f
|
||||
scaleX = 1 + FACTOR * position
|
||||
scaleY = 1f
|
||||
}
|
||||
position <= 1 -> { // (0,1]
|
||||
alpha = 1f
|
||||
translationX = pageWidth * -position
|
||||
translationZ = -1f
|
||||
scaleX = 1f
|
||||
scaleY = 1f
|
||||
}
|
||||
else -> alpha = 0f
|
||||
override fun transformPage(page: View, position: Float) = with(page) {
|
||||
translationX = -position * width
|
||||
pivotX = 0f
|
||||
pivotY = height / 2f
|
||||
cameraDistance = 20000f
|
||||
when {
|
||||
position < -1f || position > 1f -> {
|
||||
alpha = 0f
|
||||
rotationY = 0f
|
||||
translationZ = -1f
|
||||
}
|
||||
position > 0f -> {
|
||||
alpha = 1f
|
||||
rotationY = 0f
|
||||
translationZ = 0f
|
||||
}
|
||||
position <= 0f -> {
|
||||
alpha = 1f
|
||||
rotationY = 120 * position
|
||||
translationZ = 2f
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private companion object {
|
||||
|
||||
const val FACTOR = 0.1f
|
||||
}
|
||||
}
|
||||
@@ -133,6 +133,8 @@ fun View.resetTransformations() {
|
||||
translationZ = 0f
|
||||
scaleX = 1f
|
||||
scaleY = 1f
|
||||
rotationX = 0f
|
||||
rotationY = 0f
|
||||
}
|
||||
|
||||
inline fun RecyclerView.doOnCurrentItemChanged(crossinline callback: (Int) -> Unit) {
|
||||
|
||||
Reference in New Issue
Block a user