但是,实际上,AndroidX Paging Library如何知道何时加载更多页面? [英] But really, how does the AndroidX Paging Library know when to load more pages?

查看:127
本文介绍了但是,实际上,AndroidX Paging Library如何知道何时加载更多页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

存在一个这个问题,该问题措辞完全相同.

There's this question, which is identically worded.

但是张贴者的问题得到了解决,而没有实际回答发布的问题-因为问题是由于与分页库如何加载更多页面无关.

But the poster's problem was solved without actually answering the question posted - because the problem was due to something unrelated to how the Paging Library knows to load more pages.

我想知道用于消耗Paging数据源的订阅/收集(Rx/Flow)机制是否是Paging数据源如何知道何时加载更多页面的方式.因此,也许订阅/收集会拉页面.(但即使如此,初始加载后的页面如何触发?)并且数据源可以利用pull事件作为检查是否需要加载更多页面的机会.

I'm wondering if the subscription/collection (Rx/Flow) mechanism used to consume the Paging datasource is how the Paging datasource knows when to load more pages. So maybe subscription/collection pulls pages. (But even so, how would pages after the initial load be triggered?) And the datasource can use the pull events as an opportunity to check if it needs to load more pages.

我只是在这里推测,因为我不知道这一切在内部如何工作.

I'm just speculating here because I don't know how this all works internally.

我希望有人能够证实或否认我的推测,并提供有关所涉及机制的更多详细信息.特别是当页面以Flow或(Rx)Flowable形式公开时.

I'm hoping someone will either verify or dismiss my speculation and provide greater detail about the mechanism involved. In particular, when the Pages are exposed as a Flow or (Rx) Flowable.

推荐答案

演示者API的 .get(index)调用是触发项目访问其余Paging的原因.通常,您需要调用此函数才能将项目绑定到 RecyclerView.Adapter ,但是leanback和compose的工作类似.

The presenter API's .get(index) call is what triggers item access to the rest of Paging. Generally you need to call this function in order to bind items to a RecyclerView.Adapter, but leanback and compose work similarly.

在项目访问时,将发送一个名为 ViewportHint 的内部对象,其中包含演示者状态,其中包括您可以看到多少个转换后项目以及您在列表中的当前位置,这些状态可以从以下位置异步处理UI的其余部分.

On item access, an internal object called ViewportHint is sent which contains presenter-state including how many items post-transformation you can see and your current position in the list, which can be handled asyncly from rest of UI.

分页实际上是根据 PagingConfig.prefetchDistance 触发负载的,但是具有处理竞争条件,访问合并,取消,跟踪负载状态,错误处理等的大量逻辑,所有这些因素都会影响到什么最终最终被加载.

Paging then essentially triggers loads based on PagingConfig.prefetchDistance, but has a lot of logic handling race conditions, access conflation, cancellations, tracking load state, error handling, etc. which all can affect what ends up getting loaded in the end.

如果要访问但避免触发负载,则可以使用 .peek() .snapshot() API来检查演示者状态而无需获取.

If you want to access but avoid triggering loads, there are .peek() and .snapshot() APIs that let you inspect presenter state without fetching.

这篇关于但是,实际上,AndroidX Paging Library如何知道何时加载更多页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆