I have an app with bottomsheet opened upto 90% of the screen height. How can I know if the user is dragging up/down the bottomsheet. I read we can use onSlide() but the offset values are NaN and sometimes outright weird, so it seems kinda unreliable. Any help is appreciated. Thanks in advance.
set bottomSheet onClickListener to null. bottomSheet. setOnClickListener(null); this line disables all action about bottomSheet only and does not effect on inner view.
Bottom Sheet is a well-written material design component that performs enter/exit animations, respond to dragging/swiping gestures, etc. For using it in your project you should implement next dependencies into your app build.gradle file: implementation "androidx.coordinatorlayout:coordinatorlayout:1.1.0"
Android BottomSheet is a kind of view that is used as supplementary surfaces in mobile apps. This component is a part of the android design support library and is used to expose more data or information, menus, deep linked content, and in place of dialogs.
↳ com.google.android.material.bottomsheet.BottomSheetDialogFragment. Modal bottom sheet. This is a version of DialogFragment that shows a bottom sheet using BottomSheetDialog instead of a floating dialog.
bottomsheet documention doens't work but i think i figured it out to clear up the documentation read:
Hidden state is -1.0, collapsed state is 0.0 and expanded state is 1.0.
for me i see it only going from 1 to 0, and 0 to 1. That is because i did not have a hidden state, my sheeet was always to be shown at a peekheight. So as an example, if you have a sheet that will never been hidden you can try this:
just keep a property variable called oldOffSet and then do this:
behavior.addBottomSheetCallback(object : BottomSheetBehavior.BottomSheetCallback() {
var oldOffSet = 0f
override fun onSlide(bottomSheet: View, slideOffset: Float) {
val inRangeExpanding = oldOffSet < slideOffset
val inRangeCollapsing = oldOffSet > slideOffset
oldOffSet = slideOffset
}
}
You can add a BottomSheetCallback
to know the status and the direction.
Something like:
BottomSheetBehavior<...> bottomSheetBehavior = BottomSheetBehavior.from(bottomSheetLayout);
bottomSheetBehavior.addBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() {
@Override public void onStateChanged(@NonNull View bottomSheet, int newState) {
if (newState == BottomSheetBehavior.STATE_DRAGGING){
// Dragging state
}
}
@Override public void onSlide(@NonNull View bottomSheet, float slideOffset) {
// The new offset of this bottom sheet within [-1,1] range.
// Offset increasesas this bottom sheet is moving upward.
// From 0 to 1 the sheet is between collapsed and expanded states and
// From -1 to 0 it is between hidden and collapsed states.
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With