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

[Camera Animations] Introduce short-lived camera view #282

Merged
merged 40 commits into from
Apr 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
ea4aaaa
Introduce short-lived camera view; update flyTo for better performanc…
nishant-karajgikar Apr 20, 2021
372559d
Honor constant anchors in animated transitions
nishant-karajgikar Apr 21, 2021
506187e
Minor refactoring
nishant-karajgikar Apr 21, 2021
1e4caaf
fix lint
nishant-karajgikar Apr 21, 2021
23be375
Fix stresstest app
nishant-karajgikar Apr 21, 2021
5d05d6e
Expose animation owner on CameraAnimator
nishant-karajgikar Apr 21, 2021
89a4c12
Update changelog
nishant-karajgikar Apr 21, 2021
dc81f3a
cleanup
nishant-karajgikar Apr 21, 2021
329390a
Rename makeCameraAnimator* methods to makeAnimator* methods
nishant-karajgikar Apr 21, 2021
dffe75a
Nil out the internal animator when an animation completes
nishant-karajgikar Apr 21, 2021
5f600e5
fix lint
nishant-karajgikar Apr 22, 2021
be3b10f
Add CameraViewTests
nishant-karajgikar Apr 22, 2021
85c15e3
Add FlyToAnimatorTests [run device tests]
nishant-karajgikar Apr 22, 2021
b818b13
Remove unnecessary deinit
nishant-karajgikar Apr 22, 2021
2b06df5
Add files to MapboxMaps.xcworkspace [run device tests]
nishant-karajgikar Apr 22, 2021
c72c8ea
review comments
nishant-karajgikar Apr 22, 2021
490e25b
Fix issue where flyTo completion would not get called if flyToAnimato…
nishant-karajgikar Apr 22, 2021
ed68b5a
Clean up access specifiers
nishant-karajgikar Apr 22, 2021
60e2e7a
more review comments
nishant-karajgikar Apr 22, 2021
6bdc136
Make properties in FlyToAnimator internal private(set)
nishant-karajgikar Apr 22, 2021
875a536
Make optimizeBearing static function a computed var
nishant-karajgikar Apr 23, 2021
e740816
Convert constantAnchor to computed var
nishant-karajgikar Apr 23, 2021
38750e7
Fix cameraTransitionTests
nishant-karajgikar Apr 23, 2021
8a46d80
Use Timer to schedule a delayed start to an animation
nishant-karajgikar Apr 23, 2021
68356b8
Split CameraAnimatorProtocol into public facing and private facing pr…
nishant-karajgikar Apr 23, 2021
11b7055
Add docs for cancelAnimations
nishant-karajgikar Apr 23, 2021
2fb6a24
Make cameraView private
nishant-karajgikar Apr 23, 2021
a9105ad
Fix xcodeproj [run device tests]
nishant-karajgikar Apr 23, 2021
c3936e8
Reorder completion call
nishant-karajgikar Apr 23, 2021
c7959d1
Review comments
nishant-karajgikar Apr 23, 2021
a2e019b
Changes from refactoring flytoCameraAnimator + weakset introduction
nishant-karajgikar Apr 27, 2021
3befbf9
Review comments
nishant-karajgikar Apr 27, 2021
2900962
Fix optimizeBearing logic issue + remove constantAnchor for now
nishant-karajgikar Apr 27, 2021
62183b9
Cleanup
nishant-karajgikar Apr 27, 2021
df83e05
Remove Hashable conformances to UIKit types
nishant-karajgikar Apr 27, 2021
85ced78
fix lint
nishant-karajgikar Apr 27, 2021
15e900b
Put CameraAnimatorsWeakSet in separate file
nishant-karajgikar Apr 27, 2021
627d137
Move CameraAnimators computed var to CameraManager
nishant-karajgikar Apr 27, 2021
ef5a8ef
Add FlyToAnimatorTests
nishant-karajgikar Apr 27, 2021
73aaef2
Rename CameraManager -> CameraAnimationsManager [run device tests]
nishant-karajgikar Apr 27, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
33 changes: 21 additions & 12 deletions Apps/Examples/Examples/All Examples/CameraAnimatorsExample.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,39 @@ public class CameraAnimatorsExample: UIViewController, ExampleProtocol {

internal var mapView: MapView!

// Coordinate in New York City
let newYork = CLLocationCoordinate2D(latitude: 40.7128, longitude: -74.0060)

// Store the CameraAnimators so that the do not fall out of scope.
lazy var zoomAnimator: CameraAnimator = {
let animator = mapView.camera.makeCameraAnimator(duration: 4, curve: .easeInOut) { [unowned self] in
self.mapView.zoom = 14
lazy var zoomAnimator: BasicCameraAnimator = {
let animator = mapView.camera.makeAnimator(duration: 4, curve: .easeInOut) { (transition) in
transition.zoom.toValue = 14
}

animator.addCompletion { [unowned self] (_) in
print("Animating camera pitch from 0 degrees -> 55 degrees")
self.pitchAnimator.startAnimation()
}

return animator
}()

lazy var pitchAnimator: CameraAnimator = {
let animator = mapView.camera.makeCameraAnimator(duration: 2, curve: .easeInOut) { [unowned self] in
self.mapView.pitch = 55
lazy var pitchAnimator: BasicCameraAnimator = {
let animator = mapView.camera.makeAnimator(duration: 2, curve: .easeInOut) { (transition) in
transition.pitch.toValue = 55
}

animator.addCompletion { [unowned self] (_) in
print("Animating camera bearing from 0 degrees -> 45 degrees")
self.bearingAnimator.startAnimation()
}

return animator
}()

lazy var bearingAnimator: CameraAnimator = {
let animator = mapView.camera.makeCameraAnimator(duration: 4, curve: .easeInOut) { [unowned self] in
self.mapView.bearing = -45
lazy var bearingAnimator: BasicCameraAnimator = {
let animator = mapView.camera.makeAnimator(duration: 4, curve: .easeInOut) { (transition) in
transition.bearing.toValue = -45
}

animator.addCompletion { (_) in
Expand All @@ -51,13 +56,17 @@ public class CameraAnimatorsExample: UIViewController, ExampleProtocol {
mapView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
view.addSubview(mapView)

// Center the map over New York City.
let newYork = CLLocationCoordinate2D(latitude: 40.7128, longitude: -74.0060)
mapView.camera.setCamera(to: CameraOptions(center: newYork))
mapView.on(.styleLoaded) { [weak self] _ in
guard let self = self else { return }
// Center the map over New York City.
self.mapView.camera.setCamera(to: CameraOptions(center: self.newYork))
}
nishant-karajgikar marked this conversation as resolved.
Show resolved Hide resolved

// Allows the delegate to receive information about map events.
mapView.on(.mapLoaded) { [weak self] _ in
guard let self = self else { return }

print("Animating zoom from zoom lvl 3 -> zoom lvl 14")
self.zoomAnimator.startAnimation(afterDelay: 1)
self.finish()
}
Expand Down
4 changes: 1 addition & 3 deletions Apps/Examples/Examples/All Examples/FlyToExample.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import MapboxMaps
public class FlyToExample: UIViewController, ExampleProtocol {

internal var mapView: MapView!
internal var flyToAnimator: CameraAnimator?

override public func viewDidLoad() {
super.viewDidLoad()
Expand Down Expand Up @@ -35,10 +34,9 @@ public class FlyToExample: UIViewController, ExampleProtocol {
bearing: 180,
pitch: 50)

flyToAnimator = self.mapView.camera.fly(to: end) { [weak self] _ in
mapView.camera.fly(to: end) { [weak self] _ in
print("Camera fly-to finished")
// The below line is used for internal testing purposes only.
self?.flyToAnimator = nil
self?.finish()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ public class GeoJSONSourceExample: UIViewController, ExampleProtocol {
// Set the center coordinate and zoom level.
let centerCoordinate = CLLocationCoordinate2D(latitude: 18.239785,
longitude: -66.302490)
mapView.centerCoordinate = centerCoordinate
mapView.zoom = 6.9

mapView.camera.setCamera(to: CameraOptions(center: centerCoordinate,
zoom: 6.9))

// Allow the view controller to receive information about map events.
mapView.on(.mapLoaded) { [weak self] _ in
Expand Down
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ Mapbox welcomes participation and contributions from everyone.
* `Snapshotter` no longer conforms to `Observer`, and the method it required is now internal.
* The `BaseMapView.__map` property has been moved to `BaseMapView.mapboxMap.__map`. ([#280](https://github.com/mapbox/mapbox-maps-ios/pull/280))
* A `CameraOptions` struct has been introduced. This shadows the class of the same name from MapboxCoreMaps and. This avoids unintended sharing and better reflects the intended value semantics of the `CameraOptions` concept. ([#284](https://github.com/mapbox/mapbox-maps-ios/pull/284))

#### Camera Animations
* A new `CameraTransition` struct has been introduced to allow better control on the "from" and "to" values of a camera animation ([#282](https://github.com/mapbox/mapbox-maps-ios/pull/282))
* A mutable version of the `CameraTransition` struct is passed into every animation block.
* Animations can only be constructor injected into `CameraAnimator` as part of the `makeAnimator*` methods on `mapView.camera`.
* The `makeCameraAnimator*` methods have been renamed to `makeAnimator*` methods

#### Gestures
- Gestures now directly call `__map.setCamera()` instead of using CoreAnimation


- #### Dependencies
* Updated dependencies to MapboxCoreMaps 10.0.0-beta.20 and MapboxCommon 11.0.1
Expand Down