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

actionListener not called with snackbar attached to ViewGroup. #88

Open
pawelantczak opened this issue Feb 24, 2015 · 5 comments
Open

Comments

@pawelantczak
Copy link
Contributor

Hello.
Like in titie.
Regards.

@h6ah4i
Copy link
Contributor

h6ah4i commented Feb 25, 2015

Hi. Could you provide more detail of this issue?

I am trying to reproduce this issue with the "Show in Dialog" sample which attaches snackbar to RelativeLayout, but actionListener called properly though.

@pawelantczak
Copy link
Contributor Author

Hello.
My approach was this:

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        mRootView = inflater.inflate(R.layout.fragment_main, container, false);
        ButterKnife.inject(this, mRootView);

        SnackbarManager.show(Snackbar.with(mActivity)
                .text("Text")
                .actionLabel("Label")
                .actionListener(this)
                .duration(Snackbar.SnackbarDuration.LENGTH_SHORT)
                .eventListener(this), container);
    }

@h6ah4i
Copy link
Contributor

h6ah4i commented Feb 25, 2015

Can't reproduce. However, I'm using a bit different code which uses onViewCreated() method because snackbar won't appear when the SnackbarManager.show() method invoked in onCreateView().

public class TestFragmentActivity extends ActionBarActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_empty);

        getSupportFragmentManager().beginTransaction()
                .add(R.id.container, new PlaceHolderFragment())
                .commit();
    }

    public static class PlaceHolderFragment extends Fragment implements ActionClickListener, EventListener {
        private View mRootView;

        @Override
        public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
            mRootView = inflater.inflate(R.layout.fragment_dialog_list, container, false);

            ButterKnife.inject(this, mRootView);

            return mRootView;
        }

        @Override
        public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
            super.onViewCreated(view, savedInstanceState);

            SnackbarManager.show(Snackbar.with(getActivity())
                    .text("Text")
                    .actionLabel("Label")
                    .actionListener(this)
                    .duration(Snackbar.SnackbarDuration.LENGTH_SHORT)
                    .eventListener(this), (ViewGroup) mRootView.getParent());
        }

        @Override
        public void onActionClicked(Snackbar snackbar) {
        }

        @Override
        public void onShow(Snackbar snackbar) {
        }

        @Override
        public void onShowByReplace(Snackbar snackbar) {
        }

        @Override
        public void onShown(Snackbar snackbar) {
        }

        @Override
        public void onDismiss(Snackbar snackbar) {
        }

        @Override
        public void onDismissByReplace(Snackbar snackbar) {
        }

        @Override
        public void onDismissed(Snackbar snackbar) {
        }
    }
}

@AndreRoss
Copy link

I was able to reproduce this issue with a viewgroup after dismiss and show again the snackbar. Do you have an idea why this occurs?

@h6ah4i
Copy link
Contributor

h6ah4i commented Mar 4, 2015

@AndreRoss Okay, reproduced. But I think that is not the same issue of which @pawelantczak has reported.

Are you reusing the same instance of Snackbar class, right? I think current implementation does not consider to reuse the same instance in spite of attaching to Activity or ViewGroup. You should create a new Snackbar instance each time for now.

ref.) Reusing same snackbar instance #23

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

3 participants