Skip to content

Commit

Permalink
Implement circularUnRevealed animation when dismiss
Browse files Browse the repository at this point in the history
  • Loading branch information
skydoves committed Feb 16, 2020
1 parent 8b9bd84 commit b66d341
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class ProfileBalloonFactory : Balloon.Factory() {
setHeight(250)
setCornerRadius(4f)
setBackgroundColorResource(R.color.white)
setBalloonAnimation(BalloonAnimation.OVERSHOOT)
setBalloonAnimation(BalloonAnimation.CIRCULAR)
setDismissWhenShowAgain(true)
setLifecycleOwner(lifecycle)
}
Expand Down
10 changes: 9 additions & 1 deletion balloon/src/main/java/com/skydoves/balloon/Balloon.kt
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,15 @@ class Balloon(
fun dismiss() {
if (this.isShowing) {
this.isShowing = false
this.bodyWindow.dismiss()

val dismissWindow: () -> Unit = { this.bodyWindow.dismiss() }
if (this.builder.balloonAnimation == BalloonAnimation.CIRCULAR) {
this.bodyWindow.contentView.circularUnRevealed() {
dismissWindow()
}
} else {
dismissWindow()
}
}
}

Expand Down
52 changes: 43 additions & 9 deletions balloon/src/main/java/com/skydoves/balloon/ViewExtension.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,16 @@

package com.skydoves.balloon

import android.animation.Animator
import android.animation.AnimatorListenerAdapter
import android.os.Build
import android.view.View
import android.view.ViewAnimationUtils
import androidx.annotation.MainThread
import kotlin.math.max

/** makes visible or invisible a View align the value parameter. */
@MainThread
internal fun View.visible(value: Boolean) {
if (value) {
this.visibility = View.VISIBLE
Expand All @@ -30,8 +34,46 @@ internal fun View.visible(value: Boolean) {
}
}

@MainThread
/** shows circular revealed animation to a view. */
internal fun View.circularRevealed() {
doOnLayoutChanged {
val view = this
ViewAnimationUtils.createCircularReveal(
view,
(view.left + view.right) / 2,
(view.top + view.bottom) / 2,
0f,
max(view.width, view.height).toFloat()).apply {
duration = 500
start()
}
}
}

@MainThread
internal fun View.circularUnRevealed(doAfterFinish: () -> Unit) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
val view = this
ViewAnimationUtils.createCircularReveal(
view,
(view.left + view.right) / 2,
(view.top + view.bottom) / 2,
max(view.width, view.height).toFloat(),
0f).apply {
duration = 500
start()
}.addListener(object : AnimatorListenerAdapter() {
override fun onAnimationEnd(animation: Animator?) {
super.onAnimationEnd(animation)
doAfterFinish()
}
})
}
}

@MainThread
internal fun View.doOnLayoutChanged(block: () -> Unit) {
this.addOnLayoutChangeListener(
object : View.OnLayoutChangeListener {
override fun onLayoutChange(
Expand All @@ -47,15 +89,7 @@ internal fun View.circularRevealed() {
) {
view.removeOnLayoutChangeListener(this)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
ViewAnimationUtils.createCircularReveal(
view,
(view.left + view.right) / 2,
(view.top + view.bottom) / 2,
0f,
max(view.width, view.height).toFloat()).run {
duration = 500
start()
}
block()
}
}
})
Expand Down

0 comments on commit b66d341

Please sign in to comment.