Skip to content

Commit b87f469

Browse files
committed
Prevent back press while FluidContentResizer is animating
1 parent a1d4e75 commit b87f469

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

Diff for: app/src/main/java/com/ricknout/rugbyranker/MainActivity.kt

+1
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ class MainActivity : DaggerAppCompatActivity(), OnBackPressedProvider {
6565
}
6666

6767
override fun onBackPressed() {
68+
if (FluidContentResizer.isAnimating()) return
6869
val onBackPressedHandled = onBackPressedListener?.onBackPressed() ?: false
6970
if (!onBackPressedHandled) super.onBackPressed()
7071
}

Diff for: common/src/main/java/me/saket/fluidresize/sample/FluidContentResizer.kt

+3-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ object FluidContentResizer {
2424
}
2525
}
2626

27+
fun isAnimating() = heightAnimator.isStarted || heightAnimator.isRunning
28+
2729
private fun animateHeight(viewHolder: ActivityViewHolder, event: KeyboardVisibilityChanged) {
2830
val contentView = viewHolder.contentView
2931
contentView.setHeight(event.contentHeightBeforeResize)
@@ -36,7 +38,7 @@ object FluidContentResizer {
3638
// for some reason it skips the first animation and I cannot figure out why.
3739
heightAnimator = ObjectAnimator.ofInt(event.contentHeightBeforeResize, event.contentHeight).apply {
3840
interpolator = FastOutSlowInInterpolator()
39-
duration = 200
41+
duration = 150
4042
}
4143
heightAnimator.addUpdateListener { contentView.setHeight(it.animatedValue as Int) }
4244
heightAnimator.start()

0 commit comments

Comments
 (0)