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

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 this issue Oct 7, 2020 · 5 comments
Labels

Comments

@sam-devstudio
Copy link

sam-devstudio commented Oct 7, 2020

Describe the bug

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

  • Library version: 1.8.0
  • Reproducible in official demo app: yes/no
  • Device / Android version: Samsung S7, API 27
  • The first page shows correctly and Zoomable and the rest of the pages are not center aligned and not zoomable and draggable (as shown in screenshot)
  • If I set offset page limit to number of pages the pages render correctly but its an overhead for memory

To Reproduce

  • Add ViewPager2- in an project
  • Create PagerAdapter
  • Set offset Page limit to 1
  • Create pages count to 4
  • Add ZoomLayout on each page
  • Add an ImageView inside ZoomLayout -> RelativeLayout -> ImageView
  • Set an image on ImageView

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
Copy link
Collaborator

Did you have a look at #37?

@sam-devstudio
Copy link
Author

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
Copy link
Collaborator

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
Copy link
Author

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
Copy link

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)
}

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

No branches or pull requests

3 participants