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

Bugfix/#152 pan to center #158

Merged
merged 3 commits into from
Jun 12, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are the important 2 lines.

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