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

关于callback中onChildDraw方法参数的建议 #18

Open
kidloserme opened this issue Jun 5, 2017 · 0 comments
Open

关于callback中onChildDraw方法参数的建议 #18

kidloserme opened this issue Jun 5, 2017 · 0 comments

Comments

@kidloserme
Copy link

kidloserme commented Jun 5, 2017

建议把Callback类中的onChildDraw方法的第三个参数由ViewHolder类型改为Extension类型,并为Extension新增两个接口,getItemView和getTranslateView。这样就可以为使用者提供一个默认的callback,省去使用者再自己定义callback并在onChildDraw进行类型判断的步骤。下面是我使用的示例:

public interface Extension {
    float getActionWidth();
    View getTranslateView();
    View getItemView();
}

自定义的callback中onChildDraw

@Override
public void onChildDraw(Canvas c, RecyclerView recyclerView, Extension extension, float dX, float dY, int actionState, boolean isCurrentlyActive) {
    extension.getTranslateView().setTranslationX(dX);
}

ItemTouchHelperExtension中调用onChildDraw的修改

private void onDraw(Canvas c, RecyclerView parent, ViewHolder selected,
                    List<RecoverAnimation> recoverAnimationList,
                    int actionState, float dX, float dY) {
    final int recoverAnimSize = recoverAnimationList.size();
    for (int i = 0; i < recoverAnimSize; i++) {
        final RecoverAnimation anim = recoverAnimationList.get(i);
        anim.update();
        final int count = c.save();
        onChildDraw(c, parent, (Extension) anim.mViewHolder, anim.mX, anim.mY, anim.mActionState,
                false);
        c.restoreToCount(count);
    }
    if (selected != null) {
        final int count = c.save();
        onChildDraw(c, parent, (Extension) selected, dX, dY, actionState, true);
        c.restoreToCount(count);
    }
}
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