public class RecyclerBinder extends java.lang.Object implements Binder<RecyclerView>, LayoutInfo.RenderInfoCollection, HasStickyHeader
Component
and attaching them to a RecyclerSpec
.Modifier and Type | Class and Description |
---|---|
static class |
RecyclerBinder.Builder |
static interface |
RecyclerBinder.CommitPolicy
Defines when a batch should be committed: - IMMEDIATE: Commit batches to the RecyclerView as
soon as possible.
|
static class |
RecyclerBinder.RecyclerViewLayoutManagerOverrideParams |
ViewportInfo.State, ViewportInfo.ViewportChanged
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
ID_CUSTOM_ATTR_KEY |
Modifier and Type | Method and Description |
---|---|
void |
appendItem(Component component)
|
void |
appendItem(RenderInfo renderInfo)
Inserts a new item at tail.
|
void |
bind(RecyclerView view)
Bind this
Binder to a View . |
boolean |
canMeasure()
Only for horizontally scrolling layouts: return true if height is not known when measuring the
view and the first item will be measured to determine the height.
|
void |
clearAsync()
Removes all items in this binder async.
|
void |
detach()
Detach items under the hood.
|
int |
findFirstFullyVisibleItemPosition() |
int |
findFirstVisibleItemPosition() |
int |
findLastFullyVisibleItemPosition() |
int |
findLastVisibleItemPosition() |
ComponentTree |
getComponentAt(int position)
Returns the
ComponentTree for the item at index position. |
ComponentTree |
getComponentForStickyHeaderAt(int position) |
ComponentTreeHolder |
getComponentTreeHolderAt(int position) |
RecyclerView.Adapter |
getInternalAdapter() |
int |
getItemCount()
Gets the number of items currently in the adapter attached to this binder (i.e.
|
RenderInfo |
getRenderInfoAt(int position) |
void |
insertItemAt(int position,
Component component)
|
void |
insertItemAt(int position,
RenderInfo renderInfo)
Inserts a new item at position.
|
void |
insertItemAtAsync(int position,
RenderInfo renderInfo)
Inserts an item at position.
|
void |
insertRangeAt(int position,
java.util.List<RenderInfo> renderInfos)
Inserts the new items starting from position.
|
void |
insertRangeAtAsync(int position,
java.util.List<RenderInfo> renderInfos)
Inserts the new items starting from position.
|
boolean |
isSticky(int position) |
boolean |
isValidPosition(int position) |
boolean |
isWrapContent()
Return true if wrap content is enabled, false otherwise.
|
void |
measure(Size outSize,
int widthSpec,
int heightSpec,
EventHandler<ReMeasureEvent> reMeasureEventHandler)
A component mounting a RecyclerView can use this method to determine its size.
|
void |
mount(RecyclerView view)
Call from the owning
Component 's onMount. |
void |
moveItem(int fromPosition,
int toPosition)
Moves an item from fromPosition to toPosition.
|
void |
moveItemAsync(int fromPosition,
int toPosition)
Moves an item from fromPosition to toPostion.
|
void |
notifyChangeSetComplete(boolean isDataChanged,
ChangeSetCompleteCallback changeSetCompleteCallback)
Called after all the change set operations (inserts, removes, etc.) in a batch have completed.
|
void |
notifyChangeSetCompleteAsync(boolean isDataChanged,
ChangeSetCompleteCallback changeSetCompleteCallback)
Called after all the change set operations (inserts, removes, etc.) in a batch have completed.
|
void |
notifyItemRenderCompleteAt(int position,
long timestampMillis) |
void |
removeItemAt(int position)
Removes an item from index position.
|
void |
removeItemAtAsync(int position)
Removes an item from position.
|
void |
removeRangeAt(int position,
int count)
Removes count items starting from position.
|
void |
removeRangeAtAsync(int position,
int count)
Removes count items starting from position.
|
void |
removeSubAdapterModeRecyclerView(RecyclerView recyclerView) |
void |
replaceAll(java.util.List<RenderInfo> renderInfos)
Replaces all items in the
RecyclerBinder with the provided RenderInfo s. |
void |
resetLayoutInfo(LayoutInfo layoutInfo)
Reset the LayoutInfo for this RecyclerBinder, should only be used in the scenario where you
cannot provide the LayoutInfo when RecyclerBinder is created.
|
void |
scrollSmoothToPosition(int position,
int offset,
SmoothScrollAlignmentType type) |
void |
scrollSmoothToPosition(java.lang.Object id,
int offset,
SmoothScrollAlignmentType type) |
void |
scrollToPosition(int position) |
void |
scrollToPositionWithOffset(int position,
int offset) |
void |
scrollToPositionWithOffset(java.lang.Object id,
int offset) |
void |
setCanMeasure(boolean canMeasure)
Only for horizontally scrolling layouts: set to true if height is not known when measuring the
view and the first item will need to be measured to determine the height of the view.
|
void |
setCommitPolicy(int commitPolicy) |
void |
setSize(int width,
int height)
This should be called when the owner
Component 's onBoundsDefined is called. |
void |
setSubAdapterModeRecyclerView(RecyclerView recyclerView) |
void |
setViewportChangedListener(ViewportInfo.ViewportChanged viewportChangedListener)
Bind a
ViewportInfo.ViewportChanged listener to this Binder . |
void |
unbind(RecyclerView view)
Call this method when the view is unbound.
|
void |
unmount(RecyclerView view)
Call from the owning
Component 's onUnmount. |
void |
updateItemAt(int position,
Component component)
|
void |
updateItemAt(int position,
RenderInfo renderInfo)
Updates the item at position.
|
void |
updateItemAtAsync(int position,
RenderInfo renderInfo)
Update the item at index position.
|
void |
updateRangeAt(int position,
java.util.List<RenderInfo> renderInfos)
Updates the range of items starting at position.
|
void |
updateRangeAtAsync(int position,
java.util.List<RenderInfo> renderInfos)
Update the items starting from the given index position.
|
void |
updateSubAdapterVisibleRange(int firstVisiblePosition,
int lastVisiblePosition)
Updates the visible range when in sub adapter mode.
|
void |
updateSubAdapterWorkingRange(int firstVisibleIndex,
int lastVisibleIndex,
int firstFullyVisibleIndex,
int lastFullyVisibleIndex)
Updates the working range when in sub adapter mode.
|
public static final java.lang.String ID_CUSTOM_ATTR_KEY
public boolean isWrapContent()
Binder
isWrapContent
in interface Binder<RecyclerView>
public boolean canMeasure()
Binder
canMeasure
in interface Binder<RecyclerView>
public void setCanMeasure(boolean canMeasure)
Binder
setCanMeasure
in interface Binder<RecyclerView>
public void detach()
Binder
public void notifyItemRenderCompleteAt(int position, long timestampMillis)
public final void updateItemAtAsync(int position, RenderInfo renderInfo)
RecyclerView
will only be notified of the item
being updated after a layout calculation has been completed for the new Component
.public final void updateRangeAtAsync(int position, java.util.List<RenderInfo> renderInfos)
RecyclerView
will only be
notified of the item being updated after a layout calculation has been completed for the new
Component
.public final void insertItemAtAsync(int position, RenderInfo renderInfo)
RecyclerView
will only be notified of the item being
inserted after a layout calculation has been completed for the new Component
.public final void insertRangeAtAsync(int position, java.util.List<RenderInfo> renderInfos)
RecyclerView
will only be notified of
the items being inserted after a layout calculation has been completed for the new Component
s. There is not a guarantee that the RecyclerView
will be notified about all
the items in the range at the same time.public void setSubAdapterModeRecyclerView(RecyclerView recyclerView)
public void removeSubAdapterModeRecyclerView(RecyclerView recyclerView)
public final void moveItemAsync(int fromPosition, int toPosition)
public final void removeItemAtAsync(int position)
public final void removeRangeAtAsync(int position, int count)
public final void clearAsync()
public final void replaceAll(java.util.List<RenderInfo> renderInfos)
RecyclerBinder
with the provided RenderInfo
s.public final void appendItem(Component component)
public final void appendItem(RenderInfo renderInfo)
RecyclerView
gets notified immediately about the new
item being inserted. If the item's position falls within the currently visible range, the
layout is immediately computed on the] UiThread. The RenderInfo contains the component that
will be inserted in the Binder and extra info like isSticky or spanCount.public final void insertItemAt(int position, Component component)
public final void insertItemAt(int position, RenderInfo renderInfo)
RecyclerView
gets notified immediately about the
new item being inserted. If the item's position falls within the currently visible range, the
layout is immediately computed on the] UiThread. The RenderInfo contains the component that
will be inserted in the Binder and extra info like isSticky or spanCount.public final void insertRangeAt(int position, java.util.List<RenderInfo> renderInfos)
RecyclerView
gets notified
immediately about the new item being inserted. The RenderInfo contains the component that will
be inserted in the Binder and extra info like isSticky or spanCount.public final void updateItemAt(int position, Component component)
public final void updateItemAt(int position, RenderInfo renderInfo)
RecyclerView
gets notified immediately about the item
being updated. If the item's position falls within the currently visible range, the layout is
immediately computed on the UiThread.public final void updateRangeAt(int position, java.util.List<RenderInfo> renderInfos)
RecyclerView
gets notified
immediately about the item being updated.public final void moveItem(int fromPosition, int toPosition)
public final void removeItemAt(int position)
public final void removeRangeAt(int position, int count)
public void notifyChangeSetCompleteAsync(boolean isDataChanged, ChangeSetCompleteCallback changeSetCompleteCallback)
public void notifyChangeSetComplete(boolean isDataChanged, ChangeSetCompleteCallback changeSetCompleteCallback)
public final ComponentTree getComponentAt(int position)
ComponentTree
for the item at index position. TODO 16212132 remove
getComponentAt from bindergetComponentAt
in interface Binder<RecyclerView>
public final ComponentTree getComponentForStickyHeaderAt(int position)
getComponentForStickyHeaderAt
in interface HasStickyHeader
public final RenderInfo getRenderInfoAt(int position)
getRenderInfoAt
in interface LayoutInfo.RenderInfoCollection
public final ComponentTreeHolder getComponentTreeHolderAt(int position)
public void bind(RecyclerView view)
Binder
public void unbind(RecyclerView view)
Binder
public void measure(Size outSize, int widthSpec, int heightSpec, EventHandler<ReMeasureEvent> reMeasureEventHandler)
If padding is defined on the parent component it should be subtracted from the parent size specs before passing them to this method.
Currently we can't support the equivalent of MATCH_PARENT on the scrollDirection (so for example we don't support MATCH_PARENT on width in an horizontal RecyclerView). This is mainly because we don't have the equivalent of LayoutParams in components. We can extend the api of the binder in the future to provide some more layout hints in order to support this.
measure
in interface Binder<RecyclerView>
outSize
- will be populated with the measured dimensions for this Binder.widthSpec
- the widthSpec to be used to measure the RecyclerView.heightSpec
- the heightSpec to be used to measure the RecyclerView.reMeasureEventHandler
- the EventHandler to invoke in order to trigger a re-measure.public int getItemCount()
getItemCount
in interface ViewportInfo
public void setSize(int width, int height)
Component
's onBoundsDefined is called. It will
inform the binder of the final measured size. The binder might decide to re-compute its
children layouts if the measures provided here are not compatible with the ones receive in
onMeasure.public void mount(RecyclerView view)
Component
's onMount. This is where the adapter is assigned to the
RecyclerView
.public void unmount(RecyclerView view)
Component
's onUnmount. This is where the adapter is removed from
the RecyclerView
.public void scrollToPosition(int position)
public void scrollSmoothToPosition(java.lang.Object id, int offset, SmoothScrollAlignmentType type)
public void scrollSmoothToPosition(int position, int offset, SmoothScrollAlignmentType type)
public void scrollToPositionWithOffset(java.lang.Object id, int offset)
public void scrollToPositionWithOffset(int position, int offset)
public int findFirstVisibleItemPosition()
findFirstVisibleItemPosition
in interface ViewportInfo
public int findFirstFullyVisibleItemPosition()
findFirstFullyVisibleItemPosition
in interface ViewportInfo
public int findLastVisibleItemPosition()
findLastVisibleItemPosition
in interface ViewportInfo
public int findLastFullyVisibleItemPosition()
findLastFullyVisibleItemPosition
in interface ViewportInfo
public boolean isSticky(int position)
isSticky
in interface HasStickyHeader
public boolean isValidPosition(int position)
isValidPosition
in interface HasStickyHeader
public RecyclerView.Adapter getInternalAdapter()
public void setViewportChangedListener(ViewportInfo.ViewportChanged viewportChangedListener)
Binder
ViewportInfo.ViewportChanged
listener to this Binder
. The listener will
be notified of Viewport changes.setViewportChangedListener
in interface Binder<RecyclerView>
public void updateSubAdapterVisibleRange(int firstVisiblePosition, int lastVisiblePosition)
public void updateSubAdapterWorkingRange(int firstVisibleIndex, int lastVisibleIndex, int firstFullyVisibleIndex, int lastFullyVisibleIndex)
public void setCommitPolicy(int commitPolicy)
public void resetLayoutInfo(LayoutInfo layoutInfo)
layoutInfo
- an implementation of LayoutInfo
that will expose information about
the LayoutManager
this RecyclerBinder will use.