mirror of
https://github.com/topjohnwu/Magisk.git
synced 2024-11-28 04:25:27 +00:00
Added animations for toolbar transitions
This commit is contained in:
parent
b910db322b
commit
44f7c9a545
@ -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)
|
||||||
|
}
|
@ -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
|
||||||
|
Loading…
Reference in New Issue
Block a user