Skip to content

Commit

Permalink
Expose isReversed setter, add test, update animator logic
Browse files Browse the repository at this point in the history
  • Loading branch information
macdrevx committed Sep 29, 2021
1 parent 5fab12c commit 85e9001
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ class AnimateImageLayerExample: UIViewController, ExampleProtocol {
mapView.tintColor = .lightGray

// Set the map's `CameraBoundsOptions` to limit the map's zoom level.
mapView.camera.options.maxZoom = 5.99
mapView.camera.options.minZoom = 4
try? mapView.mapboxMap.setCameraBounds(with: CameraBoundsOptions(maxZoom: 5.99, minZoom: 4))

view.addSubview(mapView)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ import MapboxMaps
import MapboxCoreMaps

@objc(RestrictCoordinateBoundsExample)
final class RestrictCoordinateBoundsExample: UIViewController, ExampleProtocol {

public class RestrictCoordinateBoundsExample: UIViewController, ExampleProtocol {

override public func viewDidLoad() {
override func viewDidLoad() {
super.viewDidLoad()

let mapView = MapView(frame: view.bounds)
Expand All @@ -17,7 +16,7 @@ public class RestrictCoordinateBoundsExample: UIViewController, ExampleProtocol
northeast: CLLocationCoordinate2D(latitude: 66.61, longitude: -13.47))

// Restrict the camera to `bounds`.
mapView.camera.options = CameraBoundsOptions(bounds: bounds)
try? mapView.mapboxMap.setCameraBounds(with: CameraBoundsOptions(bounds: bounds))

// Center the camera on the bounds
let camera = mapView.mapboxMap.camera(for: bounds, padding: .zero, bearing: 0, pitch: 0)
Expand All @@ -26,7 +25,7 @@ public class RestrictCoordinateBoundsExample: UIViewController, ExampleProtocol
mapView.mapboxMap.setCamera(to: camera)
}

override public func viewDidAppear(_ animated: Bool) {
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
// The below line is used for internal testing purposes only.
finish()
Expand Down
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ Mapbox welcomes participation and contributions from everyone.
* Adds `FeatureExtensionValue.features: [Feature]?` that works with Turf. ([#717](https://github.com/mapbox/mapbox-maps-ios/pull/717))
* APIs that accept Turf `Feature` now allow `Feature.identifier` and `.properties` to be `nil`. ([#717](https://github.com/mapbox/mapbox-maps-ios/pull/717))
* APIs that accept Turf `Feature` now ignore `Feature.properties` instead of crashing if it cannot be converted to `[String: NSObject]`. ([#717](https://github.com/mapbox/mapbox-maps-ios/pull/717))
* Any touch event in the map now immedately disables camera animation. Temporarily disable user interaction on the MapView to disable this behavior as needed. ([#712](https://github.com/mapbox/mapbox-maps-ios/pull/712))
* BasicCameraAnimator no longer updates the camera a final time after being stopped or canceled prior to running to completion. ([#712](https://github.com/mapbox/mapbox-maps-ios/pull/712))
* Any touch event in the map now immedately disables camera animation. Temporarily disable user interaction on the `MapView` to disable this behavior as needed. ([#712](https://github.com/mapbox/mapbox-maps-ios/pull/712))
* `BasicCameraAnimator` no longer updates the camera a final time after being stopped or canceled prior to running to completion. ([#712](https://github.com/mapbox/mapbox-maps-ios/pull/712))
* `BasicCameraAnimator.isReversed` is now settable. ([#712](https://github.com/mapbox/mapbox-maps-ios/pull/712))

## 10.0.0-rc.9 - Sept 22, 2021

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ public class BasicCameraAnimator: NSObject, CameraAnimator, CameraAnimatorInterf
public var isRunning: Bool { propertyAnimator.isRunning }

/// Boolean that represents if the animation is running normally or in reverse.
public var isReversed: Bool { propertyAnimator.isReversed }
public var isReversed: Bool {
get { propertyAnimator.isReversed }
set { propertyAnimator.isReversed = newValue }
}

/// A Boolean value that indicates whether a completed animation remains in the active state.
public var pausesOnCompletion: Bool {
Expand Down Expand Up @@ -228,7 +231,7 @@ public class BasicCameraAnimator: NSObject, CameraAnimator, CameraAnimatorInterf
self.internalState = .final
// if the animation was stopped/canceled before finishing,
// do not update the camera again.
if animatingPosition == .end {
if animatingPosition != .current {
let finalCamera = self.cameraOptions(with: transition, cameraViewCameraOptions: self.cameraView.cameraOptions)
self.mapboxMap.setCamera(to: finalCamera)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,16 @@ final class BasicCameraAnimatorTests: XCTestCase {
XCTAssertTrue(propertyAnimator.finishAnimationStub.invocations.isEmpty)
}

func testIsReversed() {
animator.isReversed = true

XCTAssertEqual(propertyAnimator.setIsReversedStub.parameters, [true])

animator.isReversed = false

XCTAssertEqual(propertyAnimator.setIsReversedStub.parameters, [true, false])
}

func testStartAndStopAnimation() {
animator.addAnimations { (transition) in
transition.zoom.toValue = cameraOptionsTestValue.zoom!
Expand All @@ -76,7 +86,7 @@ final class BasicCameraAnimatorTests: XCTestCase {
XCTAssertEqual(propertyAnimator.finishAnimationStub.invocations.first?.parameters, .current)
}

func testAnimatorCompletionUpdatesCameraIfAnimationEnded() throws {
func testAnimatorCompletionUpdatesCameraIfAnimationCompletedAtEnd() throws {
animator.addAnimations { (transition) in
transition.zoom.toValue = cameraOptionsTestValue.zoom!
}
Expand All @@ -88,7 +98,19 @@ final class BasicCameraAnimatorTests: XCTestCase {
XCTAssertEqual(mapboxMap.setCameraStub.invocations.count, 1)
}

func testAnimatorCompletionDoesNotUpdateCameraIfAnimationWasStopped() throws {
func testAnimatorCompletionUpdatesCameraIfAnimationCompletedAtStart() throws {
animator.addAnimations { (transition) in
transition.zoom.toValue = cameraOptionsTestValue.zoom!
}
animator.startAnimation()
let completion = try XCTUnwrap(propertyAnimator.addCompletionStub.parameters.first)

completion(.start)

XCTAssertEqual(mapboxMap.setCameraStub.invocations.count, 1)
}

func testAnimatorCompletionDoesNotUpdateCameraIfAnimationCompletedAtCurrent() throws {
animator.addAnimations { (transition) in
transition.zoom.toValue = cameraOptionsTestValue.zoom!
}
Expand Down
10 changes: 10 additions & 0 deletions Tests/MapboxMapsTests/Foundation/Camera/MockPropertyAnimator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@ import UIKit

final class MockPropertyAnimator: UIViewPropertyAnimator {

let setIsReversedStub = Stub<Bool, Void>()
override var isReversed: Bool {
get {
fatalError("unimplemented")
}
set {
setIsReversedStub.call(with: newValue)
}
}

let stateStub = Stub<Void, UIViewAnimatingState>(defaultReturnValue: .inactive)
override var state: UIViewAnimatingState {
stateStub.call()
Expand Down

0 comments on commit 85e9001

Please sign in to comment.