Reputation: 163
I've been searching all over the internet over the last couple of days, to no avail. I'm trying to code something like a BottomSheetDialog
that can be dismissed (swiped out of view) either upwards or downwards.
If such a view would be coded from scratch, the use case would be as follows: The view fills the entire screen, and can be dragged up or down (only vertical movement). When dragged and released the view should have a velocity and keep moving accordingly. Once the view moves off screen, a callback should fire, indicating whether the view was moving upwards or downwards.
I don't expect the answer to be handed to me. I'm assuming I'd have to code something like this from the ground up. I just have no idea where to start. Which Android components (ViewDragHelper
, etc) could I use to create something like this? I've had some success with just an OnTouchListener
, checking for the MotionEvent.ACTION_MOVE
flag and using the received motion event's data to modify the view's LayoutParams
as shown here. How would I then go about velocity?
Upvotes: 1
Views: 206
Reputation: 163
I ended up modifying BottomSheet from the Plaid app, as suggested by @azizbekian.
The most notable changes were made in the computeSettleDuration
method and in clampViewPositionVertical
callback found in ViewDragHelper.Callback
.
It was surprisingly easy to get it working as intended. The source code can be viewed here.
Upvotes: 1