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

API of VisibilityProvider is confusing when used in Kotlin #43

Open
joshfriend opened this issue Sep 12, 2016 · 0 comments
Open

API of VisibilityProvider is confusing when used in Kotlin #43

joshfriend opened this issue Sep 12, 2016 · 0 comments

Comments

@joshfriend
Copy link

When using Java, the API is pretty much self explanatory:

ItemDecoration dividerDecoration = HorizontalDividerItemDecoration.Builder(this)
    .sizeResId(R.dimen.item_divider_height)
    .visibilityProvider(new VisibilityProvider() {
        @Override
        boolean shouldHideDivider(int position, RecyclerView parent) {
            // With the context of having the method name shown above, this is
            // obviously wrong.
            return true;
        }
    }
    .build();

However, because VisibilityProvider is a SAM-type, Kotlin allows you to use a trailing closure, so the name of the method isn't shown anywhere. In this case, a user's first instinct might be to return true to show the divider and false to hide it (like I did), which is backwards:

val dividerDecoration = HorizontalDividerItemDecoration.Builder(this)
    .sizeResId(R.dimen.item_divider_height)
    .visibilityProvider { position, parent ->
        // This looked right to me (visibility -> true), but is backwards.
        true
    }
    .build()

I'd suggest inverting that API so it's more Kotlin-friendly:

interface VisibilityProvider {
    boolean shouldShowDivider(int position, RecyclerView parent);
}

This issue may apply to other APIs, but I haven't run into any others yet, or had time to look.

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

1 participant