@@ -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