Skip to content

Commit

Permalink
Add a replaceAll(List<RenderInfo>) method to RecyclerBinder.
Browse files Browse the repository at this point in the history
For compatibility reasons, there's currently no way to hook up
RecyclerView.notifyDatasetChanged() calls to RecyclerBinder without
potentially triggering transition animations. This opens up an API to
support the equivalent of replacing all the items in a RecyclerBinder
and calling notifyDatasetChanged().
  • Loading branch information
vinc3m1 committed Mar 13, 2019
1 parent a92c073 commit 2c9de71
Showing 1 changed file with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1122,6 +1122,25 @@ private void addToCurrentBatch(AsyncOperation operation) {
mCurrentBatch.mOperations.add(operation);
}

/**
* Replaces all items in the {@link RecyclerBinder} with the provided {@link RenderInfo}s.
*/
@UiThread
public final void replaceAll(List<RenderInfo> renderInfos) {
synchronized (this) {
if (mHasAsyncOperations) {
throw new RuntimeException(
"Trying to do a sync replaceAll when using asynchronous mutations!");
}
mComponentTreeHolders.clear();
for (RenderInfo renderInfo : renderInfos) {
mComponentTreeHolders.add(createComponentTreeHolder(renderInfo));
}
}
mInternalAdapter.notifyDataSetChanged();
mViewportManager.setShouldUpdate(true);
}

/**
* See {@link RecyclerBinder#appendItem(RenderInfo)}.
*/
Expand Down

0 comments on commit 2c9de71

Please sign in to comment.