Last active
August 8, 2020 16:48
-
-
Save Skyyo/d01beb1003092e79287427f22826129c to your computer and use it in GitHub Desktop.
#extensions
This file contains 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 com.skyyo.ext | |
import android.animation.AnimatorSet | |
import android.animation.ObjectAnimator | |
import android.view.View | |
import android.view.ViewGroup | |
fun View.slideInDown(): AnimatorSet { | |
val animatorSet = AnimatorSet() | |
val distance = (top + height).toFloat() | |
val object1: ObjectAnimator = ObjectAnimator.ofFloat(this, "alpha", 0f, 1f) | |
val object2: ObjectAnimator = ObjectAnimator.ofFloat(this, "translationY", -distance, 0f) | |
animatorSet.playTogether(object1, object2) | |
return animatorSet | |
} | |
fun View.slideInLeft(): AnimatorSet { | |
val animatorSet = AnimatorSet() | |
val parent = parent as ViewGroup | |
val distance = (parent.width - left).toFloat() | |
val object1: ObjectAnimator = ObjectAnimator.ofFloat(this, "alpha", 0f, 1f) | |
val object2: ObjectAnimator = ObjectAnimator.ofFloat(this, "translationX", -distance, 0f) | |
animatorSet.playTogether(object1, object2) | |
return animatorSet | |
} | |
fun View.slideInRight(): AnimatorSet { | |
val animatorSet = AnimatorSet() | |
val parent = parent as ViewGroup | |
val distance = (parent.width - left).toFloat() | |
val object1: ObjectAnimator = ObjectAnimator.ofFloat(this, "alpha", 0f, 1f) | |
val object2: ObjectAnimator = ObjectAnimator.ofFloat(this, "translationX", distance, 0f) | |
animatorSet.playTogether(object1, object2) | |
return animatorSet | |
} | |
fun View.slideInUp(): AnimatorSet { | |
val animatorSet = AnimatorSet() | |
val parent = parent as ViewGroup | |
val distance = (parent.height - top).toFloat() | |
val object1: ObjectAnimator = ObjectAnimator.ofFloat(this, "alpha", 0f, 1f) | |
val object2: ObjectAnimator = ObjectAnimator.ofFloat(this, "translationY", distance, 0f) | |
animatorSet.playTogether(object1, object2) | |
return animatorSet | |
} | |
fun View.slideOutDown(): AnimatorSet { | |
val animatorSet = AnimatorSet() | |
val parent = parent as ViewGroup | |
val distance = (parent.height - top).toFloat() | |
val object1: ObjectAnimator = ObjectAnimator.ofFloat(this, "alpha", 1f, 0f) | |
val object2: ObjectAnimator = ObjectAnimator.ofFloat(this, "translationY", 0f, distance) | |
animatorSet.playTogether(object1, object2) | |
return animatorSet | |
} | |
fun View.slideOutLeft(): AnimatorSet { | |
val animatorSet = AnimatorSet() | |
val right = right.toFloat() | |
val object1: ObjectAnimator = ObjectAnimator.ofFloat(this, "alpha", 1f, 0f) | |
val object2: ObjectAnimator = ObjectAnimator.ofFloat(this, "translationX", 0f, -right) | |
animatorSet.playTogether(object1, object2) | |
return animatorSet | |
} | |
fun View.slideOutRight(): AnimatorSet { | |
val animatorSet = AnimatorSet() | |
val parent = parent as ViewGroup | |
val distance = (parent.width - left).toFloat() | |
val object1: ObjectAnimator = ObjectAnimator.ofFloat(this, "alpha", 1f, 0f) | |
val object2: ObjectAnimator = ObjectAnimator.ofFloat(this, "translationX", 0f, distance) | |
animatorSet.playTogether(object1, object2) | |
return animatorSet | |
} | |
fun View.slideOutUp(): AnimatorSet { | |
val animatorSet = AnimatorSet() | |
val bottom = -bottom.toFloat() | |
val object1: ObjectAnimator = ObjectAnimator.ofFloat(this, "alpha", 1f, 0f) | |
val object2: ObjectAnimator = ObjectAnimator.ofFloat(this, "translationY", 0f, bottom) | |
animatorSet.playTogether(object1, object2) | |
return animatorSet | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment