Created
January 9, 2022 18:05
-
-
Save Bloody-Badboy/ef0ebaa21d85a202e49d396eb39fc133 to your computer and use it in GitHub Desktop.
Stack Page Transformer (Supports RTL) https://giphy.com/gifs/8ykEAOx9uMmVl5Mrr7
This file contains hidden or 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
package dev.arpan.motionlayout.playground | |
import android.view.View | |
import androidx.core.view.ViewCompat | |
import androidx.viewpager2.widget.ViewPager2 | |
class StackPageTransformer : ViewPager2.PageTransformer { | |
override fun transformPage(page: View, position: Float) { | |
page.apply { | |
when { | |
position < -1 -> { | |
alpha = 0f | |
} | |
position <= 0 -> { | |
if (ViewCompat.getLayoutDirection(page) == ViewCompat.LAYOUT_DIRECTION_RTL) { | |
alpha = 1f | |
translationX = width * position | |
translationZ = -1f | |
} else { | |
alpha = 1f | |
translationX = 0f | |
translationZ = 0f | |
} | |
} | |
position in 0.0..1.0 -> { | |
if (ViewCompat.getLayoutDirection(page) == ViewCompat.LAYOUT_DIRECTION_RTL) { | |
alpha = 1f | |
translationX = 0f | |
translationZ = 0f | |
} else { | |
alpha = 1f | |
translationX = width * -position | |
translationZ = -1f | |
} | |
} | |
else -> { | |
alpha = 0f | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment