nispok / snackbar

[DEPRECATED] Android Library that implements Snackbars from Google's Material Design documentation.
MIT License
1.53k stars 237 forks source link

actionListener not called with snackbar attached to ViewGroup. #88

Open pawelantczak opened 9 years ago

pawelantczak commented 9 years ago

Hello. Like in titie. Regards.

h6ah4i commented 9 years ago

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 commented 9 years ago

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 commented 9 years ago

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 commented 9 years ago

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 commented 9 years ago

@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