Fix ChaptersPagesSheet nested scrolling
This commit is contained in:
@@ -0,0 +1,50 @@
|
|||||||
|
package org.koitharu.kotatsu.core.ui.util
|
||||||
|
|
||||||
|
import android.view.View
|
||||||
|
import androidx.coordinatorlayout.widget.CoordinatorLayout
|
||||||
|
import androidx.core.view.ancestors
|
||||||
|
import androidx.lifecycle.DefaultLifecycleObserver
|
||||||
|
import androidx.lifecycle.Lifecycle.State.RESUMED
|
||||||
|
import androidx.lifecycle.LifecycleOwner
|
||||||
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
|
import com.google.android.material.bottomsheet.BottomSheetBehavior
|
||||||
|
|
||||||
|
class PagerNestedScrollHelper(
|
||||||
|
private val recyclerView: RecyclerView,
|
||||||
|
) : DefaultLifecycleObserver {
|
||||||
|
|
||||||
|
fun bind(lifecycleOwner: LifecycleOwner) {
|
||||||
|
lifecycleOwner.lifecycle.addObserver(this)
|
||||||
|
recyclerView.isNestedScrollingEnabled = lifecycleOwner.lifecycle.currentState.isAtLeast(RESUMED)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onPause(owner: LifecycleOwner) {
|
||||||
|
recyclerView.isNestedScrollingEnabled = false
|
||||||
|
invalidateBottomSheetScrollTarget()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onResume(owner: LifecycleOwner) {
|
||||||
|
recyclerView.isNestedScrollingEnabled = true
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onDestroy(owner: LifecycleOwner) {
|
||||||
|
owner.lifecycle.removeObserver(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Here we need to invalidate the `nestedScrollingChildRef` of the [BottomSheetBehavior]
|
||||||
|
*/
|
||||||
|
private fun invalidateBottomSheetScrollTarget() {
|
||||||
|
var handleCoordinator = false
|
||||||
|
for (parent in recyclerView.ancestors) {
|
||||||
|
if (handleCoordinator && parent is CoordinatorLayout) {
|
||||||
|
parent.requestLayout()
|
||||||
|
break
|
||||||
|
}
|
||||||
|
val lp = (parent as? View)?.layoutParams ?: continue
|
||||||
|
if (lp is CoordinatorLayout.LayoutParams && lp.behavior is BottomSheetBehavior<*>) {
|
||||||
|
handleCoordinator = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -156,7 +156,6 @@ class DetailsActivity :
|
|||||||
viewBinding.chipsTags.onChipClickListener = this
|
viewBinding.chipsTags.onChipClickListener = this
|
||||||
TitleScrollCoordinator(viewBinding.textViewTitle).attach(viewBinding.scrollView)
|
TitleScrollCoordinator(viewBinding.textViewTitle).attach(viewBinding.scrollView)
|
||||||
viewBinding.containerBottomSheet?.let { BottomSheetBehavior.from(it) }?.let { behavior ->
|
viewBinding.containerBottomSheet?.let { BottomSheetBehavior.from(it) }?.let { behavior ->
|
||||||
behavior.addBottomSheetCallback(BottomSheetNoHalfExpandedCallback())
|
|
||||||
onBackPressedDispatcher.addCallback(BottomSheetClollapseCallback(behavior))
|
onBackPressedDispatcher.addCallback(BottomSheetClollapseCallback(behavior))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ import org.koitharu.kotatsu.core.util.ext.doOnPageChanged
|
|||||||
import org.koitharu.kotatsu.core.util.ext.menuView
|
import org.koitharu.kotatsu.core.util.ext.menuView
|
||||||
import org.koitharu.kotatsu.core.util.ext.observe
|
import org.koitharu.kotatsu.core.util.ext.observe
|
||||||
import org.koitharu.kotatsu.core.util.ext.observeEvent
|
import org.koitharu.kotatsu.core.util.ext.observeEvent
|
||||||
|
import org.koitharu.kotatsu.core.util.ext.recyclerView
|
||||||
import org.koitharu.kotatsu.core.util.ext.setTabsEnabled
|
import org.koitharu.kotatsu.core.util.ext.setTabsEnabled
|
||||||
import org.koitharu.kotatsu.core.util.ext.showDistinct
|
import org.koitharu.kotatsu.core.util.ext.showDistinct
|
||||||
import org.koitharu.kotatsu.core.util.ext.withArgs
|
import org.koitharu.kotatsu.core.util.ext.withArgs
|
||||||
@@ -56,6 +57,7 @@ class ChaptersPagesSheet : BaseAdaptiveSheet<SheetChaptersPagesBinding>(), Actio
|
|||||||
defaultTab = (defaultTab - 1).coerceAtLeast(TAB_CHAPTERS)
|
defaultTab = (defaultTab - 1).coerceAtLeast(TAB_CHAPTERS)
|
||||||
}
|
}
|
||||||
binding.pager.offscreenPageLimit = adapter.itemCount
|
binding.pager.offscreenPageLimit = adapter.itemCount
|
||||||
|
binding.pager.recyclerView?.isNestedScrollingEnabled = false
|
||||||
binding.pager.adapter = adapter
|
binding.pager.adapter = adapter
|
||||||
binding.pager.doOnPageChanged(::onPageChanged)
|
binding.pager.doOnPageChanged(::onPageChanged)
|
||||||
TabLayoutMediator(binding.tabs, binding.pager, adapter).attach()
|
TabLayoutMediator(binding.tabs, binding.pager, adapter).attach()
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import org.koitharu.kotatsu.bookmarks.ui.sheet.BookmarksAdapter
|
|||||||
import org.koitharu.kotatsu.core.prefs.AppSettings
|
import org.koitharu.kotatsu.core.prefs.AppSettings
|
||||||
import org.koitharu.kotatsu.core.ui.BaseFragment
|
import org.koitharu.kotatsu.core.ui.BaseFragment
|
||||||
import org.koitharu.kotatsu.core.ui.list.OnListItemClickListener
|
import org.koitharu.kotatsu.core.ui.list.OnListItemClickListener
|
||||||
|
import org.koitharu.kotatsu.core.ui.util.PagerNestedScrollHelper
|
||||||
import org.koitharu.kotatsu.core.util.ext.dismissParentDialog
|
import org.koitharu.kotatsu.core.util.ext.dismissParentDialog
|
||||||
import org.koitharu.kotatsu.core.util.ext.findParentCallback
|
import org.koitharu.kotatsu.core.util.ext.findParentCallback
|
||||||
import org.koitharu.kotatsu.core.util.ext.observe
|
import org.koitharu.kotatsu.core.util.ext.observe
|
||||||
@@ -69,6 +70,8 @@ class MangaBookmarksFragment : BaseFragment<FragmentMangaBookmarksBinding>(),
|
|||||||
viewModel.gridScale.observe(viewLifecycleOwner, ::onGridScaleChanged) // before rv initialization
|
viewModel.gridScale.observe(viewLifecycleOwner, ::onGridScaleChanged) // before rv initialization
|
||||||
with(binding.recyclerView) {
|
with(binding.recyclerView) {
|
||||||
addItemDecoration(TypedListSpacingDecoration(context, false))
|
addItemDecoration(TypedListSpacingDecoration(context, false))
|
||||||
|
setHasFixedSize(true)
|
||||||
|
PagerNestedScrollHelper(this).bind(viewLifecycleOwner)
|
||||||
adapter = bookmarksAdapter
|
adapter = bookmarksAdapter
|
||||||
addOnLayoutChangeListener(spanResolver)
|
addOnLayoutChangeListener(spanResolver)
|
||||||
(layoutManager as GridLayoutManager).let {
|
(layoutManager as GridLayoutManager).let {
|
||||||
@@ -76,7 +79,7 @@ class MangaBookmarksFragment : BaseFragment<FragmentMangaBookmarksBinding>(),
|
|||||||
it.spanCount = checkNotNull(spanResolver).spanCount
|
it.spanCount = checkNotNull(spanResolver).spanCount
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
viewModel.content.observe(viewLifecycleOwner, checkNotNull(bookmarksAdapter))
|
viewModel.content.observe(viewLifecycleOwner) { bookmarksAdapter?.setItems(it, listCommitCallback) }
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onDestroyView() {
|
override fun onDestroyView() {
|
||||||
@@ -86,17 +89,6 @@ class MangaBookmarksFragment : BaseFragment<FragmentMangaBookmarksBinding>(),
|
|||||||
super.onDestroyView()
|
super.onDestroyView()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onPause() {
|
|
||||||
// required for BottomSheetBehavior
|
|
||||||
requireViewBinding().recyclerView.isNestedScrollingEnabled = false
|
|
||||||
super.onPause()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onResume() {
|
|
||||||
requireViewBinding().recyclerView.isNestedScrollingEnabled = true
|
|
||||||
super.onResume()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onWindowInsetsChanged(insets: Insets) = Unit
|
override fun onWindowInsetsChanged(insets: Insets) = Unit
|
||||||
|
|
||||||
override fun onItemClick(item: Bookmark, view: View) {
|
override fun onItemClick(item: Bookmark, view: View) {
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ import org.koitharu.kotatsu.R
|
|||||||
import org.koitharu.kotatsu.core.ui.BaseFragment
|
import org.koitharu.kotatsu.core.ui.BaseFragment
|
||||||
import org.koitharu.kotatsu.core.ui.list.ListSelectionController
|
import org.koitharu.kotatsu.core.ui.list.ListSelectionController
|
||||||
import org.koitharu.kotatsu.core.ui.list.OnListItemClickListener
|
import org.koitharu.kotatsu.core.ui.list.OnListItemClickListener
|
||||||
|
import org.koitharu.kotatsu.core.ui.util.PagerNestedScrollHelper
|
||||||
import org.koitharu.kotatsu.core.util.RecyclerViewScrollCallback
|
import org.koitharu.kotatsu.core.util.RecyclerViewScrollCallback
|
||||||
import org.koitharu.kotatsu.core.util.ext.dismissParentDialog
|
import org.koitharu.kotatsu.core.util.ext.dismissParentDialog
|
||||||
import org.koitharu.kotatsu.core.util.ext.findAppCompatDelegate
|
import org.koitharu.kotatsu.core.util.ext.findAppCompatDelegate
|
||||||
@@ -80,7 +81,7 @@ class ChaptersFragment :
|
|||||||
addItemDecoration(TypedListSpacingDecoration(context, true))
|
addItemDecoration(TypedListSpacingDecoration(context, true))
|
||||||
checkNotNull(selectionController).attachToRecyclerView(this)
|
checkNotNull(selectionController).attachToRecyclerView(this)
|
||||||
setHasFixedSize(true)
|
setHasFixedSize(true)
|
||||||
isNestedScrollingEnabled = false
|
PagerNestedScrollHelper(this).bind(viewLifecycleOwner)
|
||||||
adapter = chaptersAdapter
|
adapter = chaptersAdapter
|
||||||
ChapterGridSpanHelper.attach(this)
|
ChapterGridSpanHelper.attach(this)
|
||||||
}
|
}
|
||||||
@@ -101,17 +102,6 @@ class ChaptersFragment :
|
|||||||
super.onDestroyView()
|
super.onDestroyView()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onPause() {
|
|
||||||
// required for BottomSheetBehavior
|
|
||||||
requireViewBinding().recyclerViewChapters.isNestedScrollingEnabled = false
|
|
||||||
super.onPause()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onResume() {
|
|
||||||
requireViewBinding().recyclerViewChapters.isNestedScrollingEnabled = true
|
|
||||||
super.onResume()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onItemClick(item: ChapterListItem, view: View) {
|
override fun onItemClick(item: ChapterListItem, view: View) {
|
||||||
if (selectionController?.onItemClick(item.chapter.id) == true) {
|
if (selectionController?.onItemClick(item.chapter.id) == true) {
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ import org.koitharu.kotatsu.core.prefs.AppSettings
|
|||||||
import org.koitharu.kotatsu.core.ui.BaseFragment
|
import org.koitharu.kotatsu.core.ui.BaseFragment
|
||||||
import org.koitharu.kotatsu.core.ui.list.BoundsScrollListener
|
import org.koitharu.kotatsu.core.ui.list.BoundsScrollListener
|
||||||
import org.koitharu.kotatsu.core.ui.list.OnListItemClickListener
|
import org.koitharu.kotatsu.core.ui.list.OnListItemClickListener
|
||||||
|
import org.koitharu.kotatsu.core.ui.util.PagerNestedScrollHelper
|
||||||
import org.koitharu.kotatsu.core.util.RecyclerViewScrollCallback
|
import org.koitharu.kotatsu.core.util.RecyclerViewScrollCallback
|
||||||
import org.koitharu.kotatsu.core.util.ext.dismissParentDialog
|
import org.koitharu.kotatsu.core.util.ext.dismissParentDialog
|
||||||
import org.koitharu.kotatsu.core.util.ext.findParentCallback
|
import org.koitharu.kotatsu.core.util.ext.findParentCallback
|
||||||
@@ -93,7 +94,7 @@ class PagesFragment :
|
|||||||
addItemDecoration(TypedListSpacingDecoration(context, false))
|
addItemDecoration(TypedListSpacingDecoration(context, false))
|
||||||
adapter = thumbnailsAdapter
|
adapter = thumbnailsAdapter
|
||||||
setHasFixedSize(true)
|
setHasFixedSize(true)
|
||||||
isNestedScrollingEnabled = false
|
PagerNestedScrollHelper(this).bind(viewLifecycleOwner)
|
||||||
addOnLayoutChangeListener(spanResolver)
|
addOnLayoutChangeListener(spanResolver)
|
||||||
addOnScrollListener(ScrollListener().also { scrollListener = it })
|
addOnScrollListener(ScrollListener().also { scrollListener = it })
|
||||||
(layoutManager as GridLayoutManager).let {
|
(layoutManager as GridLayoutManager).let {
|
||||||
@@ -117,17 +118,6 @@ class PagesFragment :
|
|||||||
super.onDestroyView()
|
super.onDestroyView()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onPause() {
|
|
||||||
// required for BottomSheetBehavior
|
|
||||||
requireViewBinding().recyclerView.isNestedScrollingEnabled = false
|
|
||||||
super.onPause()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onResume() {
|
|
||||||
requireViewBinding().recyclerView.isNestedScrollingEnabled = true
|
|
||||||
super.onResume()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onWindowInsetsChanged(insets: Insets) = Unit
|
override fun onWindowInsetsChanged(insets: Insets) = Unit
|
||||||
|
|
||||||
override fun onItemClick(item: PageThumbnail, view: View) {
|
override fun onItemClick(item: PageThumbnail, view: View) {
|
||||||
|
|||||||
@@ -406,7 +406,7 @@
|
|||||||
android:nestedScrollingEnabled="false"
|
android:nestedScrollingEnabled="false"
|
||||||
android:outlineProvider="background"
|
android:outlineProvider="background"
|
||||||
app:behavior_fitToContents="false"
|
app:behavior_fitToContents="false"
|
||||||
app:behavior_halfExpandedRatio="0.00001"
|
app:behavior_halfExpandedRatio="0.8"
|
||||||
app:behavior_hideable="false"
|
app:behavior_hideable="false"
|
||||||
app:behavior_peekHeight="@dimen/details_bs_peek_height"
|
app:behavior_peekHeight="@dimen/details_bs_peek_height"
|
||||||
app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior"
|
app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior"
|
||||||
|
|||||||
Reference in New Issue
Block a user