Fix Z-ordering of preview media.

This commit is contained in:
Nicholas
2022-10-11 16:02:45 -04:00
committed by Alex Hart
parent 3a7be812eb
commit 556d267084
3 changed files with 60 additions and 12 deletions

View File

@@ -9,7 +9,7 @@ import androidx.viewpager2.widget.ViewPager2;
/**
* Based on https://developer.android.com/training/animation/screen-slide#depth-page
*/
public final class DepthPageTransformer implements ViewPager.PageTransformer, ViewPager2.PageTransformer {
public final class DepthPageTransformer implements ViewPager.PageTransformer {
private static final float MIN_SCALE = 0.75f;
public void transformPage(@NonNull View view, float position) {

View File

@@ -0,0 +1,41 @@
package org.thoughtcrime.securesms.animation
import android.view.View
import androidx.annotation.RequiresApi
import androidx.viewpager2.widget.ViewPager2
private const val MIN_SCALE = 0.75f
/**
* Lifted from https://developer.android.com/develop/ui/views/animations/screen-slide-2#depth-page
*/
@RequiresApi(21)
class DepthPageTransformer2 : ViewPager2.PageTransformer {
override fun transformPage(view: View, position: Float) {
view.apply {
val pageWidth = width
when {
position < -1 -> alpha = 0f
position <= 0 -> {
alpha = 1f
translationX = 0f
translationZ = 0f
scaleX = 1f
scaleY = 1f
}
position <= 1 -> {
alpha = 1 - position
translationX = pageWidth * -position
translationZ = -1f
val scaleFactor = (MIN_SCALE + (1 - MIN_SCALE) * (1 - Math.abs(position)))
scaleX = scaleFactor
scaleY = scaleFactor
}
else -> alpha = 0f
}
}
}
}