- Pager不应该重复创建,但是持有Pager本身没有什么意义,通常持有flow即可
- 如果需要刷新页面内容(如加载失败重试)流程如下
- 调用PagingSource中的invalidate方法
- Pager会自动调用PagingSource.getRefreshKey()来覆盖初始化时的initialKey
- Pager通过传入的最后一个参数pagingSourceFactory重新创建了一个PagingSource
- 最后更新ViewModel中你持有的PagingSource引用
- 如果需要支持跳页,修改以下配置
- 创建Pager时,PagingConfig.jumpThreshold 给一个值,一般来说pageSize * 2 即可
- PagingSource 重写 jumpingSupported,返回true
- PagingSource 重写 getRefreshKey,返回目标跳转页数(用于创建下一个新的PagingSource)
- PagingSource 重写 load 时 LoadResult.Page 需要返回 itemsBefore itemsAfter