diff --git a/library/src/main/java/com/telefonica/mistica/button/ProgressButton.kt b/library/src/main/java/com/telefonica/mistica/button/ProgressButton.kt index 2600ec602..ab5256bca 100644 --- a/library/src/main/java/com/telefonica/mistica/button/ProgressButton.kt +++ b/library/src/main/java/com/telefonica/mistica/button/ProgressButton.kt @@ -191,7 +191,6 @@ class ProgressButton : FrameLayout { } } - @SuppressLint("ClickableViewAccessibility") private fun setButtonBackground() { buttonBackground.apply { id = NO_ID @@ -204,29 +203,38 @@ class ProgressButton : FrameLayout { setTextColor(Color.TRANSPARENT) visibility = VISIBLE setOnTouchListener { view, event -> + var eventConsumed = false when (event.action) { MotionEvent.ACTION_DOWN -> { - buttonNormal.isPressed = true - buttonLoading.isPressed = true + setButtonPressed(true) } MotionEvent.ACTION_MOVE -> { val outsideBounds = event.x < 0 || event.y < 0 || event.x > view.measuredWidth || event.y > view.measuredHeight - buttonNormal.isPressed = !outsideBounds - buttonLoading.isPressed = !outsideBounds + setButtonPressed(!outsideBounds) + } + + MotionEvent.ACTION_UP -> { + setButtonPressed(false) + view.performClick() + eventConsumed = true } - MotionEvent.ACTION_UP, MotionEvent.ACTION_CANCEL -> { - buttonNormal.isPressed = false - buttonLoading.isPressed = false + MotionEvent.ACTION_CANCEL -> { + setButtonPressed(false) } } - false + eventConsumed } } } + private fun setButtonPressed(pressed: Boolean) { + buttonNormal.isPressed = pressed + buttonLoading.isPressed = pressed + } + private fun addViews() { addView(buttonBackground) addView(buttonNormal)