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

OnClick method is not work when used the R2.id.xxx. #1612

Open
tqlmorepassion opened this issue May 20, 2020 · 4 comments
Open

OnClick method is not work when used the R2.id.xxx. #1612

tqlmorepassion opened this issue May 20, 2020 · 4 comments

Comments

@tqlmorepassion
Copy link

butterKnifePlugin--10.1.0
Gradle 3.4.2

We found that we did not know what circumstances would cause this problem, but we did encounter it several times. Once encountered, only killing the process will return to normal.

just like:

@OnClick(R2.id.tv_close) public void onViewClicked() { onBackPressed(); }

@JakeWharton
Copy link
Owner

Can you provide a sample that reproduces the issue? What does the generated code look like?

@tqlmorepassion
Copy link
Author

tqlmorepassion commented May 20, 2020

We did not know how to reproduces the issue, but we received feedback from our customers several times. And our QA faced it today, I had debugged it, it seems like the @OnClick(R2.id.tv_close) did not work as well.
It works well most time, but we did not know how to reproduces it. So I had to update the version to 10.2.1.

The generated code is

`public class NavigationBar_ViewBinding implements Unbinder {
private NavigationBar target;

private View view7f0b0080;

private View view7f0b0085;

private View view7f0b0054;

@UiThread
public NavigationBar_ViewBinding(NavigationBar target) {
this(target, target);
}

@UiThread
public NavigationBar_ViewBinding(final NavigationBar target, View source) {
this.target = target;

View view;
target.mTvNavigationTitle = Utils.findRequiredViewAsType(source, R.id.m_tv_navigation_title, "field 'mTvNavigationTitle'", TextView.class);
view = Utils.findRequiredView(source, R.id.m_iv_navigation_back, "field 'mIvNavigationLeft' and method 'onViewClicked'");
target.mIvNavigationLeft = Utils.castView(view, R.id.m_iv_navigation_back, "field 'mIvNavigationLeft'", ImageView.class);
view7f0b0080 = view;
view.setOnClickListener(new DebouncingOnClickListener() {
  @Override
  public void doClick(View p0) {
    target.onViewClicked(p0);
  }
});
target.tvLeft = Utils.findRequiredViewAsType(source, R.id.mLeftText, "field 'tvLeft'", TextView.class);
target.viewStup = Utils.findRequiredViewAsType(source, R.id.view_stup, "field 'viewStup'", ViewStub.class);
view = Utils.findRequiredView(source, R.id.m_tv_navigation_right_text, "field 'mTvNavigationRightText' and method 'onViewClicked'");
target.mTvNavigationRightText = Utils.castView(view, R.id.m_tv_navigation_right_text, "field 'mTvNavigationRightText'", TextView.class);
view7f0b0085 = view;
view.setOnClickListener(new DebouncingOnClickListener() {
  @Override
  public void doClick(View p0) {
    target.onViewClicked(p0);
  }
});
target.mIvOne = Utils.findRequiredViewAsType(source, R.id.iv_right_one, "field 'mIvOne'", ImageView.class);
target.mivTwo = Utils.findRequiredViewAsType(source, R.id.iv_right_two, "field 'mivTwo'", ImageView.class);
target.mIvThree = Utils.findRequiredViewAsType(source, R.id.iv_right_three, "field 'mIvThree'", ImageView.class);
target.mIvNavigationLeftBg = Utils.findRequiredViewAsType(source, R.id.m_iv_navigation_bg, "field 'mIvNavigationLeftBg'", ImageView.class);
view = Utils.findRequiredView(source, R.id.fl_back, "method 'onViewClicked'");
view7f0b0054 = view;
view.setOnClickListener(new DebouncingOnClickListener() {
  @Override
  public void doClick(View p0) {
    target.onViewClicked(p0);
  }
});

}

@OverRide
@callsuper
public void unbind() {
NavigationBar target = this.target;
if (target == null) throw new IllegalStateException("Bindings already cleared.");
this.target = null;

target.mTvNavigationTitle = null;
target.mIvNavigationLeft = null;
target.tvLeft = null;
target.viewStup = null;
target.mTvNavigationRightText = null;
target.mIvOne = null;
target.mivTwo = null;
target.mIvThree = null;
target.mIvNavigationLeftBg = null;

view7f0b0080.setOnClickListener(null);
view7f0b0080 = null;
view7f0b0085.setOnClickListener(null);
view7f0b0085 = null;
view7f0b0054.setOnClickListener(null);
view7f0b0054 = null;

}
}`

@tqlmorepassion
Copy link
Author

Maybe the same problem with #1511 ,
the DebouncingOnClickListener did not work.

@ZacSweers
Copy link
Contributor

ZacSweers commented Sep 22, 2020

We saw this too, kapt stubs in some cases inlined the constant value rather than the qualified reference, seemingly only on the OnClick-annotated methods. Was a good forcing function to move to listeners in preparation for viewbinding

    @butterknife.BindView(value = com.Slack.R2.id.toolbar)
    public androidx.appcompat.widget.Toolbar toolbarNewName3;

    @butterknife.OnClick(value = {5496})
    public final void onSendMagicLinkClicked() {
    }

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

No branches or pull requests

4 participants
@JakeWharton @ZacSweers @tqlmorepassion and others