skydoves / Balloon

:balloon: Modernized and sophisticated tooltips, fully customizable with an arrow and animations for Android.
https://skydoves.github.io/libraries/balloon/html/balloon/com.skydoves.balloon/index.html
Apache License 2.0
3.74k stars 291 forks source link

setOnBalloonOverlayClickListener does not work #160

Closed de-honcker closed 3 years ago

de-honcker commented 3 years ago

setOnBalloonOverlayClickListener does not work. The listener block assigned was not invoked.

Build and run the sample app. Click on the Edit Profile button Balloon is shown with overlay on top of the button Click on the overlay on top of the Edit Profile button

Observed Balloon dismissed with no overlay toast

Expected Behavior: overlay toast is displayed before dismissing balloon.

skydoves commented 3 years ago

Hi, please try using the below code.

      .setDismissWhenTouchOutside(false)
      .setOnBalloonOverlayClickListener {
        Toast.makeText(context.applicationContext, "setOnBalloonOverlayClickListener", Toast.LENGTH_SHORT).show()
      }.build()

There are a lot of listeners and it could be invoked at the same time, so we should call each action.

de-honcker commented 3 years ago

Thanks. setDismissWhenTouchOutside(true) was preventing the listeners to fire. Setting it to false works.

NattyBadWolf commented 3 years ago

Hi @skydoves But what if I need both behaviour, dismiss when touch outside AND click on balloon overlay? What should I do? Thanks!

skydoves commented 3 years ago

Hi, @NattyBadWolf You can implement it using the below codes.

setIsVisibleOverlay(true)
setDismissWhenTouchOutside(false)
setDismissWhenOverlayClicked(false)
setOnBalloonOverlayClickListener {
    Toast.makeText(context.applicationContext, "setOnBalloonOverlayClickListener", Toast.LENGTH_SHORT).show()
}
NattyBadWolf commented 3 years ago

Probably I wasn't very clear, I need click on overlay shape so it performs the same behavior as without balloon. Also I need dismiss when clicked outside. Is it possible?

abhimuktheeswarar commented 3 years ago

Hi, Thanks for this awesome library. Our requirement is: when clicking on the anchor view, which is highlighted, we need a callback (listener). But when clicking outside, the ballon should dismiss. Some like this will do:

setIsVisibleOverlay(true)
setDismissWhenTouchOutside(false)
setDismissWhenOverlayClicked(false)
setOnHighlightedViewClickListener {
    Toast.makeText(context.applicationContext, "setOnHighlightedViewClickListener", Toast.LENGTH_SHORT).show()
}
12345debdut commented 2 years ago

@NattyBadWolf I have achieved the same thing with a bit hack such as --> .setOnBalloonOverlayTouchListener { _, motionEvent -> if(binding.anchorView.isInRange(PointF(motionEvent.rawX, motionEvent.rawY))) { // Do what ever you want with the touch for overlay click } else { // Do whatever you want with the outside touch. } }

fun View.isInRange(point: PointF): Boolean { val topLeft = getActualLocationOnScreenP(getCenterX = false, getCenterY = false) val xRange = topLeft.x..(topLeft.x + width) val yRange = topLeft.y..(topLeft.y + height) return (point.x in xRange) && (point.y in yRange) }