Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow for different/custom LayoutManagers #7

Closed
gtcompscientist opened this issue Jul 12, 2018 · 4 comments
Closed

Allow for different/custom LayoutManagers #7

gtcompscientist opened this issue Jul 12, 2018 · 4 comments

Comments

@gtcompscientist
Copy link

As a user, it would be helpful to be able to pass in a custom *LayoutManager to the bind function.

@radoyankov
Copy link
Collaborator

There is a layoutManager() function which does this.

@gtcompscientist
Copy link
Author

Doesn't it make far more sense to include this as an override in the setup?

@radoyankov
Copy link
Collaborator

Default startup takes a linear layout, which is the most commonly used one. If I make it a parameter in the bind function it would have to be optional, and I want to avoid adding optional parameters to the function to keep it simple.

@gtcompscientist
Copy link
Author

gtcompscientist commented Jul 12, 2018

fun <T> RecyclerView.bind(items: List<T>,
                          @LayoutRes singleLayout: Int = 0,
                          manager: RecyclerView.LayoutManager = LinearLayoutManager(context),
                          singleBind: (View.(item: T) -> Unit))
        : FastListAdapter<T> {
    layoutManager = manager
    return FastListAdapter(
            items,
            this
    ).map(singleLayout, { true }, singleBind)
}

Use:
recyclerView.bind(items, *LayoutManager()) { ... }

This seems a lot more intuitive to use than adding a trailing .layoutManager() call.

*Also allows you to only have a single "bind" function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants