RecyclerBinder

This binder class is used to asynchronously layout Components given a list of Component and attaching them to a Recycler.

Types

Link copied to clipboard
class Builder
Link copied to clipboard
annotation class CommitPolicy

Defines when a batch should be committed: - IMMEDIATE: Commit batches to the RecyclerView as soon as possible. - LAYOUT_BEFORE_INSERT: Commit batches to the RecyclerView only after the layouts for all insert operations have been completed.

Link copied to clipboard
object Companion
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
annotation class PaginationStrategy
Link copied to clipboard
Link copied to clipboard
annotation class RecyclingStrategy

Strategies for recycling layouts of items in binder

Properties

Link copied to clipboard

To avoid creating a new runnable for each ComponentTreeHolder, we maintain a task queue to consume them in order.

Link copied to clipboard
open override val isCrossAxisWrapContent: Boolean

Return true if wrap content is enabled for the cross axis, false otherwise.

Link copied to clipboard
open override val isMainAxisWrapContent: Boolean

Return true if wrap content is enabled for the main axis, false otherwise.

Link copied to clipboard
Link copied to clipboard

Functions

Link copied to clipboard
fun appendItem(component: Component?)

See RecyclerBinder#appendItem(RenderInfo).

fun appendItem(renderInfo: RenderInfo)

Inserts a new item at tail. The 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.

Link copied to clipboard

Removes all items in this binder async.

Link copied to clipboard
fun computeLayoutsToFillListViewport(holders: List<ComponentTreeHolder?>, offset: Int, maxWidth: Int, maxHeight: Int, outputSize: Size?): Int
Link copied to clipboard
open override fun detach()

Detach items under the hood.

Link copied to clipboard
Link copied to clipboard
open override fun findFirstVisibleItemPosition(): Int
Link copied to clipboard
Link copied to clipboard
open override fun findLastVisibleItemPosition(): Int
Link copied to clipboard
open override fun getChildHeightSpec(index: Int): Int
Link copied to clipboard
open override fun getChildWidthSpec(index: Int): Int
Link copied to clipboard
open override fun getComponentAt(position: Int): ComponentTree?

Returns the ComponentTree for the item at index position. TODO 16212132 remove getComponentAt from binder

Link copied to clipboard
open override fun getComponentForStickyHeaderAt(position: Int): ComponentTree?
Link copied to clipboard
open override fun getItemCount(): Int

Gets the number of items currently in the adapter attached to this binder (i.e. the number of items the underlying RecyclerView knows about).

Link copied to clipboard
open override fun getRenderInfoAt(position: Int): RenderInfo
Link copied to clipboard
Link copied to clipboard
fun insertItemAt(position: Int, component: Component?)

See RecyclerBinder#insertItemAt(int, RenderInfo).

fun insertItemAt(position: Int, renderInfo: RenderInfo?)

Inserts a new item at position. The 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.

Link copied to clipboard
fun insertItemAtAsync(position: Int, renderInfo: RenderInfo)

Inserts an item at position. The RecyclerView will only be notified of the item being inserted after a layout calculation has been completed for the new Component.

Link copied to clipboard
fun insertRangeAt(position: Int, renderInfos: List<RenderInfo>)

Inserts the new items starting from position. The 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.

Link copied to clipboard
fun insertRangeAtAsync(position: Int, renderInfos: List<RenderInfo?>)

Inserts the new items starting from position. The RecyclerView will only be notified of the items being inserted after a layout calculation has been completed for the new Components. There is not a guarantee that the RecyclerView will be notified about all the items in the range at the same time.

Link copied to clipboard
open override fun isSticky(position: Int): Boolean
Link copied to clipboard
open override fun isValidPosition(position: Int): Boolean
Link copied to clipboard
open override fun measure(outSize: Size, widthSpec: Int, heightSpec: Int, reMeasureEventHandler: EventHandler<ReMeasureEvent>?)

A component mounting a RecyclerView can use this method to determine its size. A Recycler that scrolls horizontally will leave the width unconstrained and will measure its children with a sizeSpec for the height matching the heightSpec passed to this method.

Link copied to clipboard
open override fun mount(view: RecyclerView)

Call from the owning Component's onMount. This is where the adapter is assigned to the RecyclerView.

Link copied to clipboard
fun moveItem(fromPosition: Int, toPosition: Int)

Moves an item from fromPosition to toPosition. If the new position of the item is within the currently visible range, a layout is calculated immediately on the UI Thread.

Link copied to clipboard
fun moveItemAsync(fromPosition: Int, toPosition: Int)

Moves an item from fromPosition to toPosition. If there are other pending operations on this binder this will only be executed when all the operations have been completed (to ensure index consistency).

Link copied to clipboard
fun notifyChangeSetComplete(isDataChanged: Boolean, changeSetCompleteCallback: ChangeSetCompleteCallback?)

Called after all the change set operations (inserts, removes, etc.) in a batch have completed.

Link copied to clipboard
fun notifyChangeSetCompleteAsync(isDataChanged: Boolean, changeSetCompleteCallback: ChangeSetCompleteCallback)

Called after all the change set operations (inserts, removes, etc.) in a batch have completed. Async variant, may be called off the main thread.

Link copied to clipboard
fun notifyItemRenderCompleteAt(position: Int, timestampMillis: Long)
Link copied to clipboard
fun onNewVisibleRange(firstVisiblePosition: Int, lastVisiblePosition: Int)
Link copied to clipboard
fun onNewWorkingRange(firstVisibleIndex: Int, lastVisibleIndex: Int, firstFullyVisibleIndex: Int, lastFullyVisibleIndex: Int)
Link copied to clipboard
fun removeItemAt(position: Int)

Removes an item from index position.

Link copied to clipboard
fun removeItemAtAsync(position: Int)

Removes an item from position. If there are other pending operations on this binder this will only be executed when all the operations have been completed (to ensure index consistency).Return true if the item was removed, false if the item was not removed.

Link copied to clipboard
fun removeRangeAt(position: Int, count: Int)

Removes count items starting from position.

Link copied to clipboard
fun removeRangeAtAsync(position: Int, count: Int)

Removes count items starting from position. If there are other pending operations on this binder this will only be executed when all the operations have been completed (to ensure index consistency). Return true if the range was removed, false if the range was not removed.

Link copied to clipboard
fun replaceAll(renderInfos: List<RenderInfo>)

Replaces all items in the RecyclerBinder with the provided RenderInfos.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
fun setCommitPolicy(commitPolicy: Int)
Link copied to clipboard
open override fun setSize(width: Int, height: Int)

This should be called when the owner 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.

Link copied to clipboard
Link copied to clipboard
open override fun setViewportChangedListener(viewportChangedListener: ViewportInfo.ViewportChanged?)

Bind a ViewportInfo.ViewportChanged listener to this Binder. The listener will be notified of Viewport changes.

Link copied to clipboard
open override fun unmount(view: RecyclerView)

Call from the owning Component's onUnmount. This is where the adapter is removed from the RecyclerView.

Link copied to clipboard
fun updateItemAt(position: Int, component: Component?)

See RecyclerBinder#updateItemAt(int, Component).

fun updateItemAt(position: Int, renderInfo: RenderInfo?)

Updates the item at position. The 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.

Link copied to clipboard
fun updateItemAtAsync(position: Int, renderInfo: RenderInfo?)

Update the item at index position. The RecyclerView will only be notified of the item being updated after a layout calculation has been completed for the new Component.

Link copied to clipboard
fun updateRangeAt(position: Int, renderInfos: List<RenderInfo?>)

Updates the range of items starting at position. The RecyclerView gets notified immediately about the item being updated.

Link copied to clipboard

Update the items starting from the given index position. The RecyclerView will only be notified of the item being updated after a layout calculation has been completed for the new Component.

Link copied to clipboard
fun updateSubAdapterVisibleRange(firstVisiblePosition: Int, lastVisiblePosition: Int)

Updates the visible range when in sub adapter mode. Do not call this otherwise. This method exists because in sub adapter mode, the RecyclerBinder is never mounted to a RecyclerView and needs outside signals from the multiplexing adapter to determine which of its indices are visible.

Link copied to clipboard
fun updateSubAdapterWorkingRange(firstVisibleIndex: Int, lastVisibleIndex: Int, firstFullyVisibleIndex: Int, lastFullyVisibleIndex: Int)

Updates the working range when in sub adapter mode. Do not call this otherwise. This method exists because in sub adapter mode, the RecyclerBinder is never mounted to a RecyclerView and needs outside signals from the multiplexing adapter to determine which of its indices are visible.