BottomSheetDialogFragment removes corners when swiped up even though it is not covering full screen

722 Views Asked by At

I want to have a BottomSheetDialogFragment where I can select an item from a few items. I want it to never go full screen. I want rounded corners at top left and top right.

For the purposes above, I have implemented an ItemSelectionBottomSheetDialogFragment as follows:

class ItemSelectionBottomSheetDialogFragment : BottomSheetDialogFragment() {

    ...

    override fun getTheme(): Int = R.style.ThemeOverlay_Demo_BottomSheetDialog


    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?) {
        ...
    }
}

fragment_item_selection.xml:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.ItemSelectionBottomSheetDialogFragment">

    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/item_list"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" />

</FrameLayout>

styles.xml:

    <style name="ThemeOverlay.Demo.BottomSheetDialog" parent="@style/ThemeOverlay.MaterialComponents.BottomSheetDialog">
        <item name="bottomSheetStyle">@style/Widget.Demo.BottomSheet</item>
    </style>

    <style name="Widget.Demo.BottomSheet" parent="Widget.MaterialComponents.BottomSheet">
        <item name="shapeAppearanceOverlay">@style/ShapeAppearanceOverlay.Demo</item>
    </style>

    <style name="ShapeAppearanceOverlay.Demo" parent="">
        <item name="cornerSizeTopLeft">30dp</item>
        <item name="cornerSizeTopRight">3dp</item>
        <item name="cornerFamily">rounded</item>
    </style>

When I show the fragment, it appears from below, along with rounded corners. However, when I swipe up a little, the bottom sheet dialog doesn't go further up but top corners are animated from rounded to a square shape with right angle.

How can I resolve this problem?

0

There are 0 best solutions below