mirror of
https://github.com/mihonapp/mihon.git
synced 2024-12-24 18:08:24 +01:00
Use Compose to animate bottom reader menu bars
This commit is contained in:
parent
79b37df647
commit
97b4d1f13d
@ -24,6 +24,10 @@ import android.view.animation.Animation
|
|||||||
import android.view.animation.AnimationUtils
|
import android.view.animation.AnimationUtils
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import androidx.activity.viewModels
|
import androidx.activity.viewModels
|
||||||
|
import androidx.compose.animation.AnimatedVisibility
|
||||||
|
import androidx.compose.animation.core.tween
|
||||||
|
import androidx.compose.animation.slideInVertically
|
||||||
|
import androidx.compose.animation.slideOutVertically
|
||||||
import androidx.compose.foundation.layout.Arrangement
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
import androidx.compose.foundation.layout.Row
|
import androidx.compose.foundation.layout.Row
|
||||||
@ -249,7 +253,7 @@ class ReaderActivity : BaseActivity() {
|
|||||||
override fun onResume() {
|
override fun onResume() {
|
||||||
super.onResume()
|
super.onResume()
|
||||||
viewModel.restartReadTimer()
|
viewModel.restartReadTimer()
|
||||||
setMenuVisibility(viewModel.state.value.menuVisible, animate = false)
|
setMenuVisibility(viewModel.state.value.menuVisible)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -259,7 +263,7 @@ class ReaderActivity : BaseActivity() {
|
|||||||
override fun onWindowFocusChanged(hasFocus: Boolean) {
|
override fun onWindowFocusChanged(hasFocus: Boolean) {
|
||||||
super.onWindowFocusChanged(hasFocus)
|
super.onWindowFocusChanged(hasFocus)
|
||||||
if (hasFocus) {
|
if (hasFocus) {
|
||||||
setMenuVisibility(viewModel.state.value.menuVisible, animate = false)
|
setMenuVisibility(viewModel.state.value.menuVisible)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -473,6 +477,17 @@ class ReaderActivity : BaseActivity() {
|
|||||||
val isPagerType = ReadingModeType.isPagerType(viewModel.getMangaReadingMode())
|
val isPagerType = ReadingModeType.isPagerType(viewModel.getMangaReadingMode())
|
||||||
val cropEnabled = if (isPagerType) cropBorderPaged else cropBorderWebtoon
|
val cropEnabled = if (isPagerType) cropBorderPaged else cropBorderWebtoon
|
||||||
|
|
||||||
|
AnimatedVisibility(
|
||||||
|
visible = state.menuVisible,
|
||||||
|
enter = slideInVertically(
|
||||||
|
initialOffsetY = { it },
|
||||||
|
animationSpec = tween(200),
|
||||||
|
),
|
||||||
|
exit = slideOutVertically(
|
||||||
|
targetOffsetY = { it },
|
||||||
|
animationSpec = tween(200),
|
||||||
|
),
|
||||||
|
) {
|
||||||
Column(
|
Column(
|
||||||
verticalArrangement = Arrangement.spacedBy(8.dp),
|
verticalArrangement = Arrangement.spacedBy(8.dp),
|
||||||
) {
|
) {
|
||||||
@ -512,6 +527,7 @@ class ReaderActivity : BaseActivity() {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
val toolbarBackground = (binding.toolbar.background as MaterialShapeDrawable).apply {
|
val toolbarBackground = (binding.toolbar.background as MaterialShapeDrawable).apply {
|
||||||
elevation = resources.getDimension(R.dimen.m3_sys_elevation_level2)
|
elevation = resources.getDimension(R.dimen.m3_sys_elevation_level2)
|
||||||
@ -531,16 +547,14 @@ class ReaderActivity : BaseActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the visibility of the menu according to [visible] and with an optional parameter to
|
* Sets the visibility of the menu according to [visible].
|
||||||
* [animate] the views.
|
|
||||||
*/
|
*/
|
||||||
private fun setMenuVisibility(visible: Boolean, animate: Boolean = true) {
|
private fun setMenuVisibility(visible: Boolean) {
|
||||||
viewModel.showMenus(visible)
|
viewModel.showMenus(visible)
|
||||||
if (visible) {
|
if (visible) {
|
||||||
windowInsetsController.show(WindowInsetsCompat.Type.systemBars())
|
windowInsetsController.show(WindowInsetsCompat.Type.systemBars())
|
||||||
binding.readerMenu.isVisible = true
|
binding.readerMenu.isVisible = true
|
||||||
|
|
||||||
if (animate) {
|
|
||||||
val toolbarAnimation = AnimationUtils.loadAnimation(this, R.anim.enter_from_top)
|
val toolbarAnimation = AnimationUtils.loadAnimation(this, R.anim.enter_from_top)
|
||||||
toolbarAnimation.applySystemAnimatorScale(this)
|
toolbarAnimation.applySystemAnimatorScale(this)
|
||||||
toolbarAnimation.setAnimationListener(
|
toolbarAnimation.setAnimationListener(
|
||||||
@ -552,18 +566,12 @@ class ReaderActivity : BaseActivity() {
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
binding.toolbar.startAnimation(toolbarAnimation)
|
binding.toolbar.startAnimation(toolbarAnimation)
|
||||||
|
|
||||||
val bottomAnimation = AnimationUtils.loadAnimation(this, R.anim.enter_from_bottom)
|
|
||||||
bottomAnimation.applySystemAnimatorScale(this)
|
|
||||||
binding.readerMenuBottom.startAnimation(bottomAnimation)
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
if (readerPreferences.fullscreen().get()) {
|
if (readerPreferences.fullscreen().get()) {
|
||||||
windowInsetsController.hide(WindowInsetsCompat.Type.systemBars())
|
windowInsetsController.hide(WindowInsetsCompat.Type.systemBars())
|
||||||
windowInsetsController.systemBarsBehavior = WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
|
windowInsetsController.systemBarsBehavior = WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
|
||||||
}
|
}
|
||||||
|
|
||||||
if (animate) {
|
|
||||||
val toolbarAnimation = AnimationUtils.loadAnimation(this, R.anim.exit_to_top)
|
val toolbarAnimation = AnimationUtils.loadAnimation(this, R.anim.exit_to_top)
|
||||||
toolbarAnimation.applySystemAnimatorScale(this)
|
toolbarAnimation.applySystemAnimatorScale(this)
|
||||||
toolbarAnimation.setAnimationListener(
|
toolbarAnimation.setAnimationListener(
|
||||||
@ -574,11 +582,6 @@ class ReaderActivity : BaseActivity() {
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
binding.toolbar.startAnimation(toolbarAnimation)
|
binding.toolbar.startAnimation(toolbarAnimation)
|
||||||
|
|
||||||
val bottomAnimation = AnimationUtils.loadAnimation(this, R.anim.exit_to_bottom)
|
|
||||||
bottomAnimation.applySystemAnimatorScale(this)
|
|
||||||
binding.readerMenuBottom.startAnimation(bottomAnimation)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,8 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<set xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
android:shareInterpolator="false">
|
|
||||||
<translate
|
|
||||||
android:duration="200"
|
|
||||||
android:fromYDelta="100%"
|
|
||||||
android:toYDelta="0%" />
|
|
||||||
</set>
|
|
@ -1,8 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<set xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
android:shareInterpolator="false">
|
|
||||||
<translate
|
|
||||||
android:duration="200"
|
|
||||||
android:fromYDelta="0%"
|
|
||||||
android:toYDelta="100%" />
|
|
||||||
</set>
|
|
Loading…
Reference in New Issue
Block a user