Closed de-honcker closed 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.
Thanks. setDismissWhenTouchOutside(true)
was preventing the listeners to fire. Setting it to false works.
Hi @skydoves But what if I need both behaviour, dismiss when touch outside AND click on balloon overlay? What should I do? Thanks!
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()
}
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?
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()
}
@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) }
setOnBalloonOverlayClickListener
does not work. The listener block assigned was not invoked.EditBalloonFactory
code to the following and addsetOnBalloonOverlayClickListener
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 theEdit Profile
buttonObserved Balloon dismissed with no
overlay
toastExpected Behavior:
overlay
toast is displayed before dismissing balloon.