From 2f1d4d0a40d62ca7400db23c2b00a3462c711f54 Mon Sep 17 00:00:00 2001 From: Markus Ressel Date: Wed, 4 Nov 2020 04:42:22 +0100 Subject: [PATCH 1/2] don't use PropertyValuesHolder.ofObject since it seems to behave in a weird way --- .../zoom/internal/matrix/MatrixController.kt | 32 ++++++------------- 1 file changed, 10 insertions(+), 22 deletions(-) diff --git a/library/src/main/java/com/otaliastudios/zoom/internal/matrix/MatrixController.kt b/library/src/main/java/com/otaliastudios/zoom/internal/matrix/MatrixController.kt index 74d96ca..d81b660 100644 --- a/library/src/main/java/com/otaliastudios/zoom/internal/matrix/MatrixController.kt +++ b/library/src/main/java/com/otaliastudios/zoom/internal/matrix/MatrixController.kt @@ -302,14 +302,6 @@ internal class MatrixController( activeAnimators.clear() } - private val absolutePointEvaluator = TypeEvaluator { fraction: Float, startValue: AbsolutePoint, endValue: AbsolutePoint -> - startValue + (endValue - startValue) * fraction - } - - private val scaledPointEvaluator = TypeEvaluator { fraction: Float, startValue: ScaledPoint, endValue: ScaledPoint -> - startValue + (endValue - startValue) * fraction - } - /** * Builds and applies the given [MatrixUpdate] by calling [applyUpdate] * repeatedly until the final position is reached, interpolating in the middle. @@ -330,18 +322,12 @@ internal class MatrixController( val holders = mutableListOf() if (update.pan != null) { val target = if (update.isPanRelative) pan + update.pan else update.pan - holders.add(PropertyValuesHolder.ofObject("pan", - absolutePointEvaluator, - pan, - target - )) + holders.add(PropertyValuesHolder.ofFloat("panX", panX, target.x)) + holders.add(PropertyValuesHolder.ofFloat("panY", panY, target.y)) } else if (update.scaledPan != null) { val target = if (update.isPanRelative) scaledPan + update.scaledPan else update.scaledPan - holders.add(PropertyValuesHolder.ofObject("pan", - scaledPointEvaluator, - scaledPan, - target - )) + holders.add(PropertyValuesHolder.ofFloat("panX", scaledPanX, target.x)) + holders.add(PropertyValuesHolder.ofFloat("panY", scaledPanY, target.y)) } if (update.hasZoom) { var newZoom = if (update.isZoomRelative) zoom * update.zoom else update.zoom @@ -360,11 +346,13 @@ internal class MatrixController( zoomTo(newZoom, update.canOverZoom) } if (update.pan != null) { - val newPan = it.getAnimatedValue("pan") as AbsolutePoint - panTo(newPan, update.canOverPan) + val newPanX = it.getAnimatedValue("panX") as Float + val newPanY = it.getAnimatedValue("panY") as Float + panTo(AbsolutePoint(newPanX, newPanY), update.canOverPan) } else if (update.scaledPan != null) { - val newPan = it.getAnimatedValue("pan") as ScaledPoint - panTo(newPan, update.canOverPan) + val newPanX = it.getAnimatedValue("panX") as Float + val newPanY = it.getAnimatedValue("panY") as Float + panTo(ScaledPoint(newPanX, newPanY), update.canOverPan) } pivot(update.pivotX, update.pivotY) notify = update.notify From 654f613f4ec520056117c0a179d50a20d49c79ad Mon Sep 17 00:00:00 2001 From: Markus Ressel Date: Thu, 5 Nov 2020 00:09:42 +0100 Subject: [PATCH 2/2] Added comment --- .../otaliastudios/zoom/internal/matrix/MatrixController.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/library/src/main/java/com/otaliastudios/zoom/internal/matrix/MatrixController.kt b/library/src/main/java/com/otaliastudios/zoom/internal/matrix/MatrixController.kt index d81b660..d1c1251 100644 --- a/library/src/main/java/com/otaliastudios/zoom/internal/matrix/MatrixController.kt +++ b/library/src/main/java/com/otaliastudios/zoom/internal/matrix/MatrixController.kt @@ -322,10 +322,12 @@ internal class MatrixController( val holders = mutableListOf() if (update.pan != null) { val target = if (update.isPanRelative) pan + update.pan else update.pan + // ofObject doesn't respect animator.interpolator, so we use ofFloat instead holders.add(PropertyValuesHolder.ofFloat("panX", panX, target.x)) holders.add(PropertyValuesHolder.ofFloat("panY", panY, target.y)) } else if (update.scaledPan != null) { val target = if (update.isPanRelative) scaledPan + update.scaledPan else update.scaledPan + // ofObject doesn't respect animator.interpolator, so we use ofFloat instead holders.add(PropertyValuesHolder.ofFloat("panX", scaledPanX, target.x)) holders.add(PropertyValuesHolder.ofFloat("panY", scaledPanY, target.y)) } @@ -369,4 +371,4 @@ internal class MatrixController( // TODO Make public, add API. Use androidx.Interpolator? private val ANIMATION_INTERPOLATOR = AccelerateDecelerateInterpolator() } -} \ No newline at end of file +}