Skip to content

Injecting items into PagedListEpoxyController makes RecyclerView jump upon update #641

@kakai248

Description

@kakai248

We have a list of items that come from the database. Based on their date we generate header models that we insert in the list using addModels.

We scroll for a bit, up to a point where the last item of the first page is at half of the screen (this means the second page will be loaded). Now we update some item in the database to trigger a new PagedList. Upon submitting this new PagedList to epoxy, AsyncPagedListDiffer will diff the items and update the list. This new list will not start at position 0 (that's how paging library works). This means that the initial items will be removed from the RecyclerView. Without adding extra models, the RecyclerView will be able to keep it's position. You will see exactly the same items on screen. As soon as we add extra items, the RecyclerView isn't able to keep the same position on screen and we see a jump when it removes the initial items.

Now I have two untested theories for this:

  1. It's because only the item list gets diffed so the RecyclerView doesn't account for the extra items height (is this right?). In that case we have to diff the model list instead of the item list.

  2. It's because of:

override fun onModelBound(
    holder: EpoxyViewHolder,
    boundModel: EpoxyModel<*>,
    position: Int,
    previouslyBoundModel: EpoxyModel<*>?
  ) {
    // TODO the position may not be a good value if there are too many injected items.
    modelCache.loadAround(position)
  }

Somehow, the controller would have to take the additional injected items into account.

I'm more inclined towards theory 1. But I don't know if the premise for that option is valid.

I'll try to build a small project to replicate the issue. Maybe @yigit can shed some light on this?

Thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions