Skip to content
Permalink
Browse files

Merge pull request #394 from chrisbanes/cb/details-fab

Fix FAB not always becoming visible again
  • Loading branch information...
chrisbanes committed Aug 13, 2019
2 parents b8d2c12 + 462ceeb commit 76ea31f3c6753010a536ee4e84cbda9ebe01819a
@@ -19,6 +19,8 @@ package app.tivi.ui
import androidx.constraintlayout.motion.widget.MotionLayout

open class TransitionListenerAdapter : MotionLayout.TransitionListener {
private var lastProgress = 0f

override fun onTransitionTrigger(
parent: MotionLayout,
triggerId: Int,
@@ -30,17 +32,30 @@ open class TransitionListenerAdapter : MotionLayout.TransitionListener {
parent: MotionLayout,
startId: Int,
endId: Int
) {}
) {
lastProgress = 0f
}

override fun onTransitionChange(
final override fun onTransitionChange(
parent: MotionLayout,
startId: Int,
endId: Int,
progress: Float
) {}
) {
onTransitionChange(parent, startId, endId, progress, progress > lastProgress)
lastProgress = progress
}

open fun onTransitionChange(
parent: MotionLayout,
startId: Int,
endId: Int,
progress: Float,
positive: Boolean
) = Unit

override fun onTransitionCompleted(
parent: MotionLayout,
currentId: Int
) {}
) = Unit
}
@@ -84,16 +84,36 @@ class ShowDetailsFragment : TiviMvRxFragment() {
View.SYSTEM_UI_FLAG_LAYOUT_STABLE

binding.detailsMotion.setTransitionListener(object : TransitionListenerAdapter() {
override fun onTransitionTrigger(
override fun onTransitionCompleted(parent: MotionLayout, currentId: Int) {
super.onTransitionCompleted(parent, currentId)

when (currentId) {
R.id.show_details_open -> {
if (!binding.detailsFollowFab.isOrWillBeShown) {
binding.detailsFollowFab.show()
}
}
R.id.show_details_closed -> {
if (!binding.detailsFollowFab.isOrWillBeHidden) {
binding.detailsFollowFab.hide()
}
}
}
}

override fun onTransitionChange(
parent: MotionLayout,
triggerId: Int,
positive: Boolean,
progress: Float
startId: Int,
endId: Int,
progress: Float,
positive: Boolean
) {
if (triggerId == R.id.trigger_toggle_fab) {
if (positive) {
if (startId == R.id.show_details_open && endId == R.id.show_details_closed) {
if (progress >= 0.53 && positive &&
!binding.detailsFollowFab.isOrWillBeHidden) {
binding.detailsFollowFab.hide()
} else {
} else if (progress <= 0.47 && !positive &&
!binding.detailsFollowFab.isOrWillBeShown) {
binding.detailsFollowFab.show()
}
}
@@ -19,8 +19,8 @@
xmlns:app="http://schemas.android.com/apk/res-auto">

<Transition
app:constraintSetEnd="@id/end"
app:constraintSetStart="@id/start"
app:constraintSetEnd="@id/show_details_closed"
app:constraintSetStart="@id/show_details_open"
app:duration="400"
app:motionInterpolator="easeInOut">

@@ -68,19 +68,11 @@
app:customColorValue="@color/status_bar_scrim" />
</KeyAttribute>

<!-- This will toggle the FAB visibility via the TransitionListener -->
<KeyTrigger
app:motionTarget="@id/details_appbar_background"
app:motion_postLayoutCollision="true"
app:motion_triggerOnCollision="@id/details_toolbar"
app:triggerId="@+id/trigger_toggle_fab"
app:triggerSlack="0.05" />

</KeyFrameSet>

</Transition>

<ConstraintSet android:id="@+id/start">
<ConstraintSet android:id="@+id/show_details_open">

<Constraint
android:id="@id/details_backdrop_scrim">
@@ -146,7 +138,7 @@

</ConstraintSet>

<ConstraintSet android:id="@+id/end">
<ConstraintSet android:id="@+id/show_details_closed">
<Constraint
android:id="@id/details_backdrop_scrim">
<CustomAttribute

0 comments on commit 76ea31f

Please sign in to comment.
You can’t perform that action at this time.