Skip to content

Commit

Permalink
Lock out animations during any touch events (#712)
Browse files Browse the repository at this point in the history
* Removes CameraAnimationsManager.options
* Transfers comments from internal protocols
* Renames setCameraBounds(for:) to setCameraBounds(with:)
* Exposes BasicCameraAnimator.isReversed setter
  • Loading branch information
macdrevx committed Sep 29, 2021
1 parent 522e3c0 commit 167cc03
Show file tree
Hide file tree
Showing 51 changed files with 798 additions and 674 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
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ Mapbox welcomes participation and contributions from everyone.
* `public func layerProperty(for layerId: String, property: String) -> Any` has been renamed to `public func layerPropertyValue(for layerId: String, property: String) -> Any` to avoid ambiguity. ([#708](https://github.com/mapbox/mapbox-maps-ios/pull/708))
* `MapboxCommon.Geometry` extension methods are now marked as internal. ([#683](https://github.com/mapbox/mapbox-maps-ios/pull/683))
* `TileRegionLoadOptions` init now takes a `Geometry` instead of a `MapboxCommon.Geometry`. ([#711](https://github.com/mapbox/mapbox-maps-ios/pull/711))
* `CameraAnimationsManager.options` has been removed. Use `MapboxMap.cameraBounds` and `MapboxMap.setCameraBounds(with:)` instead. ([#712](https://github.com/mapbox/mapbox-maps-ios/pull/712))
* `MapboxMap.setCameraBounds(for:)` has been renamed to `.setCameraBounds(with:)` ([#712](https://github.com/mapbox/mapbox-maps-ios/pull/712))

### Features ✨ and improvements 🏁

Expand All @@ -27,6 +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))
* `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 Expand Up @@ -59,7 +64,6 @@ Mapbox welcomes participation and contributions from everyone.
* `GestureManagerDelegate.gestureBegan(for:)` has been renamed to `GestureManagerDelegate.gestureManager(_:didBegin:)`. ([#697](https://github.com/mapbox/mapbox-maps-ios/pull/697))
* Added the public delegate methods `GestureManagerDelegate.gestureManager(_:didEnd:willAnimate:)` and `GestureManagerDelegate.gestureManager(_:didEndAnimatingFor:)`. ([#697](https://github.com/mapbox/mapbox-maps-ios/pull/697))


### Features ✨ and improvements 🏁

* Allow users to set the map's `MapDebugOptions`. ([#648](https://github.com/mapbox/mapbox-maps-ios/pull/648))
Expand Down
13 changes: 10 additions & 3 deletions Sources/MapboxMaps/Foundation/Camera/BasicCameraAnimator.swift
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 @@ -226,8 +229,12 @@ public class BasicCameraAnimator: NSObject, CameraAnimator, CameraAnimatorInterf
propertyAnimator.addCompletion { [weak self] (animatingPosition) in
guard let self = self else { return }
self.internalState = .final
let finalCamera = self.cameraOptions(with: transition, cameraViewCameraOptions: self.cameraView.cameraOptions)
self.mapboxMap.setCamera(to: finalCamera)
// if the animation was stopped/canceled before finishing,
// do not update the camera again.
if animatingPosition != .current {
let finalCamera = self.cameraOptions(with: transition, cameraViewCameraOptions: self.cameraView.cameraOptions)
self.mapboxMap.setCamera(to: finalCamera)
}
for completion in self.completions {
completion(animatingPosition)
}
Expand Down
20 changes: 10 additions & 10 deletions Sources/MapboxMaps/Foundation/Camera/CameraAnimationsManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,13 @@ internal protocol CameraAnimationsManagerProtocol: AnyObject {
completion: @escaping () -> Void)

func cancelAnimations()

var animationsEnabled: Bool { get set }
}

/// An object that manages a camera's view lifecycle.
public class CameraAnimationsManager: CameraAnimationsManagerProtocol {

/// Used to set up camera specific configuration
public var options: CameraBoundsOptions {
didSet {
try? mapboxMap.setCameraBounds(for: options)
}
}

/// List of animators currently alive
public var cameraAnimators: [CameraAnimator] {
return cameraAnimatorsSet.allObjects
Expand All @@ -55,17 +50,22 @@ public class CameraAnimationsManager: CameraAnimationsManagerProtocol {
/// May want to convert to an enum.
fileprivate let northBearing: CGFloat = 0

internal var animationsEnabled: Bool = true

private let cameraViewContainerView: UIView

private let mapboxMap: MapboxMap
private let mapboxMap: MapboxMapProtocol

internal init(cameraViewContainerView: UIView, mapboxMap: MapboxMap) {
internal init(cameraViewContainerView: UIView, mapboxMap: MapboxMapProtocol) {
self.cameraViewContainerView = cameraViewContainerView
self.mapboxMap = mapboxMap
self.options = CameraBoundsOptions(cameraBounds: mapboxMap.cameraBounds)
}

internal func update() {
guard animationsEnabled else {
cancelAnimations()
return
}
for animator in cameraAnimatorsSet.allObjects {
animator.update()
}
Expand Down
180 changes: 0 additions & 180 deletions Sources/MapboxMaps/Foundation/CameraManagerProtocol.swift

This file was deleted.

Loading

0 comments on commit 167cc03

Please sign in to comment.