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 Oct 24, 2018
1 parent 4bc22ef commit a76a57c
Showing 1 changed file with 33 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1070,6 +1070,39 @@ 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!");
}
final int oldSize = mComponentTreeHolders.size();
final int newSize = renderInfos.size();

if (oldSize > newSize) {
for (int i = oldSize - 1; i >= newSize; i--) {
mComponentTreeHolders.remove(i).release();
}
}

for (int i = 0; i < newSize; i++) {
RenderInfo newRenderInfo = renderInfos.get(i);
if (i >= mComponentTreeHolders.size()) {
mComponentTreeHolders.add(i, createComponentTreeHolder(newRenderInfo));
} else {
mComponentTreeHolders.get(i).setRenderInfo(newRenderInfo);
}
mRenderInfoViewCreatorController.maybeTrackViewCreator(newRenderInfo);
}
}
mInternalAdapter.notifyDataSetChanged();
mViewportManager.setShouldUpdate(true);
}

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

0 comments on commit a76a57c

Please sign in to comment.