Aghajari / ZoomHelper

ZoomHelper will make any view to be zoomable just like Instagram pinch-to-zoom
Apache License 2.0
247 stars 22 forks source link

fragment issue #11

Open shoesboy opened 3 years ago

shoesboy commented 3 years ago

hello aghajari

I have a question I'm using five "fragments" for one "activity" in my app. One "fragment" is again using two "fragments". This "fragment" has two "fragments" doing "show/hide", not "attach" depending on the button.

In issue #4

return supportFragmentManager.findFragmentById(R.id.container)?.view?.let {
             ZoomHelper.getInstance().dispatchTouchEvent(ev!!, it)
           }!! || super.dispatchTouchEvent(ev)

You advised this code, it works very well when "fragment" is attached or detached However, after attaching another fragment from the existing "fragment", if you detach the fragment and show "fragment", the displayed "fragment" does not zoom.

What should I do in this case?

Aghajari commented 3 years ago

Hi, i couldn't understand what exactly do you mean, but here an idea that can solve any issue:

  1. Add ZoomLayout to your project
  2. Fragments should use this layout as the main layout
class ZoomLayout @JvmOverloads constructor(
    context: Context,
    attrs: AttributeSet? = null,
    defStyle: Int = 0
) : FrameLayout(context, attrs, defStyle)

    override fun dispatchTouchEvent(ev: MotionEvent?): Boolean {
        return (context != null && ZoomHelper.getInstance().dispatchTouchEvent(ev!!, this))
                || super.dispatchTouchEvent(ev)
    }
}

You won't need to override dispatchTouchEvent on the Activity anymore.