Skip to content

Commit

Permalink
Bugfix/#152 pan to center (#158)
Browse files Browse the repository at this point in the history
* added boolean return value to callback function for easier delegation

* respect realZoom when calculating transformationPan
  • Loading branch information
markusressel authored Jun 12, 2020
1 parent c906c5b commit adeed37
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 19 deletions.
21 changes: 10 additions & 11 deletions library/src/main/java/com/otaliastudios/zoom/ZoomEngine.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@ import android.annotation.SuppressLint
import android.content.Context
import android.graphics.Matrix
import android.graphics.RectF
import android.view.*
import android.view.Gravity
import android.view.MotionEvent
import android.view.View
import android.view.ViewTreeObserver
import com.otaliastudios.zoom.ZoomApi.*
import com.otaliastudios.zoom.internal.UpdatesDispatcher
import com.otaliastudios.zoom.internal.matrix.MatrixController
import com.otaliastudios.zoom.internal.StateController
import com.otaliastudios.zoom.internal.UpdatesDispatcher
import com.otaliastudios.zoom.internal.gestures.PinchDetector
import com.otaliastudios.zoom.internal.gestures.ScrollFlingDetector
import com.otaliastudios.zoom.internal.matrix.MatrixController
import com.otaliastudios.zoom.internal.matrix.MatrixUpdate
import com.otaliastudios.zoom.internal.movement.PanManager
import com.otaliastudios.zoom.internal.movement.ZoomManager
Expand Down Expand Up @@ -76,13 +79,9 @@ internal constructor(context: Context) : ZoomApi {

// Post utilities

override fun post(action: Runnable) {
container.post(action)
}
override fun post(action: Runnable): Boolean = container.post(action)

override fun postOnAnimation(action: Runnable) {
container.postOnAnimation(action)
}
override fun postOnAnimation(action: Runnable) = container.postOnAnimation(action)

// Matrix callbacks

Expand Down Expand Up @@ -607,8 +606,8 @@ internal constructor(context: Context) : ZoomApi {
* dimensions. This means applying the transformation gravity.
*/
private fun computeTransformationPan(): ScaledPoint {
val extraWidth = contentWidth - containerWidth
val extraHeight = contentHeight - containerHeight
val extraWidth = contentWidth * realZoom - containerWidth
val extraHeight = contentHeight * realZoom - containerHeight
val gravity = computeTransformationGravity(transformationGravity)
val x = -panManager.applyGravity(gravity, extraWidth, true)
val y = -panManager.applyGravity(gravity, extraHeight, false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ internal class MatrixController(
internal interface Callback {
fun onMatrixUpdate()
fun onMatrixSizeChanged(oldZoom: Float, firstTime: Boolean)
fun post(action: Runnable)
fun post(action: Runnable): Boolean
fun postOnAnimation(action: Runnable)
}

Expand Down Expand Up @@ -151,13 +151,9 @@ internal class MatrixController(
}


internal fun post(action: Runnable) {
callback.post(action)
}
internal fun post(action: Runnable) = callback.post(action)

internal fun postOnAnimation(action: Runnable) {
callback.postOnAnimation(action)
}
internal fun postOnAnimation(action: Runnable) = callback.postOnAnimation(action)

/**
* Clears our state.
Expand Down Expand Up @@ -213,7 +209,7 @@ internal class MatrixController(
private fun sync() {
stub.mapRect(contentScaledRect, contentRect)
}

private fun dispatch() {
callback.onMatrixUpdate()
}
Expand Down

0 comments on commit adeed37

Please sign in to comment.