Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

setOnBalloonOutsideTouchListener is not getting invoked when clicking outside the popup nor the setOnBalloonOverlayClickListener #701

Open
CoderGautam07 opened this issue Sep 13, 2024 · 7 comments

Comments

@CoderGautam07
Copy link

  • Library Version 1.6.7
  • Affected Device(s) Was testing on my own device Mi POCO X3

I am showing tool tip on a button with overlay in my project and its getting visible fine. Now i want when user clicks on button bounds the click should be passed to the button and its action should be performed. I tried using passClickToAnchor(true) but it didn't worked. Then tried setOnBalloonOutsideTouchListener and setOnBalloonOverlayClickListener but it also was not invoked when i clicked on the overlay or clicked anywhere outside the tooltip balloon. Am i missing something or is it a bug?

I expect that if i have set passClickToAnchor(true) while creating balloon using createBalloon{} kotlin dsl the click should be passed to the anchor if the click is in the bounds which is not happening currently.

Here's how i created it
`val textForm = TextForm.Builder(fragmentContext)
.setText(fragmentContext.resources.getString(R.string.click_to_view_directions))
.setTextColorResource(R.color.text_color_primary)
.setTextSize(14f)
.setTextTypeface(ResourcesCompat.getFont(fragmentContext, R.font.poppins_regular))
.setIncludeFontPadding(false)
.build()

	val balloon = createBalloon(fragmentContext) {
		setWidth(BalloonSizeSpec.WRAP)
		setHeight(BalloonSizeSpec.WRAP)
		setTextForm(textForm)
		setArrowPositionRules(ArrowPositionRules.ALIGN_ANCHOR)
		setArrowSize(10)
		setArrowPosition(0.5f)
		setPaddingHorizontal(16)
		setPaddingVertical(12)
		setCornerRadius(16f)
		setElevation(0)
		setShouldPassTouchEventToAnchor(true)
		setBackgroundColorResource(R.color.background_color_0)
		setBalloonAnimation(BalloonAnimation.OVERSHOOT)
		setLifecycleOwner(viewLifecycleOwner)
		setOverlayColorResource(R.color.black_overlay)
		setOverlayShape(BalloonOverlayRoundRect(12f, 12f))
		setIsVisibleOverlay(true)
		setOverlayPadding(6f)
		setBalloonHighlightAnimation(BalloonHighlightAnimation.SHAKE)
		build()
	}
	
	//its not getting invoked when i click anywhere on overlay nor setShouldPassTouchEventToAnchor works
	tooltipBalloon.setOnBalloonOverlayClickListener { 
			Toast.makeText(context, "touched outside", Toast.LENGTH_SHORT).show()
		}`
@skydoves
Copy link
Owner

Hi, would you add the code below on your builder?

.setDismissWhenTouchOutside(false)

@CoderGautam07
Copy link
Author

CoderGautam07 commented Sep 17, 2024

It worked, Thanks but i also want that when i click on the anchor view along with passing the click to the anchor the balloon and overlay dismisses as well, can we achieve that as well?
Currently the click is being passed to the anchor if i click with the bounds of the anchor but overlay and tooltip stays.

@skydoves
Copy link
Owner

I don't get what issue you are describing. Do you mean you need to allow clicking the outside but if you click the anchor view, it should dismiss the balloon? Not sure if this works.

.setDismissWhenTouchOutside(false)
.setFocusable(false)

@CoderGautam07
Copy link
Author

What i want is :-
Case 1 :- when click happens within the bounds of anchor view the click gets passed to the anchor view and balloon also dismisses.
Case 2 :- When click happens outside the bounds of anchor view(anywhere on screen but not on the anchor view) that should dismiss the balloon only.

@skydoves
Copy link
Owner

Case 1: You can just call the balloon.dismiss() method on your anchor view.
Case 2: You can call the balloon.dismiss() method inside setOnBalloonOverlayClickListener.

@skydoves
Copy link
Owner

Btw, there's no way that you can pass a click event through the overlay to your anchor view. It's an entire window the will be displayed on your screen.

@CoderGautam07
Copy link
Author

So i need to set .setDismissWhenTouchOutside(false) as well and use the solution you provided for the dismiss cases right?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants