rubensousa / BottomSheetExample

A sample project with the new BottomSheet classes from the android support library
129 stars 27 forks source link

Full screen BottomSheetDialogFragment #3

Closed hrsalehi closed 8 years ago

hrsalehi commented 8 years ago

Hi I wrote a BottomSheetDialogFragment and inflated a custom view in it but i have a little problem doing these:

  1. making dialog full screen : bottom sheets opens like 50% of screen and you can drag it to full screen but I want to open It full screen
  2. How can I disable gestures like drag? I have a scroll view inside bottom sheet and by dragging It must scroll It's content not open or close bottom sheet.
public class NewFoodDialog extends BottomSheetDialogFragment {
    private BottomSheetBehavior.BottomSheetCallback mBottomSheetBehaviorCallback = new BottomSheetBehavior.BottomSheetCallback() {

        @Override
        public void onStateChanged(@NonNull View bottomSheet, int newState) {
            if (newState == BottomSheetBehavior.STATE_HIDDEN) {
                dismiss();
            }

        }

        @Override
        public void onSlide(@NonNull View bottomSheet, float slideOffset) {
        }
    };

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View contentView = View.inflate(getContext(), R.layout.dialog_add_food, null);

        CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) ((View) contentView.getParent()).getLayoutParams();
        CoordinatorLayout.Behavior behavior = params.getBehavior();

        if( behavior != null && behavior instanceof BottomSheetBehavior ) {
            ((BottomSheetBehavior) behavior).setBottomSheetCallback(mBottomSheetBehaviorCallback);
        }

        return contentView;
    }

    @Override
    public void setupDialog(Dialog dialog, int style) {
        super.setupDialog(dialog, style);

    }
}
rubensousa commented 8 years ago

Hi, I just updated the sample with an example of this. Check out the new FullBottomSheetDialogFragment at: https://github.com/rubensousa/BottomSheetExample/blob/master/app/src/main/java/com/github/rubensousa/bottomsheetexample/ui/FullBottomSheetDialogFragment.java

public class FullBottomSheetDialogFragment extends BottomSheetDialogFragment
        implements ItemAdapter.ItemListener {

    private BottomSheetBehavior mBehavior;

    @NonNull
    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        BottomSheetDialog dialog = (BottomSheetDialog) super.onCreateDialog(savedInstanceState);

        View view = View.inflate(getContext(), R.layout.sheet, null);

        view.findViewById(R.id.fakeShadow).setVisibility(View.GONE);
        RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.recyclerView);
        recyclerView.setHasFixedSize(true);
        recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
        ItemAdapter itemAdapter = new ItemAdapter(createItems(), this);
        recyclerView.setAdapter(itemAdapter);

        dialog.setContentView(view);
        mBehavior = BottomSheetBehavior.from((View) view.getParent());
        return dialog;
    }

    @Override
    public void onStart() {
        super.onStart();
        mBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);
    }

    public List<Item> createItems() {
        ArrayList<Item> items = new ArrayList<>();
        items.add(new Item(R.drawable.ic_preview_24dp, "Preview"));
        items.add(new Item(R.drawable.ic_share_24dp, "Share"));
        items.add(new Item(R.drawable.ic_link_24dp, "Get link"));
        items.add(new Item(R.drawable.ic_content_copy_24dp, "Copy"));
        items.add(new Item(R.drawable.ic_preview_24dp, "Preview"));
        items.add(new Item(R.drawable.ic_share_24dp, "Share"));
        items.add(new Item(R.drawable.ic_link_24dp, "Get link"));
        items.add(new Item(R.drawable.ic_content_copy_24dp, "Copy"));
        items.add(new Item(R.drawable.ic_preview_24dp, "Preview"));
        items.add(new Item(R.drawable.ic_share_24dp, "Share"));
        items.add(new Item(R.drawable.ic_link_24dp, "Get link"));
        items.add(new Item(R.drawable.ic_content_copy_24dp, "Copy"));
        items.add(new Item(R.drawable.ic_preview_24dp, "Preview"));
        items.add(new Item(R.drawable.ic_share_24dp, "Share"));
        items.add(new Item(R.drawable.ic_link_24dp, "Get link"));
        items.add(new Item(R.drawable.ic_content_copy_24dp, "Copy"));
        return items;
    }

    @Override
    public void onItemClick(Item item) {
        mBehavior.setState(BottomSheetBehavior.STATE_HIDDEN);
    }
}
LOG-TAG commented 7 years ago

@rubensousa while recyclerview scrolling ends BottomSheetDialogFragment should not be dragged down !! any ways to do that?

not working !

@Override
public void onStateChanged(@NonNull View bottomSheet, int newState) {

    if (newState == BottomSheetBehavior.STATE_DRAGGING) {
        mBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);
    }
ishaan-khan commented 7 years ago

This however does not cover the toolbar, any idea how to achieve that?

nasreekar commented 6 years ago

@ishaan-khan Were you able to achieve that?