Skip to content

Commit de1b203

Browse files
OdNairypersidskiy
authored andcommitted
Support multiple resizing calls during the same animation (#2337)
1 parent 9cf7d74 commit de1b203

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ Mapbox welcomes participation and contributions from everyone.
44

55
## main
66

7+
* Fix the bug when MapView would ignore the new bounds size if there are more than a single resizing event in the animation.
8+
79
## 11.8.0-beta.1 - 14 October, 2024
810

911
* [SwiftUI] Fixed crash when ForEvery was used with duplicated IDs.

Sources/MapboxMaps/Foundation/SizeTrackingLayer.swift

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ class SizeTrackingLayer: CALayer {
2121

2222
private var sizeAnimationIsActive = false
2323

24+
private let loggerCategory = "SizeTrackingLayer"
25+
2426
override func add(_ anim: CAAnimation, forKey key: String?) {
2527
if anim.isAnimatingBounds {
2628
sizeAnimationIsActive = true
@@ -30,6 +32,13 @@ class SizeTrackingLayer: CALayer {
3032

3133
override var bounds: CGRect {
3234
didSet {
35+
Log.debug(forMessage: """
36+
\(SizeTrackingLayer.self) did resize
37+
Layer: \(self)
38+
Old size: \(oldValue.size)
39+
New size: \(bounds.size)
40+
Animation is \(sizeAnimationIsActive ? "" : "NOT ")active
41+
""", category: loggerCategory)
3342
guard oldValue.size != bounds.size else { return }
3443
guard sizeAnimationIsActive else {
3544
sizeTrackingDelegate?.sizeTrackingLayer(layer: self, completeResizingFrom: oldValue.size, to: bounds.size)
@@ -39,6 +48,26 @@ class SizeTrackingLayer: CALayer {
3948
CATransaction.setCompletionBlock { [bounds, weak self] in
4049
guard let self else { return }
4150

51+
// In case there were more than one resizing in the same animation period, the last resizing should win
52+
// CATransaction completionBlock's get called in the reverse mode.
53+
guard self.bounds.size == bounds.size else {
54+
Log.debug(forMessage: """
55+
Skipping bounds resize completion of \(self) due to mismatched bounds.
56+
Layer: \(self)
57+
Old size: \(oldValue.size)
58+
Expected size: \(bounds.size)
59+
Actual size: \(self.bounds.size)
60+
""", category: loggerCategory)
61+
return
62+
}
63+
64+
Log.debug(forMessage: """
65+
\(SizeTrackingLayer.self) animation completed
66+
layer: \(self)
67+
Old size: \(oldValue.size)
68+
New size: \(bounds.size)
69+
""", category: loggerCategory)
70+
4271
self.sizeTrackingDelegate?.sizeTrackingLayer(layer: self, completeResizingFrom: oldValue.size, to: bounds.size)
4372

4473
self.sizeAnimationIsActive = false

0 commit comments

Comments
 (0)