material-components / material-components-android

Modular and customizable Material Design UI components for Android
Apache License 2.0
16.37k stars 3.07k forks source link

[Snackbar] Custom view can't be dragged #1333

Closed simoks closed 2 years ago

simoks commented 4 years ago

I have created a custom view extending from the BaseTransientBottomBar class. I can't drag to dismiss this view, so no animation is visible for dragging.

When I'm trying to drag the view, the message below is shown in my logcat console : "Ignoring pointerId=0 because ACTION_DOWN was not received for this pointer before ACTION_MOVE. It likely happened because ViewDragHelper did not receive all the events in the event stream."

class CustomSnackBar (parent: ViewGroup, content: CustomView) : BaseTransientBottomBar< CustomView >(parent, content, content){

..... }

val behavior = Behavior().apply { setSwipeDirection(SwipeDismissBehavior.SWIPE_DIRECTION_END_TO_START) setDragDismissDistance(0.3f) }

customSnackBar.setDuration(Snackbar.LENGTH_INDEFINITE).setBehavior(behavior)

Android target and compiled SdkVersion: : 28

Material Library version: tested with 1.1.0, 1.2.0-alpha05, 1.2.0-alpha07 (the same problem)

elliotmurray commented 4 years ago

I'm experiencing this problem with the default SnackBar too, seems to be something to do with it recieving a ACTION_CANCEL event from the CoordinatorLayout when the SwipeDismissBehavior calls requestDisallowInterceptTouchEvent in onViewCaptured.

marcardar commented 3 years ago

@elliotmurray I'm also experiencing this with the default snackbar. Did you find a solution?

Does this help: https://stackoverflow.com/a/42222170/444761 (also: https://www.codeleading.com/article/43344985927/ )

kingwang666 commented 2 years ago

Behavior touch event comes from CoordinatorLayout. I think CoordinatorLayout parent requestDisallowInterceptTouchEvent should be used