From 2c9de716fd91c7a3f39cf8784119bf8c4f50b4ac Mon Sep 17 00:00:00 2001 From: Vince Mi Date: Tue, 23 Oct 2018 18:24:10 -0700 Subject: [PATCH] Add a replaceAll(List) method to RecyclerBinder. 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(). --- .../facebook/litho/widget/RecyclerBinder.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/litho-widget/src/main/java/com/facebook/litho/widget/RecyclerBinder.java b/litho-widget/src/main/java/com/facebook/litho/widget/RecyclerBinder.java index ef85945cadf..1c019129816 100644 --- a/litho-widget/src/main/java/com/facebook/litho/widget/RecyclerBinder.java +++ b/litho-widget/src/main/java/com/facebook/litho/widget/RecyclerBinder.java @@ -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 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)}. */