Skip to content

Customization of Composite Items

Vitaly Vivchar edited this page Oct 19, 2017 · 17 revisions

How to change a LayoutManager

override the createLayoutManager() method:

public class RecyclerViewRenderer extends CompositeViewRenderer<RecyclerViewModel, RecyclerViewHolder> {

        ...

	@Override
	protected RecyclerView.LayoutManager createLayoutManager() {
		return new AnyLayoutManager();
	}
}

How to set extended RecyclerViewAdapter

override the createAdapter() method:

public class RecyclerViewRenderer extends CompositeViewRenderer<RecyclerViewModel, RecyclerViewHolder> {

        ...

	@Override
	protected RendererRecyclerViewAdapter createAdapter() {
		return new AnyExtendedAdapter();
	}
}

How to add any ItemDecoration

override the createItemDecorations() method:

public class RecyclerViewRenderer extends CompositeViewRenderer<RecyclerViewModel, RecyclerViewHolder> {

        ...

	@Override
	protected List<? extends RecyclerView.ItemDecoration> createItemDecorations() {
		return Collections.singletonList(new AnyItemDecoration());
	}
}

How to change default bindView method

override the bindView method

public class RecyclerViewRenderer extends CompositeViewRenderer<RecyclerViewModel, RecyclerViewHolder> {

        ...

	@Override
	public void bindView(RecyclerViewModel model, RecyclerViewHolder holder) {
		...

                holder.adapter.setItems(model.getItems(), new AnyDiffCallback());
	}
}