Skip to content

Commit

Permalink
Support multiple resizing calls during the same animation (#2337)
Browse files Browse the repository at this point in the history
  • Loading branch information
OdNairy authored Oct 17, 2024
1 parent 9cf7d74 commit fb97a45
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ Mapbox welcomes participation and contributions from everyone.

## main

* Fix the bug when MapView would ignore the new bounds size if there are more than a single resizing event in the animation.

## 11.8.0-beta.1 - 14 October, 2024

* [SwiftUI] Fixed crash when ForEvery was used with duplicated IDs.
Expand Down
29 changes: 29 additions & 0 deletions Sources/MapboxMaps/Foundation/SizeTrackingLayer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ class SizeTrackingLayer: CALayer {

private var sizeAnimationIsActive = false

private let loggerCategory = "SizeTrackingLayer"

override func add(_ anim: CAAnimation, forKey key: String?) {
if anim.isAnimatingBounds {
sizeAnimationIsActive = true
Expand All @@ -30,6 +32,13 @@ class SizeTrackingLayer: CALayer {

override var bounds: CGRect {
didSet {
Log.debug(forMessage: """
\(SizeTrackingLayer.self) did resize
Layer: \(self)
Old size: \(oldValue.size)
New size: \(bounds.size)
Animation is \(sizeAnimationIsActive ? "" : "NOT ")active
""", category: loggerCategory)
guard oldValue.size != bounds.size else { return }
guard sizeAnimationIsActive else {
sizeTrackingDelegate?.sizeTrackingLayer(layer: self, completeResizingFrom: oldValue.size, to: bounds.size)
Expand All @@ -39,6 +48,26 @@ class SizeTrackingLayer: CALayer {
CATransaction.setCompletionBlock { [bounds, weak self] in
guard let self else { return }

// In case there were more than one resizing in the same animation period, the last resizing should win
// CATransaction completionBlock's get called in the reverse mode.
guard self.bounds.size == bounds.size else {
Log.debug(forMessage: """
Skipping bounds resize completion of \(self) due to mismatched bounds.
Layer: \(self)
Old size: \(oldValue.size)
Expected size: \(bounds.size)
Actual size: \(self.bounds.size)
""", category: loggerCategory)
return
}

Log.debug(forMessage: """
\(SizeTrackingLayer.self) animation completed
layer: \(self)
Old size: \(oldValue.size)
New size: \(bounds.size)
""", category: loggerCategory)

self.sizeTrackingDelegate?.sizeTrackingLayer(layer: self, completeResizingFrom: oldValue.size, to: bounds.size)

self.sizeAnimationIsActive = false
Expand Down

0 comments on commit fb97a45

Please sign in to comment.