Skip to content
This repository has been archived by the owner on Apr 30, 2024. It is now read-only.

Update to Butterknife 8.0 #72

Closed
wants to merge 2 commits into from
Closed

Update to Butterknife 8.0 #72

wants to merge 2 commits into from

Conversation

Jawnnypoo
Copy link

As you can see, apart from the rename of Bind to BindView, you now need to keep a reference to an Unbinder. This means that there is no longer a need to pass the Object back in the framework ViewBinder, but I figured you could leave it in for compatibility and it doesn't hurt anything

@Override
public void bind(Object object, View view) {
ButterKnife.bind(object, view);
unbinder = ButterKnife.bind(object, view);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There might be more bookkeeping involved here. You probably need to keep an unbinder instance per object

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

public class ButterKnifeViewBinder implements ViewBinder {
    private WeakHashMap<Object, Unbinder> unbinders = new WeakHashMap<>();

    @Override
    public void bind(Object object, View view) {
        unbinders.put(object, ButterKnife.bind(object, view));
    }

    @Override
    public void unbind(Object object) {
        Unbinder unbinder = unbinders.get(object);
        if (unbinder != null)
            unbinder.unbind();
    }
}

@Jawnnypoo
Copy link
Author

Good call, @benoitdion thanks for calling that out.

@Jawnnypoo Jawnnypoo closed this Nov 22, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants