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.69k stars 289 forks source link

Missing ability to finish Activitiy instead of Balloon being dismissed #103

Closed KonradSzewczuk closed 3 years ago

KonradSzewczuk commented 3 years ago

Please complete the following information:

Describe the Bug:

While not showing Balloon in my FragmentActivity when I tap the phone system back button the Activity is being finished and the app goes to background. But while showing Balloon in this FragmentActivity when I tap the phone system back button I am only dismissing the Balloon, and not finishing the Activity in which the Balloon is being shown (as in the previous scenario)

Code:

@MainThread
fun ComponentActivity.topTooltip(): Lazy<Balloon> {
    return ActivityBalloonLazy(this, this, TopTooltipFactory::class)
}

class TopTooltipFactory : TooltipFactory() {

    override fun create(context: Context, lifecycle: LifecycleOwner?): Balloon {
        return baseBalloon(context, lifecycle).setArrowOrientation(BOTTOM).build()
    }
}

abstract class TooltipFactory : Balloon.Factory() {

    @Suppress("MagicNumber")
    fun baseBalloon(context: Context, lifecycle: LifecycleOwner?): Balloon.Builder {
        return Balloon.Builder(context)
            .setLayout(R.layout.my_layout)
            .setMarginLeft(16)
            .setMarginRight(16)
            .setCornerRadius(8f)
            .setArrowSize(12)
            .setArrowConstraints(ALIGN_ANCHOR)
            .setArrowColorResource(R.color.blue)
            .setBackgroundDrawableResource(R.drawable.tooltip_background)
            .setBalloonAnimation(FADE)
            .setElevation(0)
            .setDismissWhenClicked(true)
            .setLifecycleOwner(lifecycle)
    }
}

interface IMyView {
    fun onCreate(view: View)
    fun showTooltip()
}

class MyView @Inject constructor(
    activity: FragmentActivity
) : IMyView {

   private lateinit var view: View
   private val tooltip by activity.topTooltip()

    override fun onCreate(view: View) {
        this.view = view
    }

   override fun showTooltip() {
       val image: BottomNavigationItemView = ///
       tooltip.apply {
                        // 
                        show(image)
            }
    }
}

Expected Behavior:

As a user when I try to click the phone back button I should be able to finish my current activity (only one on the stack) despite the Balloon is being shown, instead of only dismissing the current Balloon and not finishing my activity.

@skydoves Is it possible to fulfill my requirements with the library?

skydoves commented 3 years ago

Hi, You can use the below method for removing focus from the balloon.

.setFocusable(false)