Giter Club home page Giter Club logo

anvil-recyclerview's Introduction

anvil-recyclerview

Simple RecyclerView bindings for Anvil.

The library provides a Recycler "namespace" which contains utility functions for creating RecyclerViews, modifying their properties and binding adapters.

Gradle

repositories {
	maven { url = 'https://jitpack.io/' }
}
dependencies {
	compile 'co.trikita:anvil-sdk15:+' // or sdk19
	compile 'com.github.trikita:anvil-recyclerview:1.1'
}

Usage

Recycler.view(...) creates a new View and configures it using Anvil DSL.

Recycler.Adapter is an implementation of RecyclerView.Adapter which behaves in a reactive manner, e.g. on Anvil.render() it updates on the the view holders that have been changed.

Recycler.Adapter.simple(list, renderable) is a syntax sugar for binding simple adapter using a plain List as data model.

List<Item> mItems = ...;

public void view() {

	Recycler.view(() -> {

		Recycler.layoutManager(new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false));
		Recycler.hasFixedSize(true);

		Recycler.adapter(Recycler.Adapter.simple(mItems, (viewHolder) -> {
			textView(() -> {
				text(mItems.get(viewHolder.getAdapterPosition()).getName());
			});
		}));
	});
}

Further improvements

It might be useful to add some support for the most common gestures like drag to reorder items or swipe to dismiss.

It might be also helpful to add multiselect support.

Feel free to submit your pull requests!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.