Added animations for toolbar transitions

This commit is contained in:
Viktor De Pasquale 2019-10-20 11:14:49 +02:00
parent b910db322b
commit 44f7c9a545
2 changed files with 13 additions and 2 deletions

View File

@ -1,7 +1,11 @@
package com.topjohnwu.magisk.extensions
import android.view.View
import android.view.ViewGroup
import android.view.ViewTreeObserver
import androidx.interpolator.view.animation.FastOutSlowInInterpolator
import androidx.transition.AutoTransition
import androidx.transition.TransitionManager
fun View.setOnViewReadyListener(callback: () -> Unit) = addOnGlobalLayoutListener(true, callback)
@ -12,3 +16,8 @@ fun View.addOnGlobalLayoutListener(oneShot: Boolean = false, callback: () -> Uni
callback()
}
})
fun ViewGroup.startAnimations() {
val transition = AutoTransition().setInterpolator(FastOutSlowInInterpolator())
TransitionManager.beginDelayedTransition(this, transition)
}

View File

@ -16,6 +16,7 @@ import com.ncapdevi.fragnav.FragNavController
import com.topjohnwu.magisk.Const
import com.topjohnwu.magisk.R
import com.topjohnwu.magisk.databinding.ActivityMainMd2Binding
import com.topjohnwu.magisk.extensions.startAnimations
import com.topjohnwu.magisk.model.navigation.Navigation
import com.topjohnwu.magisk.redesign.compat.CompatActivity
import com.topjohnwu.magisk.redesign.compat.CompatNavigationDelegate
@ -136,7 +137,8 @@ open class MainActivity : CompatActivity<MainViewModel, ActivityMainMd2Binding>(
viewModel.insets.value = insets
}
fun setDisplayHomeAsUpEnabled(isEnabled: Boolean) {
private fun setDisplayHomeAsUpEnabled(isEnabled: Boolean) {
binding.mainToolbar.startAnimations()
when {
isEnabled -> binding.mainToolbar.setNavigationIcon(R.drawable.ic_back_md2)
else -> binding.mainToolbar.navigationIcon = null