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.75k stars 292 forks source link

Shadow not displaying. SetElevation not working #35

Closed GuillemRoca closed 4 years ago

GuillemRoca commented 4 years ago

Please complete the following information:

Describe the Bug:

I tried the parameter setElevation in order to display the shadow as recently you released this feature in version 1.1.3 and I couldn't manage to get it to work.

I've tested in my own app and in the sample of the repo and I couldn't manage to get it to work, I've edited all the Factories without success:

Sample code

class TagBalloonFactory : Balloon.Factory() {

  override fun create(context: Context, lifecycle: LifecycleOwner?): Balloon {
    return createBalloon(context) {
      setLayout(R.layout.layout_custom_tag)
      setArrowSize(10)
      setArrowOrientation(ArrowOrientation.BOTTOM)
      setArrowPosition(0.5f)
      setElevation(10f)
      setPadding(4)
      isRtlSupport(BalloonUtils.isRtlLayout())
      setCornerRadius(4f)
      setBalloonAnimationStyle(R.style.ElasticAndFadeOut)
      setBackgroundColorResource(R.color.white_93)
      setAutoDismissDuration(2000L)
      setDismissWhenClicked(true)
      setDismissWhenShowAgain(true)
      setLifecycleOwner(lifecycle)
    }
  }
}

Also shouldn't the elevation be set as the padding or the width/height which is an Int and not a Float for consistency API reasons? The elevation should also be applied in dp.

Expected Behavior:

The elevation should behave as normal and be displayed in the UI.

PS: Thanks for the awesome library! Keep up the good work! 💪

rajal2009 commented 4 years ago

Yes, I am also using setElevation and setArrowColor but not working.

it's just display normal background without elevation and arrow color can not be changed

skydoves commented 4 years ago

@GuillemRoca @rajal2009 Hi, I checked this issue just now and I will try to fix it soon! If you have any idea, please let me know or make a pull request! Thank you for your issue :)

skydoves commented 4 years ago

@rajal2009 Also, I checked the setArrowColor method is not working when the color is white. It will be fixed on the next release! Thank you for your issue :)

GuillemRoca commented 4 years ago

Hello @skydoves!

After a brief investigation, I believe this could be caused by this.

In the method:

  private fun initializeBalloonListeners() {
    this.onBalloonClickListener = builder.onBalloonClickListener
    this.onBalloonDismissListener = builder.onBalloonDismissListener
    this.onBalloonOutsideTouchListener = builder.onBalloonOutsideTouchListener
    this.bodyView.setOnClickListener {
      this.onBalloonClickListener?.onBalloonClick(it)
      if (builder.dismissWhenClicked) dismiss()
    }
    with(this.bodyWindow) {
      setOnDismissListener { onBalloonDismissListener?.onBalloonDismiss() }
      setBackgroundDrawable(ColorDrawable(Color.WHITE))
      isOutsideTouchable = true
      setTouchInterceptor(object : View.OnTouchListener {
        @SuppressLint("ClickableViewAccessibility")
        override fun onTouch(view: View, event: MotionEvent): Boolean {
          if (event.action == MotionEvent.ACTION_OUTSIDE) {
            if (builder.dismissWhenTouchOutside) {
              this@Balloon.dismiss()
            }
            onBalloonOutsideTouchListener?.onBalloonOutsideTouch(view, event)
            return true
          }
          return false
        }
      })
    }
  }

I've changed the setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT)) to White and now the elevation is displayed correctly! 🍾

The bad thing is that it messes with the arrow and the background set in the API. Maybe you can help me get to the final solution.

skydoves commented 4 years ago

Hi, @GuillemRoca , @rajal2009 It is fixed on version 1.1.7. Thank you for your issue! :)

GuillemRoca commented 4 years ago

Awesome! I will take a look and test it! 😄

GuillemRoca commented 4 years ago

I've finally had time to test it and it works as intended! Great work and great library! :D