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

[animation] Delete anchor animator and make it animator property #108

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
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 @@ -155,7 +155,6 @@ internal class CameraAnimationsPluginImpl : CameraAnimationsPlugin {
val startValue = cameraAnimator.startValue ?: when (cameraAnimator.type) {
CameraAnimatorType.CENTER -> mapCameraDelegate.getCameraOptions().center
CameraAnimatorType.ZOOM -> mapCameraDelegate.getCameraOptions().zoom
CameraAnimatorType.ANCHOR -> cameraAnimator.startValue
CameraAnimatorType.PADDING -> mapCameraDelegate.getCameraOptions().padding
CameraAnimatorType.BEARING -> mapCameraDelegate.getCameraOptions().bearing
CameraAnimatorType.PITCH -> mapCameraDelegate.getCameraOptions().pitch
Expand Down Expand Up @@ -204,7 +203,6 @@ internal class CameraAnimationsPluginImpl : CameraAnimationsPlugin {
when (cameraAnimator) {
is CameraCenterAnimator -> cameraOptionsBuilder.center(cameraAnimator.animatedValue as? Point)
is CameraZoomAnimator -> cameraOptionsBuilder.zoom(cameraAnimator.animatedValue as? Double)
is CameraAnchorAnimator -> cameraOptionsBuilder.anchor(cameraAnimator.animatedValue as? ScreenCoordinate)
is CameraPaddingAnimator -> cameraOptionsBuilder.padding(cameraAnimator.animatedValue as? EdgeInsets)
is CameraBearingAnimator -> cameraOptionsBuilder.bearing(cameraAnimator.animatedValue as? Double)
is CameraPitchAnimator -> cameraOptionsBuilder.pitch(cameraAnimator.animatedValue as? Double)
Expand Down Expand Up @@ -278,6 +276,9 @@ internal class CameraAnimationsPluginImpl : CameraAnimationsPlugin {
unregisterAnimators(this, cancelAnimators = false)
}
if (runningAnimatorsQueue.isEmpty()) {
anchor?.let {
cameraOptionsBuilder.anchor(it)
}
performMapJump(cameraOptionsBuilder.build())
mapTransformDelegate.setUserAnimationInProgress(false)
}
Expand Down Expand Up @@ -313,6 +314,10 @@ internal class CameraAnimationsPluginImpl : CameraAnimationsPlugin {
}
}
cameraOptions?.let { camera ->
// add anchor if was specified for given animator
animator.anchor?.let { anchor ->
camera.anchor = anchor
}
// move map camera
performMapJump(camera)
// reset values
Expand Down Expand Up @@ -704,11 +709,6 @@ internal class CameraAnimationsPluginImpl : CameraAnimationsPlugin {
block: (ValueAnimator.() -> Unit)?
) = CameraZoomAnimator(options, block)

override fun createAnchorAnimator(
options: CameraAnimatorOptions<ScreenCoordinate>,
block: (ValueAnimator.() -> Unit)?
) = CameraAnchorAnimator(options, block)

override fun createBearingAnimator(
options: CameraAnimatorOptions<Double>,
block: (ValueAnimator.() -> Unit)?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,6 @@ class CameraAnimatorsFactory internal constructor(mapDelegateProvider: MapDelega
val animationList = mutableListOf<ValueAnimator>()
val currentCameraOptions = mapCameraDelegate.getCameraOptions()

cameraOptions.anchor?.let {
animationList.add(
CameraAnchorAnimator(
options = cameraAnimatorOptions(it) {
startValue = it
},
block = defaultAnimationParameters[CameraAnimatorType.ANCHOR]
)
)
}
cameraOptions.bearing?.let {
var startBearing = currentCameraOptions.bearing ?: it
var endBearing = it
Expand All @@ -65,6 +55,7 @@ class CameraAnimatorsFactory internal constructor(mapDelegateProvider: MapDelega
CameraBearingAnimator(
options = cameraAnimatorOptions(endBearing) {
startValue = startBearing
anchor = cameraOptions.anchor
},
block = defaultAnimationParameters[CameraAnimatorType.BEARING]
)
Expand All @@ -76,6 +67,7 @@ class CameraAnimatorsFactory internal constructor(mapDelegateProvider: MapDelega
CameraPaddingAnimator(
options = cameraAnimatorOptions(target) {
startValue = start
anchor = cameraOptions.anchor
},
block = defaultAnimationParameters[CameraAnimatorType.PADDING]
)
Expand All @@ -89,6 +81,7 @@ class CameraAnimatorsFactory internal constructor(mapDelegateProvider: MapDelega
CameraPitchAnimator(
options = cameraAnimatorOptions(target) {
startValue = start
anchor = cameraOptions.anchor
},
block = defaultAnimationParameters[CameraAnimatorType.PITCH]
)
Expand All @@ -102,6 +95,7 @@ class CameraAnimatorsFactory internal constructor(mapDelegateProvider: MapDelega
CameraCenterAnimator(
options = cameraAnimatorOptions(target) {
startValue = start
anchor = cameraOptions.anchor
},
block = defaultAnimationParameters[CameraAnimatorType.CENTER]
)
Expand All @@ -115,6 +109,7 @@ class CameraAnimatorsFactory internal constructor(mapDelegateProvider: MapDelega
CameraZoomAnimator(
options = cameraAnimatorOptions(target) {
startValue = start
anchor = cameraOptions.anchor
},
block = defaultAnimationParameters[CameraAnimatorType.ZOOM]
)
Expand Down Expand Up @@ -150,28 +145,19 @@ class CameraAnimatorsFactory internal constructor(mapDelegateProvider: MapDelega
* Add scale value to current camera scale
*
* @param amount The amount to scale by
* @param anchor The optional focal point to scale on
* @param scaleAnchor The optional focal point to scale on
* @return Array of the created animators
*/
internal fun getScaleBy(amount: Double, anchor: ScreenCoordinate? = null): Array<CameraAnimator<*>> {
internal fun getScaleBy(amount: Double, scaleAnchor: ScreenCoordinate? = null): Array<CameraAnimator<*>> {
val animationList = mutableListOf<ValueAnimator>()
anchor?.let {
animationList.add(
CameraAnchorAnimator(
options = cameraAnimatorOptions(it) {
startValue = it
},
block = defaultAnimationParameters[CameraAnimatorType.ANCHOR]
)
)
}
val currentZoom = mapCameraDelegate.getCameraOptions().zoom
currentZoom?.let {
val newScale = CameraTransform.calculateScaleBy(amount, currentZoom)
animationList.add(
CameraZoomAnimator(
options = cameraAnimatorOptions(newScale) {
startValue = currentZoom
anchor = scaleAnchor
},
block = defaultAnimationParameters[CameraAnimatorType.ZOOM]
)
Expand All @@ -198,15 +184,13 @@ class CameraAnimatorsFactory internal constructor(mapDelegateProvider: MapDelega
mapProjectionDelegate
)
cameraOptions.center?.let { start ->
centerTarget?.let { target ->
return Array(1) {
CameraCenterAnimator(
options = cameraAnimatorOptions(target) {
startValue = start
},
block = defaultAnimationParameters[CameraAnimatorType.CENTER]
)
}
return Array(1) {
CameraCenterAnimator(
options = cameraAnimatorOptions(centerTarget) {
startValue = start
},
block = defaultAnimationParameters[CameraAnimatorType.CENTER]
)
}
}
return emptyArray()
Expand Down Expand Up @@ -463,10 +447,6 @@ class CameraAnimatorsFactory internal constructor(mapDelegateProvider: MapDelega

private val defaultAnimationParameters =
hashMapOf<CameraAnimatorType, ValueAnimator.() -> Unit>().apply {
put(CameraAnimatorType.ANCHOR) {
duration = DEFAULT_ANIMATION_DURATION_MS
interpolator = DEFAULT_INTERPOLATOR
}
put(CameraAnimatorType.BEARING) {
duration = DEFAULT_ANIMATION_DURATION_MS
interpolator = DEFAULT_INTERPOLATOR
Expand Down Expand Up @@ -513,7 +493,6 @@ class CameraAnimatorsFactory internal constructor(mapDelegateProvider: MapDelega
defaultAnimationParameters[CameraAnimatorType.ZOOM] = block
defaultAnimationParameters[CameraAnimatorType.BEARING] = block
defaultAnimationParameters[CameraAnimatorType.PITCH] = block
defaultAnimationParameters[CameraAnimatorType.ANCHOR] = block
defaultAnimationParameters[CameraAnimatorType.PADDING] = block
}
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ abstract class CameraAnimator<out T> (
* Start animation value, will use current map value option from [CameraOptions] if null.
*/
val startValue = cameraAnimatorOptions.startValue

/**
* Anchor to be used with current animator.
*/
val anchor = cameraAnimatorOptions.anchor
/**
* Sets the values to animate between for this animation (except start value).
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package com.mapbox.maps.plugin.animation.animator
import android.animation.TypeEvaluator
import com.mapbox.geojson.Point
import com.mapbox.maps.EdgeInsets
import com.mapbox.maps.ScreenCoordinate

/**
* Contains custom animator evaluators related to animating camera properties
Expand Down Expand Up @@ -39,16 +38,6 @@ object Evaluators {
)
}

/**
* Type evaluator for ScreenCoordinate data
*/
val SCREEN_COORDINATE = TypeEvaluator<ScreenCoordinate> { fraction, startValue, endValue ->
ScreenCoordinate(
startValue.x + fraction * (endValue.x - startValue.x),
startValue.y + fraction * (endValue.y - startValue.y)
)
}

/**
* Type evaluator for Object data
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,9 @@ import com.mapbox.maps.CameraOptions
import com.mapbox.maps.ScreenCoordinate
import com.mapbox.maps.plugin.InvalidPluginConfigurationException
import com.mapbox.maps.plugin.PLUGIN_CAMERA_ANIMATIONS_CLASS_NAME
import com.mapbox.maps.plugin.animation.CameraAnimationsPlugin
import com.mapbox.maps.plugin.animation.CameraAnimatorOptions
import com.mapbox.maps.plugin.animation.*
import com.mapbox.maps.plugin.animation.CameraAnimatorOptions.Companion.cameraAnimatorOptions
import com.mapbox.maps.plugin.animation.MapAnimationOptions
import com.mapbox.maps.plugin.animation.MapAnimationOptions.Companion.mapAnimationOptions
import com.mapbox.maps.plugin.animation.MapAnimationOwnerRegistry
import com.mapbox.maps.plugin.delegates.*
import com.mapbox.maps.plugin.gestures.generated.GesturesAttributeParser
import com.mapbox.maps.plugin.gestures.generated.GesturesSettings
Expand Down Expand Up @@ -525,8 +522,7 @@ class GesturesPluginImpl : GesturesPlugin, GesturesSettingsBase {
) * SCALE_VELOCITY_ANIMATION_DURATION_MULTIPLIER
).toLong()
currentZoom?.let {
val animators =
createScaleAnimators(it, zoomAddition, focalPoint, animationTime)
val animators = createScaleAnimator(it, zoomAddition, focalPoint, animationTime)
scaleAnimators = animators
scheduleAnimators(animators)
}
Expand Down Expand Up @@ -685,7 +681,7 @@ class GesturesPluginImpl : GesturesPlugin, GesturesSettingsBase {
return ScreenCoordinate(pointF.x.toDouble(), pointF.y.toDouble())
}

private fun createRotateAnimators(
private fun createRotateAnimator(
angularVelocity: Float,
animationTime: Long,
animationFocalPoint: ScreenCoordinate
Expand All @@ -706,21 +702,12 @@ class GesturesPluginImpl : GesturesPlugin, GesturesSettingsBase {
val bearingCurrent = mapTransformDelegate.getCameraOptions(null).bearing ?: return arrayOf()
val bearingTarget = bearingCurrent + bearingDistance

val screenCoordinate = ScreenCoordinate(animationFocalPoint.x, animationFocalPoint.y)
val bearingAnimator = cameraAnimationsPlugin.createBearingAnimator(
options = cameraAnimatorOptions(bearingTarget) {
owner = MapAnimationOwnerRegistry.GESTURES
startValue = bearingCurrent
},
) {
interpolator = rotateInterpolator
duration = animationTime
}

val screenCoordinate = ScreenCoordinate(animationFocalPoint.x, animationFocalPoint.y)
val anchorAnimator = cameraAnimationsPlugin.createAnchorAnimator(
options = cameraAnimatorOptions(screenCoordinate) {
owner = MapAnimationOwnerRegistry.GESTURES
startValue = screenCoordinate
anchor = screenCoordinate
},
) {
interpolator = rotateInterpolator
Expand All @@ -736,7 +723,7 @@ class GesturesPluginImpl : GesturesPlugin, GesturesSettingsBase {
}
}
}
return arrayOf(bearingAnimator, anchorAnimator)
return arrayOf(bearingAnimator)
}

internal fun handleRotateEnd(
Expand Down Expand Up @@ -780,7 +767,7 @@ class GesturesPluginImpl : GesturesPlugin, GesturesSettingsBase {
).toLong()

val focalPoint = getRotateFocalPoint(detector)
rotateAnimators = createRotateAnimators(angularVelocity, animationTime, focalPoint)
rotateAnimators = createRotateAnimator(angularVelocity, animationTime, focalPoint)
scheduleAnimators(rotateAnimators)
}

Expand Down Expand Up @@ -960,7 +947,7 @@ class GesturesPluginImpl : GesturesPlugin, GesturesSettingsBase {
}
}

private fun createScaleAnimators(
private fun createScaleAnimator(
currentZoom: Double,
zoomAddition: Double,
animationFocalPoint: ScreenCoordinate,
Expand All @@ -972,22 +959,13 @@ class GesturesPluginImpl : GesturesPlugin, GesturesSettingsBase {
options = cameraAnimatorOptions(currentZoom + zoomAddition) {
owner = MapAnimationOwnerRegistry.GESTURES
startValue = currentZoom
anchor = animationFocalPoint
}
) {
interpolator = scaleInterpolator
duration = animationTime
}

val anchorAnimator = cameraAnimationsPlugin.createAnchorAnimator(
options = cameraAnimatorOptions(animationFocalPoint) {
owner = MapAnimationOwnerRegistry.GESTURES
startValue = animationFocalPoint
},
) {
interpolator = scaleInterpolator
duration = animationTime
}

zoomAnimator.addListener(object : AnimatorListenerAdapter() {

override fun onAnimationStart(animation: Animator) {}
Expand All @@ -998,7 +976,7 @@ class GesturesPluginImpl : GesturesPlugin, GesturesSettingsBase {
dispatchCameraIdle()
}
})
return arrayOf(zoomAnimator, anchorAnimator)
return arrayOf(zoomAnimator)
}

/**
Expand Down Expand Up @@ -1033,7 +1011,7 @@ class GesturesPluginImpl : GesturesPlugin, GesturesSettingsBase {

val currentZoom = mapTransformDelegate.getCameraOptions(null).zoom
currentZoom?.let {
val animators = createScaleAnimators(
val animators = createScaleAnimator(
currentZoom,
(if (zoomIn) 1 else -1).toDouble(),
zoomFocalPoint,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,17 +101,6 @@ interface CameraAnimationsPlugin : MapPlugin {
block: (ValueAnimator.() -> Unit)? = null
): ValueAnimator

/**
* Create CameraAnchorAnimator
*
* @param options animator options object to set targets and other non mandatory options
* @param block optional block to apply any [ValueAnimator] parameters
*/
fun createAnchorAnimator(
options: CameraAnimatorOptions<ScreenCoordinate>,
block: (ValueAnimator.() -> Unit)? = null
): ValueAnimator

/**
* Create CameraBearingAnimator. Current map camera option will be applied on animation start.
*
Expand Down
Loading