嵌套滚动在底部表格中

发布于 2025-01-26 18:51:54 字数 1444 浏览 4 评论 0原文

是2022年,我在ViewPager2上与ViewPager遇到的同样问题(请参见嵌套在底部表格式的视角内部的盘旋) - 5年前。

尽管我不使用底部纸张fragment,但只有一个普通的旧底纸(带有片段范围)。

ViewPager2有点不同,因为它本身使用了水平回收库。 bottomSheetView.findscollingchild()将其视为滚动孩子!

因此,我采用的方法是:

  1. 在我的ViewPager2中添加了一个页面更改侦听器,以获取托管 coordinatorLayout,并在页面更改后调用requestLayout()

  2. 复制了与我当前的材料组件版本(1.5)匹配的底部表贝哈维尔类,并将其重命名,并将FindScrollingChild公开。

  3. 将该副本分类,并将子类设置为我的工作表上的行为。

为什么不仅会直接更改FindsCrollingChild方法?好吧,这样,当我们更新材料组件时,更新底部表贝哈维尔的副本相对容易。

我专门针对ViewPager2的子类检查中FindScrollingChild()的实现。

如果是的话,它会使viewPager2(水平回收库)的孩子0,然后使用recycler?.layoutManager?.findViewByposition(pager.currentitem)作为视图,然后搜索滚动孩子。

如果视图不是viewPager2,则使用原始findsCrollingChild()

this 基本上是 works的相同算法。我有一个带有2个选项卡的寻呼机,一个包含启用滚动滚动的scollView,一个包含回收库。底部的纸张随着其滚动而扩展,然后在纸张打开后正确向下滚动的内容。

问题是,如果抬高手指,纸张膨胀后,任何尝试向上滚动的尝试都会导致底部纸关闭而不是向上滚动 - 无论滚动多远。至少在第二个选项卡中的回收瓶是这种情况,我在第一个选项卡中没有足够的内容实际上需要滚动。

列表仍然滚动了几页(或您停止滚动的任何地方)都关闭。但是,如果您向下滚动(甚至只是一点),请再次滚动工作!而且您可以滑动几次,并且可以工作 - 直到它不行为止,并且床单移至一半扩展状态。

我不确定这种行为来自何处或如何解决。当底部表具有直接的recyclerview时(没有ViewPager2,我就是这样)。

我尝试在ViewPager2中禁用刷动,以为它可能正在干扰触摸事件,但无济于事。

It's 2022, and I'm having the same issue with ViewPager2 that folks had with ViewPager (see NestedScrolling inside a Viewpager inside a BottomSheetDialog ) - 5 years ago.

Although I'm not using a BottomSheetDialogFragment, just a regular old bottom sheet (with a FragmentContainer).

ViewPager2 is a bit different in that it itself uses a horizontal RecyclerView. BottomSheetView.findScollingChild() sees this as the scrolling child!

So, the approach I took to solving this is:

  1. added a page change listener to my ViewPager2 that gets the hosting
    CoordinatorLayout, and calls requestLayout() on it after the page change.

  2. copied the BottomSheetBehavior class that matches my current material components version (1.5) into my project, renamed it, and made findScrollingChild public.

  3. subclassed that copy, and set the sub-class as the behavior on my sheet.

Why sub-class and not just change the findScrollingChild method directly? Well, this way it's relatively easy to update the copy of BottomSheetBehavior when we update our material components.

My implementation of findScrollingChild() in the sub-class checks specifically for a ViewPager2.

If it is, it gets child 0 of the ViewPager2 (the horizontal RecyclerView), and then uses recycler?.layoutManager?.findViewByPosition(pager.currentItem) as the view to then search for the scrolling child.

If the view is not a ViewPager2, it uses the same algorithm from the original findScrollingChild()

This basically works. I have a pager with 2 tabs, one containing a ScollView that has nested scrolling enabled, and one containing a RecyclerView. The bottom sheet expands as its scrolled, and then the contents of the nested child scroll down properly once the sheet is open.

The problem is if after the sheet has expanded if the finger gets lifted, then any attempt to scroll up causes the bottom sheet to close rather then scrolling up -- no matter how far it's been scrolled down. At least this is the case for the RecyclerView in the second tab, I don't have enough content in the first tab at the moment that it actually needs to scroll.

The sheet gets closed with the list still scrolled down several pages (or wherever you stopped scrolling). If however you scroll down -- even just a little bit -- scrolling up works again! And you can swipe a couple times and it will work - until it doesn't, and the sheet moves to the half expanded state.

I'm not sure where this behavior is coming from or how to resolve it. It doesn't happen when the bottom sheet has a direct RecyclerView (no ViewPager2 I'm the way).

I tried disabling swiping in the ViewPager2 thinking it might be interfering with touch events, but to no avail.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文