From c43446247b4355ae50dfef6b489afc66cbefffb4 Mon Sep 17 00:00:00 2001 From: Nishant Karajgikar Date: Fri, 23 Apr 2021 11:00:38 -0400 Subject: [PATCH] Review comments --- .../MapboxMaps/Foundation/BaseMapView.swift | 2 +- .../Camera/BasicCameraAnimator.swift | 19 +++++++------------ .../Foundation/Camera/CameraManager.swift | 4 ++-- 3 files changed, 10 insertions(+), 15 deletions(-) diff --git a/Sources/MapboxMaps/Foundation/BaseMapView.swift b/Sources/MapboxMaps/Foundation/BaseMapView.swift index d4a4418faf3..170227d8793 100644 --- a/Sources/MapboxMaps/Foundation/BaseMapView.swift +++ b/Sources/MapboxMaps/Foundation/BaseMapView.swift @@ -35,7 +35,7 @@ open class BaseMapView: UIView { /// List of animators currently alive public var cameraAnimators: [CameraAnimator] { - return cameraAnimatorsHashTable.allObjects.compactMap { $0 as? CameraAnimator } + return cameraAnimatorsHashTable.allObjects } /// Map of event types to subscribed event handlers diff --git a/Sources/MapboxMaps/Foundation/Camera/BasicCameraAnimator.swift b/Sources/MapboxMaps/Foundation/Camera/BasicCameraAnimator.swift index 86d950bb678..ceb315dd93f 100644 --- a/Sources/MapboxMaps/Foundation/Camera/BasicCameraAnimator.swift +++ b/Sources/MapboxMaps/Foundation/Camera/BasicCameraAnimator.swift @@ -11,31 +11,27 @@ import CoreLocation } /// Internal-facing protocol to represent camera animators -@objc internal protocol CameraAnimatorInterface: AnyObject { +@objc internal protocol CameraAnimatorInterface: CameraAnimator { func update() - - func stopAnimation() - - var state: UIViewAnimatingState { get } } // MARK: CameraAnimator Class public class BasicCameraAnimator: NSObject, CameraAnimator, CameraAnimatorInterface { /// Instance of the property animator that will run animations. - internal private(set) var propertyAnimator: UIViewPropertyAnimator + private let propertyAnimator: UIViewPropertyAnimator /// Delegate that conforms to `CameraAnimatorDelegate`. internal private(set) weak var delegate: CameraAnimatorDelegate? /// The ID of the owner of this `CameraAnimator`. - public private(set) var owner: AnimationOwner + private let owner: AnimationOwner /// The `CameraView` owned by this animator - private var cameraView: CameraView + private let cameraView: CameraView /// Represents the animation that this animator is attempting to execute - internal private(set) var animation: ((inout CameraTransition) -> Void)? + private var animation: ((inout CameraTransition) -> Void)? /// Defines the transition that will occur to the `CameraOptions` of the renderer due to this animator public private(set) var transition: CameraTransition? @@ -79,6 +75,7 @@ public class BasicCameraAnimator: NSObject, CameraAnimator, CameraAnimatorInterf propertyAnimator.stopAnimation(false) propertyAnimator.finishAnimation(at: .current) cameraView.removeFromSuperview() + delayedAnimationTimer?.invalidate() } /// Starts the animation if this animator is in `inactive` state. Also used to resume a "paused" animation. @@ -116,9 +113,7 @@ public class BasicCameraAnimator: NSObject, CameraAnimator, CameraAnimatorInterf /// - Parameter delay: Delay (in seconds) after which the animation should start public func startAnimation(afterDelay delay: TimeInterval) { delayedAnimationTimer = Timer.scheduledTimer(withTimeInterval: delay, repeats: false, block: { [weak self] (timer) in - guard let self = self else { return } - self.startAnimation() - timer.invalidate() + self?.startAnimation() }) } diff --git a/Sources/MapboxMaps/Foundation/Camera/CameraManager.swift b/Sources/MapboxMaps/Foundation/Camera/CameraManager.swift index dafe6d7131e..9c5569793bf 100644 --- a/Sources/MapboxMaps/Foundation/Camera/CameraManager.swift +++ b/Sources/MapboxMaps/Foundation/Camera/CameraManager.swift @@ -266,9 +266,9 @@ public class CameraManager { } // Nil out the `internalAnimator` once the "ease to" finishes - animator.addCompletion { [weak self] (_) in + animator.addCompletion { [weak self] (position) in self?.internalAnimator = nil - animator.addCompletion(completion) + completion?(position) } animator.startAnimation()