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 147 forks source link

Unwanted animated zoom after setMaxZoom call #213

Closed sergsave closed 2 years ago

sergsave commented 2 years ago

Describe the bug

ZoomLayout zooms when after setMaxZoom(xx, ZoomApi.TYPE_REAL_ZOOM) even current realZoom value less than maxZoom value

To Reproduce

val zoomLayout = binding.zoomLayout

zoomLayout.realZoomTo(1.5f, false)

// Just wait while zoom applied
zoomLayout.postDelayed(1000) {
    // With current transformation the zoom value is greater than the realZoom value
    val zoom = zoomLayout.zoom // 2.21f
    val realZoom = zoomLayout.realZoom // 1.5f

    // After setMaxZoom call a layout automatically zooms with animation
    // But why? maxZoom value is less than current realZoom value
    val maxZoom = 2f
    zoomLayout.setMaxZoom(maxZoom, ZoomApi.TYPE_REAL_ZOOM)
}

Expected behavior

The layout should not be zoomed when setting the maximum zoom, if the current zoom value is less than the setted maximum value.

sergsave commented 2 years ago

Maybe this is because of this comparison https://github.com/natario1/ZoomLayout/blob/94962c425e87a2014eb118c1811000495772cb38/library/src/main/java/com/otaliastudios/zoom/ZoomEngine.kt#L850

zoom has annotation @Zoom, zoomManager.getMaxZoom() has annotation @ZoomApi.RealZoom. I think comparison of different types is not correct.

In setMinZoom value compares with realZoom value https://github.com/natario1/ZoomLayout/blob/94962c425e87a2014eb118c1811000495772cb38/library/src/main/java/com/otaliastudios/zoom/ZoomEngine.kt#L885

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had activity in the last 20 days. It will be closed if no further activity occurs within the next seven days. Thank you for your contributions.