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 package com.topjohnwu.magisk.extensions
import android.view.View import android.view.View
import android.view.ViewGroup
import android.view.ViewTreeObserver 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) fun View.setOnViewReadyListener(callback: () -> Unit) = addOnGlobalLayoutListener(true, callback)
@ -11,4 +15,9 @@ fun View.addOnGlobalLayoutListener(oneShot: Boolean = false, callback: () -> Uni
if (oneShot) viewTreeObserver.removeOnGlobalLayoutListener(this) if (oneShot) viewTreeObserver.removeOnGlobalLayoutListener(this)
callback() 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.Const
import com.topjohnwu.magisk.R import com.topjohnwu.magisk.R
import com.topjohnwu.magisk.databinding.ActivityMainMd2Binding import com.topjohnwu.magisk.databinding.ActivityMainMd2Binding
import com.topjohnwu.magisk.extensions.startAnimations
import com.topjohnwu.magisk.model.navigation.Navigation import com.topjohnwu.magisk.model.navigation.Navigation
import com.topjohnwu.magisk.redesign.compat.CompatActivity import com.topjohnwu.magisk.redesign.compat.CompatActivity
import com.topjohnwu.magisk.redesign.compat.CompatNavigationDelegate import com.topjohnwu.magisk.redesign.compat.CompatNavigationDelegate
@ -136,7 +137,8 @@ open class MainActivity : CompatActivity<MainViewModel, ActivityMainMd2Binding>(
viewModel.insets.value = insets viewModel.insets.value = insets
} }
fun setDisplayHomeAsUpEnabled(isEnabled: Boolean) { private fun setDisplayHomeAsUpEnabled(isEnabled: Boolean) {
binding.mainToolbar.startAnimations()
when { when {
isEnabled -> binding.mainToolbar.setNavigationIcon(R.drawable.ic_back_md2) isEnabled -> binding.mainToolbar.setNavigationIcon(R.drawable.ic_back_md2)
else -> binding.mainToolbar.navigationIcon = null else -> binding.mainToolbar.navigationIcon = null