material-components-android
material-components-android copied to clipboard
[BottomSheet] Incorrect position when bottom sheet's default layout position is not at the top of parent
Description:
When bottom sheet would get laid out not at the top of parent view it gets positioned too low. In the example I'm using fixed height that's smaller than screen height and layout_gravity="bottom" to achieve this effect. Dragging the sheet fixes its position, but calling requestLayout will move it to wrong place again.
Expected behavior:
Bottom sheet position is correct and doesn't change when calling requestLayout().
Source code:
<androidx.coordinatorlayout.widget.CoordinatorLayout 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:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/bs"
android:layout_width="match_parent"
android:layout_height="800dp"
android:background="#1B5E20"
android:layout_gravity="bottom"
app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior"
>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
Minimal sample app repro: https://github.com/tabasavr/BottomSheet-layout-position-bug
This app is also set up to call requestLayout() when bottom sheet is clicked. Height used works for Pixel 8 emulator, it might need to be adjusted for other devices
Android API version: 21, 34, probably all of them
Material Library version: 1.13.0-alpha04, 1.12.0
Device: Emulators API 21 and 34