natario1 / ZoomLayout

2D zoom and pan behavior for View hierarchies, images, video streams, and much more, written in Kotlin for Android.
https://natario1.github.io/ZoomLayout
Apache License 2.0
1.05k stars 148 forks source link

The library is behaving weird in ViewPager2 The first page is fine but the rest of pages are not properly indented and Not zooming #184

Open sam-devstudio opened 4 years ago

sam-devstudio commented 4 years ago

Describe the bug

Please add a clear description of what the bug is, and fill the list below.

To Reproduce

Expected behavior

Full Image should be shown on each page with Zooming allowed

XML layout

<?xml version="1.0" encoding="utf-8"?>
<com.otaliastudios.zoom.ZoomLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/zoomLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:animationDuration="300"
    app:hasClickableChildren="true"
    app:horizontalPanEnabled="true"
    app:maxZoom="4.0"
    app:minZoom="1.0"
    app:overPinchable="false"
    app:overScrollHorizontal="false"
    app:overScrollVertical="false"
    app:scrollEnabled="true"
    app:verticalPanEnabled="true"
    app:zoomEnabled="true"
    tools:context=".BlankFragment">
    <RelativeLayout
        android:id="@+id/rootLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <ImageView
            android:id="@+id/imageView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:scaleType="fitCenter"
            android:src="@drawable/sample1" />
        <Button
            android:id="@+id/btn"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="20dp"
            android:text="Signature Button" />
    </RelativeLayout>
</com.otaliastudios.zoom.ZoomLayout>

Screenshots

Screenshot_20201007-134213_Custom Zoom View

markusressel commented 4 years ago

Did you have a look at #37?

sam-devstudio commented 4 years ago

Did you have a look at #37?

Yes @markusressel before opening the issue I have searched for existing issues that one is for ViewPager and I have also tried the solutions that were provided there but none worked.

markusressel commented 4 years ago

Sorry, but I'm not sure how to help with this without a reproducable setup, and I'm very limited on time. I'll label this as a bug though so it won't be closed automatically. If you do find a solution, please let us know.

sam-devstudio commented 4 years ago

Sorry, but I'm not sure how to help with this without a reproducable setup, and I'm very limited on time. I'll label this as a bug though so it won't be closed automatically. If you do find a solution, please let us know.

Sure @markusressel I will definitely share the solution if I got one.

oOJohn6Oo commented 1 year ago

I edit the onTouchEvent() function of ZoomLayout, and it works fine inside ViewPager2 with horizontal scroll.

override fun onTouchEvent(ev: MotionEvent): Boolean {
    val interceptByEngine = engine.onTouchEvent(ev)
    if (ev.pointerCount > 1) {
        parent.requestDisallowInterceptTouchEvent(true)
    }else{
        if (engine.realZoom <= 1f){
            parent.requestDisallowInterceptTouchEvent(false)
        }else {
            val maxAvailableOffset = engine.computeHorizontalScrollRange() - width
            val isScrolledToViewEnd = engine.computeHorizontalScrollOffset().absoluteValue >= maxAvailableOffset
            parent.requestDisallowInterceptTouchEvent(!isScrolledToViewEnd)
        }
    }
    if (ev.actionMasked == MotionEvent.ACTION_UP){
        parent.requestDisallowInterceptTouchEvent(false)
    }
    return interceptByEngine || hasClickableChildren && super.onTouchEvent(ev)
}