rubensousa / BottomSheetBuilder

A simple library that creates BottomSheets according to the Material Design specs
Apache License 2.0
558 stars 98 forks source link

BottomSheetDialog usage in Fragment #16

Open suleymanccelik opened 7 years ago

suleymanccelik commented 7 years ago

Hi, Thanks for your library.

I am trying to show BottomSheet in a fragment but a problem occurs on onBottomSheetItemClick listener. Problem steps are;

1- User clicks edit button and BottomSheet opens 2- User clicks an item and BottomSheet dismisses 3- User clicks edit button again and BottomSheet opens 4- User clicks an item but BottomSheet doesn't close and onBottomSheetItemClick is not called.

I changed your sample code using a fragment and same problem occurs. BottomSheet dialog dismisses when user clicks outside of the dialog. In my fragment, there is no coordinatorlayout.


mShowingSimpleDialog = true;
        mBottomSheetDialog = new BottomSheetBuilder(getActivity())
                .setMode(BottomSheetBuilder.MODE_LIST)
                .addTitleItem("Custom title")
                .addItem(0, "Preview", R.drawable.ic_close_24dp)
                .addItem(1, "Share", R.drawable.ic_close_24dp)
                .addDividerItem()
                .addItem(2, "Get link", R.drawable.ic_close_24dp)
                .addItem(3, "Make a copy", R.drawable.ic_close_24dp)
                .expandOnStart(true)
                .setItemClickListener(new BottomSheetItemClickListener() {
                    @Override
                    public void onBottomSheetItemClick(MenuItem item) {
                        Log.d("Item click", item.getTitle() + "");
                        mShowingSimpleDialog = false;
                    }
                })
                .createDialog();
        mBottomSheetDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
            @Override
            public void onCancel(DialogInterface dialog) {
                mShowingSimpleDialog = false;
            }
        });
rubensousa commented 7 years ago

Did you find a solution for this?

Fuhrmann commented 6 years ago

Same problem. I guess this is the culprit:

@Override
public void onBottomSheetItemClick(MenuItem item) {
    if (!mClicked) {

        if (mBehavior != null) {
            mBehavior.setState(BottomSheetBehavior.STATE_HIDDEN);
        }

        if (mClickListener != null) {
            mClickListener.onBottomSheetItemClick(item);
        }

        mClicked = true;
    }
}

The mClicked once true, stays true. It never changes to false.

Angelk90 commented 6 years ago

@rubensousa , @suleymanccelik :

I'm having a similar problem.

When an item is clicked, nothing happens.

It looks like setItemClickListener, it's not working.


        mBottomSheetDialog = new BottomSheetBuilder(this)
                .setMode(BottomSheetBuilder.MODE_LIST)
                .setItemTextColor(Color.parseColor("#000000"))
                .setBackgroundColor(Color.parseColor("#ffffff"))
                .addItem(0, "Add sub", R.drawable.ic_facebook_box)
                .addItem(1, "Change time", R.drawable.ic_facebook_box)
                .addItem(2, "Show/Hide title", R.drawable.ic_facebook_box)
                .expandOnStart(true)
                .setItemClickListener(new BottomSheetItemClickListener() {
                    @Override
                    public void onBottomSheetItemClick(MenuItem item) {
                        Log.v("ok", " click2-" + item.getTitle());
                    }
                }).createDialog();

        mBottomSheetDialog.show();