Respect system animation disabling #341

This commit is contained in:
Koitharu
2023-04-07 18:33:47 +03:00
parent dba506cb42
commit 16c3e61984
8 changed files with 54 additions and 44 deletions

View File

@@ -18,6 +18,7 @@ import org.koitharu.kotatsu.reader.ui.pager.BaseReaderAdapter
import org.koitharu.kotatsu.reader.ui.pager.ReaderPage
import org.koitharu.kotatsu.reader.ui.pager.standard.PagerReaderFragment
import org.koitharu.kotatsu.utils.ext.doOnPageChanged
import org.koitharu.kotatsu.utils.ext.isAnimationsEnabled
import org.koitharu.kotatsu.utils.ext.recyclerView
import org.koitharu.kotatsu.utils.ext.resetTransformations
import org.koitharu.kotatsu.utils.ext.viewLifecycleScope
@@ -74,15 +75,17 @@ class ReversedReaderFragment : BaseReader<FragmentReaderStandardBinding>() {
override fun switchPageBy(delta: Int) {
with(binding.pager) {
setCurrentItem(currentItem - delta, true)
setCurrentItem(currentItem - delta, context.isAnimationsEnabled)
}
}
override fun switchPageTo(position: Int, smooth: Boolean) {
binding.pager.setCurrentItem(
reversed(position),
smooth && (binding.pager.currentItem - position).absoluteValue < PagerReaderFragment.SMOOTH_SCROLL_LIMIT,
)
with(binding.pager) {
setCurrentItem(
reversed(position),
smooth && context.isAnimationsEnabled && (currentItem - position).absoluteValue < PagerReaderFragment.SMOOTH_SCROLL_LIMIT,
)
}
}
override fun onPagesChanged(pages: List<ReaderPage>, pendingState: ReaderState?) {

View File

@@ -17,6 +17,7 @@ import org.koitharu.kotatsu.reader.ui.pager.BaseReader
import org.koitharu.kotatsu.reader.ui.pager.BaseReaderAdapter
import org.koitharu.kotatsu.reader.ui.pager.ReaderPage
import org.koitharu.kotatsu.utils.ext.doOnPageChanged
import org.koitharu.kotatsu.utils.ext.isAnimationsEnabled
import org.koitharu.kotatsu.utils.ext.recyclerView
import org.koitharu.kotatsu.utils.ext.resetTransformations
import org.koitharu.kotatsu.utils.ext.viewLifecycleScope
@@ -93,15 +94,17 @@ class PagerReaderFragment : BaseReader<FragmentReaderStandardBinding>() {
override fun switchPageBy(delta: Int) {
with(binding.pager) {
setCurrentItem(currentItem + delta, true)
setCurrentItem(currentItem + delta, context.isAnimationsEnabled)
}
}
override fun switchPageTo(position: Int, smooth: Boolean) {
binding.pager.setCurrentItem(
position,
smooth && (binding.pager.currentItem - position).absoluteValue < SMOOTH_SCROLL_LIMIT,
)
with(binding.pager) {
setCurrentItem(
position,
smooth && context.isAnimationsEnabled && (currentItem - position).absoluteValue < SMOOTH_SCROLL_LIMIT,
)
}
}
override fun getCurrentState(): ReaderState? = bindingOrNull()?.run {

View File

@@ -17,6 +17,7 @@ import org.koitharu.kotatsu.reader.ui.pager.BaseReaderAdapter
import org.koitharu.kotatsu.reader.ui.pager.ReaderPage
import org.koitharu.kotatsu.utils.ext.findCenterViewPosition
import org.koitharu.kotatsu.utils.ext.firstVisibleItemPosition
import org.koitharu.kotatsu.utils.ext.isAnimationsEnabled
import org.koitharu.kotatsu.utils.ext.viewLifecycleScope
import javax.inject.Inject
@@ -103,11 +104,13 @@ class WebtoonReaderFragment : BaseReader<FragmentReaderWebtoonBinding>() {
}
override fun switchPageBy(delta: Int) {
binding.recyclerView.smoothScrollBy(
0,
(binding.recyclerView.height * 0.9).toInt() * delta,
scrollInterpolator,
)
with(binding.recyclerView) {
if (context.isAnimationsEnabled) {
smoothScrollBy(0, (height * 0.9).toInt() * delta, scrollInterpolator)
} else {
nestedScrollBy(0, (height * 0.9).toInt() * delta)
}
}
}
override fun switchPageTo(position: Int, smooth: Boolean) {