Skip to content

Commit

Permalink
For mozilla-mobile#9044 - Improved DynamicDownloadDialog behaviour wh…
Browse files Browse the repository at this point in the history
…en scrolling
  • Loading branch information
codrut.topliceanu committed May 19, 2020
1 parent c2083d8 commit 6c9b5b7
Showing 1 changed file with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ class DynamicDownloadDialogBehavior<V : View>(
private val bottomToolbarHeight: Float = 0f
) : CoordinatorLayout.Behavior<V>(context, attrs) {

private var expanded: Boolean = true

@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
internal var shouldSnapAfterScroll: Boolean = false

Expand Down Expand Up @@ -93,13 +95,14 @@ class DynamicDownloadDialogBehavior<V : View>(
type: Int
) {
if (shouldSnapAfterScroll || type == ViewCompat.TYPE_NON_TOUCH) {
val minHeight: Float =
if (bottomToolbarHeight > 0) bottomToolbarHeight else child.height.toFloat()

if (child.translationY >= minHeight / 2) {
animateSnap(child, SnapDirection.DOWN)
if (expanded) {
if (child.translationY >= bottomToolbarHeight / 2)
animateSnap(child, SnapDirection.DOWN)
else animateSnap(child, SnapDirection.UP)
} else {
animateSnap(child, SnapDirection.UP)
if (child.translationY < (bottomToolbarHeight + child.height.toFloat() / 2))
animateSnap(child, SnapDirection.UP)
else animateSnap(child, SnapDirection.DOWN)
}
}
}
Expand Down Expand Up @@ -140,6 +143,7 @@ class DynamicDownloadDialogBehavior<V : View>(

@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
internal fun animateSnap(child: View, direction: SnapDirection) = with(snapAnimator) {
expanded = direction == SnapDirection.UP
addUpdateListener { child.translationY = it.animatedValue as Float }
setFloatValues(
child.translationY,
Expand Down

0 comments on commit 6c9b5b7

Please sign in to comment.