Skip to content

Instantly share code, notes, and snippets.

@Skyyo
Last active August 8, 2020 16:49
Show Gist options
  • Save Skyyo/efa28b15dc1e25480272f0507064a8e3 to your computer and use it in GitHub Desktop.
Save Skyyo/efa28b15dc1e25480272f0507064a8e3 to your computer and use it in GitHub Desktop.
#extensions
package com.skyyo.ext
import android.animation.AnimatorSet
import android.animation.ObjectAnimator
import android.view.View
fun View.fadeIn(): AnimatorSet {
val animatorSet = AnimatorSet()
val object1: ObjectAnimator = ObjectAnimator.ofFloat(this, "alpha", 0f, 1f)
animatorSet.playTogether(object1)
return animatorSet
}
fun View.fadeInLeft(): AnimatorSet {
val animatorSet = AnimatorSet()
val width = -width.toFloat()
val object1: ObjectAnimator = ObjectAnimator.ofFloat(this, "alpha", 0f, 1f)
val object2: ObjectAnimator = ObjectAnimator.ofFloat(this, "translationX", width / 4f, 0f)
animatorSet.playTogether(object1, object2)
return animatorSet
}
fun View.fadeInRight(): AnimatorSet {
val animatorSet = AnimatorSet()
val width = width.toFloat()
val object1: ObjectAnimator = ObjectAnimator.ofFloat(this, "alpha", 0f, 1f)
val object2: ObjectAnimator = ObjectAnimator.ofFloat(this, "translationX", width / 4f, 0f)
animatorSet.playTogether(object1, object2)
return animatorSet
}
fun View.fadeInUp(): AnimatorSet {
val animatorSet = AnimatorSet()
val height = height.toFloat()
val object1: ObjectAnimator = ObjectAnimator.ofFloat(this, "alpha", 0f, 1f)
val object2: ObjectAnimator = ObjectAnimator.ofFloat(this, "translationY", height / 4f, 0f)
animatorSet.playTogether(object1, object2)
return animatorSet
}
fun View.fadeInDown(): AnimatorSet {
val animatorSet = AnimatorSet()
val height = -height.toFloat()
val object1: ObjectAnimator = ObjectAnimator.ofFloat(this, "alpha", 0f, 1f)
val object2: ObjectAnimator = ObjectAnimator.ofFloat(this, "translationY", height / 4f, 0f)
animatorSet.playTogether(object1, object2)
return animatorSet
}
fun View.fadeOut(): AnimatorSet {
val animatorSet = AnimatorSet()
val object1: ObjectAnimator = ObjectAnimator.ofFloat(this, "alpha", 1f, 0f)
animatorSet.playTogether(object1)
return animatorSet
}
fun View.fadeOutLeft(): AnimatorSet {
val animatorSet = AnimatorSet()
val width = -width.toFloat()
val object1: ObjectAnimator = ObjectAnimator.ofFloat(this, "alpha", 1f, 0f)
val object2: ObjectAnimator = ObjectAnimator.ofFloat(this, "translationX", 0f, width / 4f)
animatorSet.playTogether(object1, object2)
return animatorSet
}
fun View.fadeOutRight(): AnimatorSet {
val animatorSet = AnimatorSet()
val width = width.toFloat()
val object1: ObjectAnimator = ObjectAnimator.ofFloat(this, "alpha", 0f, 1f)
val object2: ObjectAnimator = ObjectAnimator.ofFloat(this, "translationX", width / 4f, 0f)
animatorSet.playTogether(object1, object2)
return animatorSet
}
fun View.fadeOutUp(): AnimatorSet {
val animatorSet = AnimatorSet()
val height = height.toFloat()
val object1: ObjectAnimator = ObjectAnimator.ofFloat(this, "alpha", 1f, 0f)
val object2: ObjectAnimator = ObjectAnimator.ofFloat(this, "translationY", 0f, height / 4f)
animatorSet.playTogether(object1, object2)
return animatorSet
}
fun View.fadeOutDown(): AnimatorSet {
val animatorSet = AnimatorSet()
val height = -height.toFloat()
val object1: ObjectAnimator = ObjectAnimator.ofFloat(this, "alpha", 1f, 0f)
val object2: ObjectAnimator = ObjectAnimator.ofFloat(this, "translationY", 0f, height / 4f)
animatorSet.playTogether(object1, object2)
return animatorSet
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment