ZoomLayout icon indicating copy to clipboard operation
ZoomLayout copied to clipboard

ZoomLayout.zoomTo() ignored when loading images of different resolutions

Open littledot opened this issue 2 years ago • 1 comments

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: no, but repro app included
  • Device / Android version: Nexus 5, API 21

I'm implementing a feature that allows users to select the resolution of the image being displayed. I reset the zoom to 1 with zoomTo(1f, false) when the user selects a resolution, like so:

    fun loadImg(res: Int) {
        zoom.zoomTo(1f, false)
        img.setImageResource(res)
        zoom.zoomTo(1f, false)
        zoomInfo()
    }

but ZoomLayout sometimes ignores the call and sets the zoom to 2.

If you run my repro app, then tap the 3 resolution buttons, you'll see the unwanted jumps in zoom levels. Pan the image around with 1 finger to get updated zoom and realZoom values.

To Reproduce

Steps to reproduce the behavior, possibly in the demo app:

  1. Run my repro app https://github.com/littledot/android-bug-report
  2. Click on 160p, 320p, etc.
  3. Pan the image with 1 finger to get updated ZoomLayout info

Expected behavior

.zoomTo() should not be ignored.

XML layout

Declaration of your XML component, so we can read its attributes.

    <com.otaliastudios.zoom.ZoomLayout
        android:id="@+id/zoom"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:maxZoom="1000.00"
        app:minZoom="1.0"
        app:overPinchable="false"
        app:overScrollHorizontal="false"
        app:overScrollVertical="false">

        <ImageView
            android:id="@+id/img"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />

    </com.otaliastudios.zoom.ZoomLayout>

Screenshots

If applicable, add screenshots to help explain your problem.

Logs

If applicable, please add logs to help diagnose the problem. Use ZoomLogger.setLogLevel(LEVEL_INFO) to stream all logs into LogCat.

APK

Link to a Github repo where the bug is reproducible.

littledot avatar Aug 08 '21 23:08 littledot

Thx for the detailed bug report ❤️ Not sure when I have time, but I will try to investigate this. If you find any hints as to why this might be happening, feel free to open a PR.

markusressel avatar Aug 09 '21 12:08 markusressel