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

Less jiggly animation on moveTo #189

Merged
merged 2 commits into from
Nov 4, 2020
Merged
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -330,18 +322,14 @@ internal class MatrixController(
val holders = mutableListOf<PropertyValuesHolder>()
if (update.pan != null) {
val target = if (update.isPanRelative) pan + update.pan else update.pan
holders.add(PropertyValuesHolder.ofObject("pan",
absolutePointEvaluator,
pan,
target
))
// 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
holders.add(PropertyValuesHolder.ofObject("pan",
scaledPointEvaluator,
scaledPan,
target
))
// 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))
}
if (update.hasZoom) {
var newZoom = if (update.isZoomRelative) zoom * update.zoom else update.zoom
Expand All @@ -360,11 +348,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
Expand All @@ -381,4 +371,4 @@ internal class MatrixController(
// TODO Make public, add API. Use androidx.Interpolator?
private val ANIMATION_INTERPOLATOR = AccelerateDecelerateInterpolator()
}
}
}