Remove up/down animation for FAB, add list padding (#2456)

This commit is contained in:
arkon 2020-01-08 21:33:10 -05:00 committed by GitHub
parent 6025b44e5b
commit e411f54236
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 9 additions and 91 deletions

View File

@ -1,35 +0,0 @@
package eu.kanade.tachiyomi.widget
import androidx.coordinatorlayout.widget.CoordinatorLayout
import com.google.android.material.floatingactionbutton.FloatingActionButton
import androidx.core.view.ViewCompat
import android.view.View
abstract class FABAnimationBase : FloatingActionButton.Behavior() {
var isAnimatingOut = false
override fun onStartNestedScroll(coordinatorLayout: CoordinatorLayout, child: FloatingActionButton,
directTargetChild: View, target: View, axes: Int, type: Int): Boolean {
// Ensure we react to vertical scrolling
return axes == ViewCompat.SCROLL_AXIS_VERTICAL ||
super.onStartNestedScroll(coordinatorLayout, child, directTargetChild, target, axes, type)
}
override fun onNestedScroll(coordinatorLayout: CoordinatorLayout, child: FloatingActionButton,
target: View, dxConsumed: Int, dyConsumed: Int, dxUnconsumed: Int,
dyUnconsumed: Int, type: Int) {
super.onNestedScroll(coordinatorLayout, child, target, dxConsumed, dyConsumed, dxUnconsumed, dyUnconsumed, type)
if (dyConsumed > 0 && !isAnimatingOut && child.visibility == View.VISIBLE) {
// User scrolled down and the FAB is currently visible -> hide the FAB
animateOut(child)
} else if (dyConsumed < 0 && child.visibility != View.VISIBLE) {
// User scrolled up and the FAB is currently not visible -> show the FAB
animateIn(child)
}
}
abstract fun animateOut(button: FloatingActionButton)
abstract fun animateIn(button: FloatingActionButton)
}

View File

@ -1,51 +0,0 @@
package eu.kanade.tachiyomi.widget
import android.content.Context
import com.google.android.material.floatingactionbutton.FloatingActionButton
import androidx.interpolator.view.animation.FastOutSlowInInterpolator
import android.util.AttributeSet
import android.view.View
import android.view.animation.Animation
import android.view.animation.AnimationUtils
import eu.kanade.tachiyomi.R
@Suppress("unused", "UNUSED_PARAMETER")
class FABAnimationUpDown @JvmOverloads constructor(ctx: Context, attrs: AttributeSet? = null) : FABAnimationBase() {
private val INTERPOLATOR = FastOutSlowInInterpolator()
private val outAnimation by lazy {
AnimationUtils.loadAnimation(ctx, R.anim.fab_hide_to_bottom).apply {
duration = 200
interpolator = INTERPOLATOR
}
}
private val inAnimation by lazy {
AnimationUtils.loadAnimation(ctx, R.anim.fab_show_from_bottom).apply {
duration = 200
interpolator = INTERPOLATOR
}
}
override fun animateOut(button: FloatingActionButton) {
outAnimation.setAnimationListener(object : Animation.AnimationListener {
override fun onAnimationStart(animation: Animation) {
isAnimatingOut = true
}
override fun onAnimationEnd(animation: Animation) {
isAnimatingOut = false
button.visibility = View.INVISIBLE
}
override fun onAnimationRepeat(animation: Animation) {
}
})
button.startAnimation(outAnimation)
}
override fun animateIn(button: FloatingActionButton) {
button.visibility = View.VISIBLE
button.startAnimation(inAnimation)
}
}

View File

@ -6,12 +6,13 @@
android:layout_height="match_parent">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/recycler"
android:choiceMode="multipleChoice"
tools:listitem="@layout/categories_item"
/>
android:paddingBottom="@dimen/fab_list_padding"
android:clipToPadding="false"
tools:listitem="@layout/categories_item" />
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fab"

View File

@ -28,6 +28,8 @@
android:layout_height="match_parent"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:paddingBottom="@dimen/fab_list_padding"
android:clipToPadding="false"
android:descendantFocusability="blocksDescendants"
tools:listitem="@layout/chapters_item">

View File

@ -6,9 +6,11 @@
<dimen name="margin_bottom">16dp</dimen>
<dimen name="margin_left">16dp</dimen>
<dimen name="margin_right">16dp</dimen>
<dimen name="fab_margin">16dp</dimen>
<dimen name="space_between_cards">4dp</dimen>
<dimen name="fab_size">56dp</dimen>
<dimen name="fab_margin">16dp</dimen>
<dimen name="fab_list_padding">88dp</dimen>
<dimen name="dialog_content_padding">24dp</dimen>
<dimen name="dialog_margin_top_content">20dp</dimen>

View File

@ -145,7 +145,6 @@
<item name="android:scaleType">fitCenter</item>
<item name="layout_anchorGravity">bottom|right|end</item>
<item name="android:tint">@color/md_white_1000</item>
<item name="layout_behavior">eu.kanade.tachiyomi.widget.FABAnimationUpDown</item>
</style>
<style name="Theme.Widget.CardView" parent="CardView">