Skip to content

Commit 5c9ce70

Browse files
OdNairymaios
andauthored
Option to disable resizing animation (#2374)
Co-authored-by: Mai Mai <[email protected]>
1 parent 997c751 commit 5c9ce70

File tree

3 files changed

+94
-0
lines changed

3 files changed

+94
-0
lines changed

Apps/Examples/Examples/All Examples/Lab/ResizeMapViewExample.swift

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,15 @@ final class ResizeMapViewExample: UIViewController, ExampleProtocol {
3636

3737
setupDefaultCamera()
3838
applyAutolayout()
39+
40+
let animationBehaviourButton = UIBarButtonItem(
41+
title: nil,
42+
style: .done,
43+
target: self,
44+
action: #selector(toggleAnimationBehaviour(_:))
45+
)
46+
navigationItem.rightBarButtonItem = animationBehaviourButton
47+
syncAnimationBehaviourButton(animationBehaviourButton)
3948
}
4049

4150
func mapStyleDidLoad() {
@@ -128,6 +137,39 @@ final class ResizeMapViewExample: UIViewController, ExampleProtocol {
128137
lastManualResizingDirection.toggle()
129138
}
130139

140+
var animationBehaviour: MapView.ResizingAnimation = .automatic {
141+
didSet {
142+
mapboxMapView.resizingAnimation = animationBehaviour
143+
}
144+
}
145+
146+
@objc
147+
private func toggleAnimationBehaviour(_ sender: UIBarButtonItem) {
148+
switch animationBehaviour {
149+
case .automatic:
150+
animationBehaviour = .none
151+
case .none:
152+
animationBehaviour = .automatic
153+
}
154+
155+
syncAnimationBehaviourButton(sender)
156+
}
157+
158+
private func syncAnimationBehaviourButton(_ button: UIBarButtonItem) {
159+
switch animationBehaviour {
160+
case .automatic:
161+
if #available(iOS 13.0, *) {
162+
button.image = UIImage(systemName: "arrow.up.arrow.down.circle.fill")
163+
}
164+
button.title = "Automatic"
165+
case .none:
166+
if #available(iOS 13.0, *) {
167+
button.image = UIImage(systemName: "arrow.up.arrow.down.circle")
168+
}
169+
button.title = "None"
170+
}
171+
}
172+
131173
// MARK: -
132174

133175
func setupDefaultCamera() {

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
Mapbox welcomes participation and contributions from everyone.
44

5+
## main
6+
7+
* Add a new API to disable custom resizing implementation of the MapView. To disable the custom resizing implementation, set `MapView.resizingAnimation` to `.none`.
8+
59
## 11.9.0-beta.1
610

711
⚠️⚠️⚠️ Potentially breaking changes ⚠️⚠️⚠️

Sources/MapboxMaps/Foundation/MapView.swift

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,8 +565,52 @@ open class MapView: UIView, SizeTrackingLayerDelegate {
565565

566566
metalView?.center = CGPoint(x: bounds.midX, y: bounds.midY)
567567
safeAreaSignalSubject.value = self.safeAreaInsets
568+
569+
if let metalView, metalView.autoResizeDrawable {
570+
metalView.frame = bounds
571+
mapboxMap.size = metalView.bounds.size
572+
}
568573
}
569574

575+
#if !os(visionOS)
576+
/// Control the resizing animation behavior of the map view.
577+
/// The default value is ``ResizingAnimation-swift.enum/automatic``.
578+
public enum ResizingAnimation {
579+
/// Change the default behaviour to have a nice looking resizing animation.
580+
///
581+
/// The map plane would fulfil the MapView sized all the time.
582+
/// Custom implementation.
583+
case automatic
584+
585+
/// Default UIView behaviour. The map plane would be resized immediately leading to gaps renderer when assign higher size values.
586+
case none
587+
588+
init?(autoResizeDrawable: Bool?) {
589+
guard let autoResizeDrawable else { return nil }
590+
self = autoResizeDrawable ? .none : .automatic
591+
}
592+
593+
var autoResizeDrawable: Bool {
594+
switch self {
595+
case .automatic: return false
596+
case .none: return true
597+
}
598+
}
599+
}
600+
601+
/// Control resizing animation behavior of the map view.
602+
public var resizingAnimation: ResizingAnimation = .automatic {
603+
didSet {
604+
syncResizingAnimation()
605+
}
606+
}
607+
608+
private func syncResizingAnimation() {
609+
// VisionOS doesn't support autoResizeDrawable
610+
metalView?.autoResizeDrawable = resizingAnimation.autoResizeDrawable
611+
}
612+
#endif
613+
570614
/// Synchronize size updates with GL-Native and UIKit
571615
///
572616
/// To provide nice custom resizing behavior SDK rely on custom `drawableSize` updates
@@ -740,6 +784,10 @@ extension MapView: DelegatingMapClientDelegate {
740784

741785
self.metalView = metalView
742786

787+
#if !os(visionOS)
788+
syncResizingAnimation()
789+
#endif
790+
743791
return metalView
744792
}
745793
}

0 commit comments

Comments
 (0)